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/public/interfaces/http_server.mojom.h" | 13 #include "mojo/services/network/public/interfaces/http_server.mojom.h" |
14 #include "mojo/services/network/public/interfaces/net_address.mojom.h" | 14 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
15 #include "mojo/shell/public/cpp/shell.h" | 15 #include "mojo/shell/public/cpp/message_loop_ref.h" |
16 #include "net/server/http_server.h" | 16 #include "net/server/http_server.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class HttpServer; | 19 class HttpServer; |
20 } | 20 } |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 | 23 |
24 class HttpConnectionImpl; | 24 class HttpConnectionImpl; |
25 | 25 |
26 class HttpServerImpl : public net::HttpServer::Delegate { | 26 class HttpServerImpl : public net::HttpServer::Delegate { |
27 public: | 27 public: |
28 static void Create( | 28 static void Create( |
29 NetAddressPtr local_address, | 29 NetAddressPtr local_address, |
30 HttpServerDelegatePtr delegate, | 30 HttpServerDelegatePtr delegate, |
31 scoped_ptr<mojo::AppRefCount> app_refcount, | 31 scoped_ptr<mojo::MessageLoopRef> app_refcount, |
32 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); | 32 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); |
33 | 33 |
34 net::HttpServer* server() { return server_.get(); } | 34 net::HttpServer* server() { return server_.get(); } |
35 | 35 |
36 private: | 36 private: |
37 // The lifetime of the returned HttpServerImpl object is bound to that of | 37 // The lifetime of the returned HttpServerImpl object is bound to that of |
38 // |delegate|'s underlying pipe. The object will self-destruct when it is | 38 // |delegate|'s underlying pipe. The object will self-destruct when it is |
39 // notified that |delegate|'s pipe is closed. Deleting the object directly | 39 // notified that |delegate|'s pipe is closed. Deleting the object directly |
40 // before that is okay, too. | 40 // before that is okay, too. |
41 HttpServerImpl(HttpServerDelegatePtr delegate, | 41 HttpServerImpl(HttpServerDelegatePtr delegate, |
42 scoped_ptr<mojo::AppRefCount> app_refcount); | 42 scoped_ptr<mojo::MessageLoopRef> app_refcount); |
43 ~HttpServerImpl() override; | 43 ~HttpServerImpl() override; |
44 | 44 |
45 int Start(NetAddressPtr local_address); | 45 int Start(NetAddressPtr local_address); |
46 NetAddressPtr GetLocalAddress() const; | 46 NetAddressPtr GetLocalAddress() const; |
47 | 47 |
48 // net::HttpServer::Delegate implementation. | 48 // net::HttpServer::Delegate implementation. |
49 void OnConnect(int connection_id) override; | 49 void OnConnect(int connection_id) override; |
50 void OnHttpRequest(int connection_id, | 50 void OnHttpRequest(int connection_id, |
51 const net::HttpServerRequestInfo& info) override; | 51 const net::HttpServerRequestInfo& info) override; |
52 void OnWebSocketRequest(int connection_id, | 52 void OnWebSocketRequest(int connection_id, |
53 const net::HttpServerRequestInfo& info) override; | 53 const net::HttpServerRequestInfo& info) override; |
54 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 54 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
55 void OnClose(int connection_id) override; | 55 void OnClose(int connection_id) override; |
56 | 56 |
57 HttpServerDelegatePtr delegate_; | 57 HttpServerDelegatePtr delegate_; |
58 scoped_ptr<mojo::AppRefCount> app_refcount_; | 58 scoped_ptr<mojo::MessageLoopRef> app_refcount_; |
59 scoped_ptr<net::HttpServer> server_; | 59 scoped_ptr<net::HttpServer> server_; |
60 | 60 |
61 std::map<int, linked_ptr<HttpConnectionImpl>> connections_; | 61 std::map<int, linked_ptr<HttpConnectionImpl>> connections_; |
62 | 62 |
63 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); | 63 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); |
64 }; | 64 }; |
65 | 65 |
66 } // namespace mojo | 66 } // namespace mojo |
67 | 67 |
68 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ | 68 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
OLD | NEW |