OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
| 6 #define MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "mojo/services/network/public/interfaces/http_server.mojom.h" |
| 14 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
| 15 #include "net/server/http_server.h" |
| 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
| 17 |
| 18 namespace net { |
| 19 class HttpServer; |
| 20 } |
| 21 |
| 22 namespace mojo { |
| 23 |
| 24 class HttpConnectionImpl; |
| 25 |
| 26 class HttpServerImpl : public net::HttpServer::Delegate, |
| 27 public ErrorHandler { |
| 28 public: |
| 29 static void Create( |
| 30 NetAddressPtr local_address, |
| 31 HttpServerDelegatePtr delegate, |
| 32 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback); |
| 33 |
| 34 net::HttpServer* server() { return server_.get(); } |
| 35 |
| 36 private: |
| 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 |
| 39 // notified that |delegate|'s pipe is closed. Deleting the object directly |
| 40 // before that is okay, too. |
| 41 explicit HttpServerImpl(HttpServerDelegatePtr delegate); |
| 42 ~HttpServerImpl() override; |
| 43 |
| 44 int Start(NetAddressPtr local_address); |
| 45 NetAddressPtr GetLocalAddress() const; |
| 46 |
| 47 // net::HttpServer::Delegate implementation. |
| 48 void OnConnect(int connection_id) override; |
| 49 void OnHttpRequest(int connection_id, |
| 50 const net::HttpServerRequestInfo& info) override; |
| 51 void OnWebSocketRequest(int connection_id, |
| 52 const net::HttpServerRequestInfo& info) override; |
| 53 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| 54 void OnClose(int connection_id) override; |
| 55 |
| 56 // ErrorHandler implementation. |
| 57 void OnConnectionError() override; |
| 58 |
| 59 HttpServerDelegatePtr delegate_; |
| 60 scoped_ptr<net::HttpServer> server_; |
| 61 |
| 62 std::map<int, linked_ptr<HttpConnectionImpl>> connections_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); |
| 65 }; |
| 66 |
| 67 } // namespace mojo |
| 68 |
| 69 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
OLD | NEW |