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_CONNECTION_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "mojo/services/network/public/interfaces/http_connection.mojom.h"
14 #include "mojo/services/network/public/interfaces/http_message.mojom.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
18 class HttpServerRequestInfo
;
25 class HttpConnectionImpl
: public HttpConnection
{
27 // |server| must outlive this object.
28 HttpConnectionImpl(int connection_id
,
29 HttpServerImpl
* server
,
30 HttpConnectionDelegatePtr delegate
,
31 HttpConnectionPtr
* connection
);
33 ~HttpConnectionImpl() override
;
35 void OnReceivedHttpRequest(const net::HttpServerRequestInfo
& info
);
36 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo
& info
);
37 void OnReceivedWebSocketMessage(const std::string
& data
);
40 class SimpleDataPipeReader
;
43 // HttpConnection implementation.
44 void SetSendBufferSize(uint32_t size
,
45 const SetSendBufferSizeCallback
& callback
) override
;
46 void SetReceiveBufferSize(
48 const SetReceiveBufferSizeCallback
& callback
) override
;
50 void OnConnectionError();
52 void OnFinishedReadingResponseBody(HttpResponsePtr response_ptr
,
53 SimpleDataPipeReader
* reader
,
54 scoped_ptr
<std::string
> body
);
58 // Checks whether Close() has been called.
59 bool IsClosing() const { return !binding_
.is_bound(); }
61 // Checks whether all wrap-up work has been done during the closing process.
62 // If yes, notifies the owner, which may result in the destruction of this
64 void NotifyOwnerCloseIfAllDone();
66 void OnWebSocketClosed();
68 const int connection_id_
;
69 HttpServerImpl
* const server_
;
70 HttpConnectionDelegatePtr delegate_
;
71 Binding
<HttpConnection
> binding_
;
73 std::set
<SimpleDataPipeReader
*> response_body_readers_
;
75 scoped_ptr
<WebSocketImpl
> web_socket_
;
77 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl
);
82 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_