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_
10 #include "mojo/spy/common.h"
11 #include "mojo/spy/public/spy.mojom.h"
12 #include "net/server/http_server.h"
22 class WebSocketServer
: public net::HttpServer::Delegate
,
23 public spy_api::SpyClient
{
25 // Pass 0 in |port| to listen in one available port.
26 explicit WebSocketServer(int port
, ScopedMessagePipeHandle server_pipe
);
27 virtual ~WebSocketServer();
28 // Begin accepting HTTP requests. Must be called from an IO MessageLoop.
30 // Returns the listening port, useful if 0 was passed to the contructor.
31 int port() const { return port_
; }
33 // Maintains a log of the message passed in.
35 const mojo::MojoRequestHeader
& message_header
,
37 const base::Time
& message_time
);
40 // Overridden from net::HttpServer::Delegate.
41 virtual void OnHttpRequest(
43 const net::HttpServerRequestInfo
& info
) OVERRIDE
;
44 virtual void OnWebSocketRequest(
46 const net::HttpServerRequestInfo
& info
) OVERRIDE
;
47 virtual void OnWebSocketMessage(
49 const std::string
& data
) OVERRIDE
;
50 virtual void OnClose(int connection_id
) OVERRIDE
;
52 // Overriden form spy_api::SpyClient.
53 virtual void OnFatalError(spy_api::Result result
) OVERRIDE
;
54 virtual void OnSessionEnd(spy_api::Result result
) OVERRIDE
;
55 virtual void OnClientConnection(
56 const mojo::String
& name
,
58 spy_api::ConnectionOptions options
) OVERRIDE
;
59 virtual void OnMessage(spy_api::MessagePtr message
) OVERRIDE
;
61 // Callbacks from calling spy_api::SpyServer.
62 void OnStartSession(spy_api::Result
, mojo::String
);
64 bool Connected() const;
69 scoped_ptr
<net::HttpServer
> web_server_
;
70 spy_api::SpyServerPtr spy_server_
;
72 DISALLOW_COPY_AND_ASSIGN(WebSocketServer
);
77 #endif // MOJO_SPY_WEBSOCKET_SERVER_H_