Standardize usage of virtual/override/final in mojo/
[chromium-blink-merge.git] / mojo / spy / websocket_server.h
blob879682d44481d1e1e4b179b37d582016e8665302
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MOJO_SPY_WEBSOCKET_SERVER_H_
6 #define MOJO_SPY_WEBSOCKET_SERVER_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "mojo/spy/common.h"
12 #include "mojo/spy/public/spy.mojom.h"
13 #include "net/server/http_server.h"
15 namespace base {
16 class Time;
19 class GURL;
21 namespace mojo {
23 class WebSocketServer : public net::HttpServer::Delegate,
24 public spy_api::SpyClient {
25 public:
26 // Pass 0 in |port| to listen in one available port.
27 explicit WebSocketServer(int port, ScopedMessagePipeHandle server_pipe);
28 ~WebSocketServer() override;
29 // Begin accepting HTTP requests. Must be called from an IO MessageLoop.
30 bool Start();
31 // Returns the listening port, useful if 0 was passed to the contructor.
32 int port() const { return port_; }
34 // Maintains a log of the message passed in.
35 void LogMessageInfo(
36 const mojo::MojoRequestHeader& message_header,
37 const GURL& url,
38 const base::Time& message_time);
40 protected:
41 // Overridden from net::HttpServer::Delegate.
42 void OnConnect(int connection_id) override {}
43 void OnHttpRequest(int connection_id,
44 const net::HttpServerRequestInfo& info) override;
45 void OnWebSocketRequest(int connection_id,
46 const net::HttpServerRequestInfo& info) override;
47 void OnWebSocketMessage(int connection_id, const std::string& data) override;
48 void OnClose(int connection_id) override;
50 // Overriden form spy_api::SpyClient.
51 void OnFatalError(spy_api::Result result) override;
52 void OnSessionEnd(spy_api::Result result) override;
53 void OnClientConnection(const mojo::String& name,
54 uint32_t id,
55 spy_api::ConnectionOptions options) override;
56 void OnMessage(spy_api::MessagePtr message) override;
58 // Callbacks from calling spy_api::SpyServer.
59 void OnStartSession(spy_api::Result, mojo::String);
61 bool Connected() const;
63 private:
64 int port_;
65 int connection_id_;
66 scoped_ptr<net::HttpServer> web_server_;
67 spy_api::SpyServerPtr spy_server_;
69 DISALLOW_COPY_AND_ASSIGN(WebSocketServer);
72 } // namespace mojo
74 #endif // MOJO_SPY_WEBSOCKET_SERVER_H_