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.
5 #ifndef MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_
10 #include "base/macros.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "mojo/application/public/cpp/app_lifetime_helper.h"
14 #include "mojo/services/network/public/interfaces/http_server.mojom.h"
15 #include "mojo/services/network/public/interfaces/net_address.mojom.h"
16 #include "net/server/http_server.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
25 class HttpConnectionImpl
;
27 class HttpServerImpl
: public net::HttpServer::Delegate
,
31 NetAddressPtr local_address
,
32 HttpServerDelegatePtr delegate
,
33 scoped_ptr
<mojo::AppRefCount
> app_refcount
,
34 const Callback
<void(NetworkErrorPtr
, NetAddressPtr
)>& callback
);
36 net::HttpServer
* server() { return server_
.get(); }
39 // The lifetime of the returned HttpServerImpl object is bound to that of
40 // |delegate|'s underlying pipe. The object will self-destruct when it is
41 // notified that |delegate|'s pipe is closed. Deleting the object directly
42 // before that is okay, too.
43 HttpServerImpl(HttpServerDelegatePtr delegate
,
44 scoped_ptr
<mojo::AppRefCount
> app_refcount
);
45 ~HttpServerImpl() override
;
47 int Start(NetAddressPtr local_address
);
48 NetAddressPtr
GetLocalAddress() const;
50 // net::HttpServer::Delegate implementation.
51 void OnConnect(int connection_id
) override
;
52 void OnHttpRequest(int connection_id
,
53 const net::HttpServerRequestInfo
& info
) override
;
54 void OnWebSocketRequest(int connection_id
,
55 const net::HttpServerRequestInfo
& info
) override
;
56 void OnWebSocketMessage(int connection_id
, const std::string
& data
) override
;
57 void OnClose(int connection_id
) override
;
59 // ErrorHandler implementation.
60 void OnConnectionError() override
;
62 HttpServerDelegatePtr delegate_
;
63 scoped_ptr
<mojo::AppRefCount
> app_refcount_
;
64 scoped_ptr
<net::HttpServer
> server_
;
66 std::map
<int, linked_ptr
<HttpConnectionImpl
>> connections_
;
68 DISALLOW_COPY_AND_ASSIGN(HttpServerImpl
);
73 #endif // MOJO_SERVICES_NETWORK_HTTP_SERVER_IMPL_H_