OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ |
6 #define MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | 6 #define MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ |
7 | 7 |
| 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
11 #include "mojo/services/network/public/interfaces/http_connection.mojom.h" | 13 #include "mojo/services/network/public/interfaces/http_connection.mojom.h" |
| 14 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
14 | 17 |
15 namespace net { | 18 namespace net { |
16 class HttpServerRequestInfo; | 19 class HttpServerRequestInfo; |
17 } | 20 } |
18 | 21 |
19 namespace mojo { | 22 namespace mojo { |
20 | 23 |
21 class HttpServerImpl; | 24 class HttpServerImpl; |
22 | 25 |
23 class HttpConnectionImpl : public HttpConnection, | 26 class HttpConnectionImpl : public HttpConnection, |
24 public ErrorHandler { | 27 public ErrorHandler { |
25 public: | 28 public: |
26 // |owner| must outlive this object. | 29 // |owner| must outlive this object. |
27 HttpConnectionImpl(int connection_id, | 30 HttpConnectionImpl(int connection_id, |
28 HttpServerImpl* owner, | 31 HttpServerImpl* owner, |
29 HttpConnectionDelegatePtr delegate, | 32 HttpConnectionDelegatePtr delegate, |
30 HttpConnectionPtr* connection); | 33 HttpConnectionPtr* connection); |
31 | 34 |
32 ~HttpConnectionImpl() override; | 35 ~HttpConnectionImpl() override; |
33 | 36 |
34 void OnReceivedHttpRequest(const net::HttpServerRequestInfo& info); | 37 void OnReceivedHttpRequest(const net::HttpServerRequestInfo& info); |
35 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo& info); | 38 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo& info); |
36 void OnReceivedWebSocketMessage(const std::string& data); | 39 void OnReceivedWebSocketMessage(const std::string& data); |
37 | 40 |
38 private: | 41 private: |
| 42 class SimpleDataPipeReader; |
| 43 |
39 // HttpConnection implementation. | 44 // HttpConnection implementation. |
40 void SetSendBufferSize(uint32_t size, | 45 void SetSendBufferSize(uint32_t size, |
41 const SetSendBufferSizeCallback& callback) override; | 46 const SetSendBufferSizeCallback& callback) override; |
42 void SetReceiveBufferSize( | 47 void SetReceiveBufferSize( |
43 uint32_t size, | 48 uint32_t size, |
44 const SetReceiveBufferSizeCallback& callback) override; | 49 const SetReceiveBufferSizeCallback& callback) override; |
45 | 50 |
46 // ErrorHandler implementation. | 51 // ErrorHandler implementation. |
47 void OnConnectionError() override; | 52 void OnConnectionError() override; |
48 | 53 |
| 54 void OnFinishedReadingResponseBody(URLResponsePtr response_ptr, |
| 55 SimpleDataPipeReader* reader, |
| 56 scoped_ptr<std::string> body); |
| 57 |
| 58 bool EncounteredConnectionError() const { |
| 59 return !binding_.is_bound() || !delegate_; |
| 60 } |
| 61 |
49 const int connection_id_; | 62 const int connection_id_; |
50 HttpServerImpl* const owner_; | 63 HttpServerImpl* const owner_; |
51 HttpConnectionDelegatePtr delegate_; | 64 HttpConnectionDelegatePtr delegate_; |
52 Binding<HttpConnection> binding_; | 65 Binding<HttpConnection> binding_; |
| 66 // Owns its elements. |
| 67 std::set<SimpleDataPipeReader*> response_body_readers_; |
53 | 68 |
54 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl); | 69 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl); |
55 }; | 70 }; |
56 | 71 |
57 } // namespace mojo | 72 } // namespace mojo |
58 | 73 |
59 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | 74 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ |
OLD | NEW |