Chromium Code Reviews| Index: mojo/services/network/http_server_impl.h |
| diff --git a/mojo/services/network/http_server_impl.h b/mojo/services/network/http_server_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f646d7daa40f3a5cef96e22743c464b3a2ee4599 |
| --- /dev/null |
| +++ b/mojo/services/network/http_server_impl.h |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
| +#define MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "mojo/services/network/public/interfaces/http_server.mojom.h" |
| +#include "mojo/services/network/public/interfaces/net_address.mojom.h" |
| +#include "net/server/http_server.h" |
| +#include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
| + |
| +namespace net { |
| +class HttpServer; |
| +} |
| + |
| +namespace mojo { |
| + |
| +class HttpConnectionImpl; |
| + |
| +class HttpServerImpl : public net::HttpServer::Delegate, |
| + public ErrorHandler { |
| + public: |
| + // The lifetime of the returned HttpServerImpl object is bound to that of |
| + // |delegate|'s underlying pipe. The object will self-destruct when |
| + // |delegate|'s pipe is closed. However, it is safe to delete the object |
| + // directly as well. |
| + static HttpServerImpl* Create(HttpServerDelegatePtr delegate); |
|
jam
2015/05/12 15:50:23
why is there a static factory method which just ca
yzshen1
2015/05/12 16:02:04
Making the ctor private has be benefit of preventi
|
| + ~HttpServerImpl() override; |
| + |
| + int Start(NetAddressPtr local_address); |
| + |
| + NetAddressPtr GetLocalAddress() const; |
| + |
| + net::HttpServer* server() { return server_.get(); } |
| + |
| + private: |
| + explicit HttpServerImpl(HttpServerDelegatePtr delegate); |
| + |
| + // net::HttpServer::Delegate implementation. |
| + void OnConnect(int connection_id) override; |
| + void OnHttpRequest(int connection_id, |
| + const net::HttpServerRequestInfo& info) override; |
| + void OnWebSocketRequest(int connection_id, |
| + const net::HttpServerRequestInfo& info) override; |
| + void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| + void OnClose(int connection_id) override; |
| + |
| + // ErrorHandler implementation. |
| + void OnConnectionError() override; |
| + |
| + HttpServerDelegatePtr delegate_; |
| + scoped_ptr<net::HttpServer> server_; |
| + |
| + std::map<int, linked_ptr<HttpConnectionImpl>> connections_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HttpServerImpl); |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_ |