Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: mojo/services/network/http_connection_impl.cc

Issue 1227373002: Roll mojo SDK to 734c6e1652ff2f3b696e441722838f453f4f9b42 (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Fix build Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "mojo/services/network/http_connection_impl.h" 5 #include "mojo/services/network/http_connection_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void OnHandleReady(MojoResult result) { ReadMore(); } 78 void OnHandleReady(MojoResult result) { ReadMore(); }
79 79
80 ScopedDataPipeConsumerHandle consumer_; 80 ScopedDataPipeConsumerHandle consumer_;
81 common::HandleWatcher watcher_; 81 common::HandleWatcher watcher_;
82 CompletionCallback completion_callback_; 82 CompletionCallback completion_callback_;
83 scoped_ptr<std::string> buffer_; 83 scoped_ptr<std::string> buffer_;
84 84
85 DISALLOW_COPY_AND_ASSIGN(SimpleDataPipeReader); 85 DISALLOW_COPY_AND_ASSIGN(SimpleDataPipeReader);
86 }; 86 };
87 87
88 class HttpConnectionImpl::WebSocketImpl : public WebSocket, 88 class HttpConnectionImpl::WebSocketImpl : public WebSocket {
89 public ErrorHandler {
90 public: 89 public:
91 // |connection| must outlive this object. 90 // |connection| must outlive this object.
92 WebSocketImpl(HttpConnectionImpl* connection, 91 WebSocketImpl(HttpConnectionImpl* connection,
93 InterfaceRequest<WebSocket> request, 92 InterfaceRequest<WebSocket> request,
94 ScopedDataPipeConsumerHandle send_stream, 93 ScopedDataPipeConsumerHandle send_stream,
95 WebSocketClientPtr client) 94 WebSocketClientPtr client)
96 : connection_(connection), 95 : connection_(connection),
97 binding_(this, request.Pass()), 96 binding_(this, request.Pass()),
98 client_(client.Pass()), 97 client_(client.Pass()),
99 send_stream_(send_stream.Pass()), 98 send_stream_(send_stream.Pass()),
100 read_send_stream_(new WebSocketReadQueue(send_stream_.get())), 99 read_send_stream_(new WebSocketReadQueue(send_stream_.get())),
101 pending_send_count_(0) { 100 pending_send_count_(0) {
102 DCHECK(binding_.is_bound()); 101 DCHECK(binding_.is_bound());
103 DCHECK(client_); 102 DCHECK(client_);
104 DCHECK(send_stream_.is_valid()); 103 DCHECK(send_stream_.is_valid());
105 104
106 binding_.set_error_handler(this); 105 binding_.set_connection_error_handler([this]() { Close(); });
107 client_.set_error_handler(this); 106 client_.set_connection_error_handler([this]() { Close(); });
108 107
109 DataPipe data_pipe; 108 DataPipe data_pipe;
110 receive_stream_ = data_pipe.producer_handle.Pass(); 109 receive_stream_ = data_pipe.producer_handle.Pass();
111 write_receive_stream_.reset(new WebSocketWriteQueue(receive_stream_.get())); 110 write_receive_stream_.reset(new WebSocketWriteQueue(receive_stream_.get()));
112 111
113 client_->DidConnect("", "", data_pipe.consumer_handle.Pass()); 112 client_->DidConnect("", "", data_pipe.consumer_handle.Pass());
114 } 113 }
115 114
116 ~WebSocketImpl() override {} 115 ~WebSocketImpl() override {}
117 116
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 num_bytes, base::Bind(&WebSocketImpl::OnFinishedReadingSendStream, 165 num_bytes, base::Bind(&WebSocketImpl::OnFinishedReadingSendStream,
167 base::Unretained(this), num_bytes)); 166 base::Unretained(this), num_bytes));
168 } 167 }
169 168
170 void FlowControl(int64_t quota) override { NOTIMPLEMENTED(); } 169 void FlowControl(int64_t quota) override { NOTIMPLEMENTED(); }
171 170
172 void Close(uint16_t code, const String& reason) override { 171 void Close(uint16_t code, const String& reason) override {
173 Close(); 172 Close();
174 } 173 }
175 174
176 // ErrorHandler implementation.
177 void OnConnectionError() override { Close(); }
178
179 void OnFinishedReadingSendStream(uint32_t num_bytes, const char* data) { 175 void OnFinishedReadingSendStream(uint32_t num_bytes, const char* data) {
180 DCHECK_GT(pending_send_count_, 0u); 176 DCHECK_GT(pending_send_count_, 0u);
181 pending_send_count_--; 177 pending_send_count_--;
182 178
183 if (data) { 179 if (data) {
184 connection_->server_->server()->SendOverWebSocket( 180 connection_->server_->server()->SendOverWebSocket(
185 connection_->connection_id_, std::string(data, num_bytes)); 181 connection_->connection_id_, std::string(data, num_bytes));
186 } 182 }
187 183
188 if (IsClosing()) 184 if (IsClosing())
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 252
257 HttpConnectionImpl::HttpConnectionImpl(int connection_id, 253 HttpConnectionImpl::HttpConnectionImpl(int connection_id,
258 HttpServerImpl* server, 254 HttpServerImpl* server,
259 HttpConnectionDelegatePtr delegate, 255 HttpConnectionDelegatePtr delegate,
260 HttpConnectionPtr* connection) 256 HttpConnectionPtr* connection)
261 : connection_id_(connection_id), 257 : connection_id_(connection_id),
262 server_(server), 258 server_(server),
263 delegate_(delegate.Pass()), 259 delegate_(delegate.Pass()),
264 binding_(this, connection) { 260 binding_(this, connection) {
265 DCHECK(delegate_); 261 DCHECK(delegate_);
266 binding_.set_error_handler(this); 262 binding_.set_connection_error_handler([this]() { Close(); });
267 delegate_.set_error_handler(this); 263 delegate_.set_connection_error_handler([this]() { Close(); });
268 } 264 }
269 265
270 HttpConnectionImpl::~HttpConnectionImpl() { 266 HttpConnectionImpl::~HttpConnectionImpl() {
271 STLDeleteElements(&response_body_readers_); 267 STLDeleteElements(&response_body_readers_);
272 } 268 }
273 269
274 void HttpConnectionImpl::OnReceivedHttpRequest( 270 void HttpConnectionImpl::OnReceivedHttpRequest(
275 const net::HttpServerRequestInfo& info) { 271 const net::HttpServerRequestInfo& info) {
276 if (IsClosing()) 272 if (IsClosing())
277 return; 273 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 uint32_t size, 333 uint32_t size,
338 const SetReceiveBufferSizeCallback& callback) { 334 const SetReceiveBufferSizeCallback& callback) {
339 if (size > static_cast<uint32_t>(std::numeric_limits<int32_t>::max())) 335 if (size > static_cast<uint32_t>(std::numeric_limits<int32_t>::max()))
340 size = std::numeric_limits<int32_t>::max(); 336 size = std::numeric_limits<int32_t>::max();
341 337
342 server_->server()->SetReceiveBufferSize(connection_id_, 338 server_->server()->SetReceiveBufferSize(connection_id_,
343 static_cast<int32_t>(size)); 339 static_cast<int32_t>(size));
344 callback.Run(MakeNetworkError(net::OK)); 340 callback.Run(MakeNetworkError(net::OK));
345 } 341 }
346 342
347 void HttpConnectionImpl::OnConnectionError() {
348 // This method is called when the proxy side of |binding_| or the impl side of
349 // |delegate_| has closed the pipe. Although it is set as error handler for
350 // both |binding_| and |delegate_|, it will only be called at most once
351 // because when called it closes/resets |binding_| and |delegate_|.
352 Close();
353 }
354
355 void HttpConnectionImpl::OnFinishedReadingResponseBody( 343 void HttpConnectionImpl::OnFinishedReadingResponseBody(
356 HttpResponsePtr response, 344 HttpResponsePtr response,
357 SimpleDataPipeReader* reader, 345 SimpleDataPipeReader* reader,
358 scoped_ptr<std::string> body) { 346 scoped_ptr<std::string> body) {
359 if (reader) { 347 if (reader) {
360 delete reader; 348 delete reader;
361 response_body_readers_.erase(reader); 349 response_body_readers_.erase(reader);
362 } 350 }
363 351
364 net::HttpServerResponseInfo info( 352 net::HttpServerResponseInfo info(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // The close operation is initiated by this object. 411 // The close operation is initiated by this object.
424 NotifyOwnerCloseIfAllDone(); 412 NotifyOwnerCloseIfAllDone();
425 } else { 413 } else {
426 // The close operation is initiated by |web_socket_|; start closing this 414 // The close operation is initiated by |web_socket_|; start closing this
427 // object. 415 // object.
428 Close(); 416 Close();
429 } 417 }
430 } 418 }
431 419
432 } // namespace mojo 420 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698