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"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
19 class HttpServerRequestInfo
;
26 class HttpConnectionImpl
: public HttpConnection
,
29 // |server| must outlive this object.
30 HttpConnectionImpl(int connection_id
,
31 HttpServerImpl
* server
,
32 HttpConnectionDelegatePtr delegate
,
33 HttpConnectionPtr
* connection
);
35 ~HttpConnectionImpl() override
;
37 void OnReceivedHttpRequest(const net::HttpServerRequestInfo
& info
);
38 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo
& info
);
39 void OnReceivedWebSocketMessage(const std::string
& data
);
42 class SimpleDataPipeReader
;
45 // HttpConnection implementation.
46 void SetSendBufferSize(uint32_t size
,
47 const SetSendBufferSizeCallback
& callback
) override
;
48 void SetReceiveBufferSize(
50 const SetReceiveBufferSizeCallback
& callback
) override
;
52 // ErrorHandler implementation.
53 void OnConnectionError() override
;
55 void OnFinishedReadingResponseBody(HttpResponsePtr response_ptr
,
56 SimpleDataPipeReader
* reader
,
57 scoped_ptr
<std::string
> body
);
61 // Checks whether Close() has been called.
62 bool IsClosing() const { return !binding_
.is_bound(); }
64 // Checks whether all wrap-up work has been done during the closing process.
65 // If yes, notifies the owner, which may result in the destruction of this
67 void NotifyOwnerCloseIfAllDone();
69 void OnWebSocketClosed();
71 const int connection_id_
;
72 HttpServerImpl
* const server_
;
73 HttpConnectionDelegatePtr delegate_
;
74 Binding
<HttpConnection
> binding_
;
76 std::set
<SimpleDataPipeReader
*> response_body_readers_
;
78 scoped_ptr
<WebSocketImpl
> web_socket_
;
80 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl
);
85 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_