OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
6 #define MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ | 6 #define MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "mojo/services/network/interfaces/http_server.mojom.h" | 13 #include "mojo/services/network/interfaces/http_server.mojom.h" |
14 #include "mojo/services/network/interfaces/net_address.mojom.h" | 14 #include "mojo/services/network/interfaces/net_address.mojom.h" |
15 #include "net/server/http_server.h" | 15 #include "net/server/http_server.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 class HttpServer; | 18 class HttpServer; |
19 } | 19 } |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 | 22 |
23 class HttpConnectionImpl; | 23 class HttpConnectionImpl; |
24 | 24 |
25 class HttpServerImpl : public net::HttpServer::Delegate { | 25 class HttpServerImpl : public net::HttpServer::Delegate { |
26 public: | 26 public: |
27 static void Create( | 27 static void Create( |
28 NetAddressPtr local_address, | 28 NetAddressPtr local_address, |
29 HttpServerDelegatePtr delegate, | 29 InterfaceHandle<HttpServerDelegate> delegate, |
30 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); | 30 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); |
31 | 31 |
32 net::HttpServer* server() { return server_.get(); } | 32 net::HttpServer* server() { return server_.get(); } |
33 | 33 |
34 private: | 34 private: |
35 // The lifetime of the returned HttpServerImpl object is bound to that of | 35 // The lifetime of the returned HttpServerImpl object is bound to that of |
36 // |delegate|'s underlying pipe. The object will self-destruct when it is | 36 // |delegate|'s underlying pipe. The object will self-destruct when it is |
37 // notified that |delegate|'s pipe is closed. Deleting the object directly | 37 // notified that |delegate|'s pipe is closed. Deleting the object directly |
38 // before that is okay, too. | 38 // before that is okay, too. |
39 explicit HttpServerImpl(HttpServerDelegatePtr delegate); | 39 explicit HttpServerImpl(InterfaceHandle<HttpServerDelegate> delegate); |
40 virtual ~HttpServerImpl(); | 40 virtual ~HttpServerImpl(); |
41 | 41 |
42 int Start(NetAddressPtr local_address); | 42 int Start(NetAddressPtr local_address); |
43 NetAddressPtr GetLocalAddress() const; | 43 NetAddressPtr GetLocalAddress() const; |
44 | 44 |
45 // net::HttpServer::Delegate implementation. | 45 // net::HttpServer::Delegate implementation. |
46 void OnConnect(int connection_id) override; | 46 void OnConnect(int connection_id) override; |
47 void OnHttpRequest(int connection_id, | 47 void OnHttpRequest(int connection_id, |
48 const net::HttpServerRequestInfo& info) override; | 48 const net::HttpServerRequestInfo& info) override; |
49 void OnWebSocketRequest(int connection_id, | 49 void OnWebSocketRequest(int connection_id, |
50 const net::HttpServerRequestInfo& info) override; | 50 const net::HttpServerRequestInfo& info) override; |
51 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 51 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
52 void OnClose(int connection_id) override; | 52 void OnClose(int connection_id) override; |
53 | 53 |
54 HttpServerDelegatePtr delegate_; | 54 HttpServerDelegatePtr delegate_; |
55 scoped_ptr<net::HttpServer> server_; | 55 scoped_ptr<net::HttpServer> server_; |
56 | 56 |
57 std::map<int, linked_ptr<HttpConnectionImpl>> connections_; | 57 std::map<int, linked_ptr<HttpConnectionImpl>> connections_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); | 59 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); |
60 }; | 60 }; |
61 | 61 |
62 } // namespace mojo | 62 } // namespace mojo |
63 | 63 |
64 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ | 64 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
OLD | NEW |