Make --install-chrome-app use extensions::WebstoreInstallWithPrompt.
[chromium-blink-merge.git] / mojo / spy / websocket_server.h
blob1811c0c8d689748a8012bcf0cf5a2382f91c8d25
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 "mojo/spy/common.h"
11 #include "mojo/spy/public/spy.mojom.h"
12 #include "net/server/http_server.h"
14 namespace base {
15 class Time;
18 class GURL;
20 namespace mojo {
22 class WebSocketServer : public net::HttpServer::Delegate,
23 public spy_api::SpyClient {
24 public:
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.
29 bool Start();
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.
34 void LogMessageInfo(
35 const mojo::MojoRequestHeader& message_header,
36 const GURL& url,
37 const base::Time& message_time);
39 protected:
40 // Overridden from net::HttpServer::Delegate.
41 virtual void OnHttpRequest(
42 int connection_id,
43 const net::HttpServerRequestInfo& info) OVERRIDE;
44 virtual void OnWebSocketRequest(
45 int connection_id,
46 const net::HttpServerRequestInfo& info) OVERRIDE;
47 virtual void OnWebSocketMessage(
48 int connection_id,
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,
57 uint32_t id,
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;
66 private:
67 int port_;
68 int connection_id_;
69 scoped_refptr<net::HttpServer> web_server_;
70 spy_api::SpyServerPtr spy_server_;
72 DISALLOW_COPY_AND_ASSIGN(WebSocketServer);
75 } // namespace mojo
77 #endif // MOJO_SPY_WEBSOCKET_SERVER_H_