OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | |
6 #define MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <set> | |
11 #include <string> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "mojo/public/cpp/bindings/binding.h" | |
16 #include "mojo/services/network/public/interfaces/http_connection.mojom.h" | |
17 #include "mojo/services/network/public/interfaces/http_message.mojom.h" | |
18 | |
19 namespace net { | |
20 class HttpServerRequestInfo; | |
21 } | |
22 | |
23 namespace mojo { | |
24 | |
25 class HttpServerImpl; | |
26 | |
27 class HttpConnectionImpl : public HttpConnection { | |
28 public: | |
29 // |server| must outlive this object. | |
30 HttpConnectionImpl(int connection_id, | |
31 HttpServerImpl* server, | |
32 HttpConnectionDelegatePtr delegate, | |
33 HttpConnectionPtr* connection); | |
34 | |
35 ~HttpConnectionImpl() override; | |
36 | |
37 void OnReceivedHttpRequest(const net::HttpServerRequestInfo& info); | |
38 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo& info); | |
39 void OnReceivedWebSocketMessage(const std::string& data); | |
40 | |
41 private: | |
42 class SimpleDataPipeReader; | |
43 class WebSocketImpl; | |
44 | |
45 // HttpConnection implementation. | |
46 void SetSendBufferSize(uint32_t size, | |
47 const SetSendBufferSizeCallback& callback) override; | |
48 void SetReceiveBufferSize( | |
49 uint32_t size, | |
50 const SetReceiveBufferSizeCallback& callback) override; | |
51 | |
52 void OnConnectionError(); | |
53 | |
54 void OnFinishedReadingResponseBody(HttpResponsePtr response_ptr, | |
55 SimpleDataPipeReader* reader, | |
56 scoped_ptr<std::string> body); | |
57 | |
58 void Close(); | |
59 | |
60 // Checks whether Close() has been called. | |
61 bool IsClosing() const { return !binding_.is_bound(); } | |
62 | |
63 // Checks whether all wrap-up work has been done during the closing process. | |
64 // If yes, notifies the owner, which may result in the destruction of this | |
65 // object. | |
66 void NotifyOwnerCloseIfAllDone(); | |
67 | |
68 void OnWebSocketClosed(); | |
69 | |
70 const int connection_id_; | |
71 HttpServerImpl* const server_; | |
72 HttpConnectionDelegatePtr delegate_; | |
73 Binding<HttpConnection> binding_; | |
74 // Owns its elements. | |
75 std::set<SimpleDataPipeReader*> response_body_readers_; | |
76 | |
77 scoped_ptr<WebSocketImpl> web_socket_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl); | |
80 }; | |
81 | |
82 } // namespace mojo | |
83 | |
84 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_ | |
OLD | NEW |