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

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.cc

Issue 2750373002: Revert of Mojo: Armed Watchers (Closed)
Patch Set: Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/loader/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 MojoAsyncResourceHandler::MojoAsyncResourceHandler( 115 MojoAsyncResourceHandler::MojoAsyncResourceHandler(
116 net::URLRequest* request, 116 net::URLRequest* request,
117 ResourceDispatcherHostImpl* rdh, 117 ResourceDispatcherHostImpl* rdh,
118 mojom::URLLoaderAssociatedRequest mojo_request, 118 mojom::URLLoaderAssociatedRequest mojo_request,
119 mojom::URLLoaderClientPtr url_loader_client, 119 mojom::URLLoaderClientPtr url_loader_client,
120 ResourceType resource_type) 120 ResourceType resource_type)
121 : ResourceHandler(request), 121 : ResourceHandler(request),
122 rdh_(rdh), 122 rdh_(rdh),
123 binding_(this, std::move(mojo_request)), 123 binding_(this, std::move(mojo_request)),
124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), 124 handle_watcher_(FROM_HERE),
125 url_loader_client_(std::move(url_loader_client)), 125 url_loader_client_(std::move(url_loader_client)),
126 weak_factory_(this) { 126 weak_factory_(this) {
127 DCHECK(url_loader_client_); 127 DCHECK(url_loader_client_);
128 InitializeResourceBufferConstants(); 128 InitializeResourceBufferConstants();
129 // This unretained pointer is safe, because |binding_| is owned by |this| and 129 // This unretained pointer is safe, because |binding_| is owned by |this| and
130 // the callback will never be called after |this| is destroyed. 130 // the callback will never be called after |this| is destroyed.
131 binding_.set_connection_error_handler( 131 binding_.set_connection_error_handler(
132 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); 132 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
133 133
134 if (IsResourceTypeFrame(resource_type)) { 134 if (IsResourceTypeFrame(resource_type)) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; 238 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
239 options.element_num_bytes = 1; 239 options.element_num_bytes = 1;
240 options.capacity_num_bytes = g_allocation_size; 240 options.capacity_num_bytes = g_allocation_size;
241 mojo::DataPipe data_pipe(options); 241 mojo::DataPipe data_pipe(options);
242 242
243 DCHECK(data_pipe.producer_handle.is_valid()); 243 DCHECK(data_pipe.producer_handle.is_valid());
244 DCHECK(data_pipe.consumer_handle.is_valid()); 244 DCHECK(data_pipe.consumer_handle.is_valid());
245 245
246 response_body_consumer_handle_ = std::move(data_pipe.consumer_handle); 246 response_body_consumer_handle_ = std::move(data_pipe.consumer_handle);
247 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle)); 247 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle));
248 handle_watcher_.Watch(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, 248 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE,
249 base::Bind(&MojoAsyncResourceHandler::OnWritable, 249 base::Bind(&MojoAsyncResourceHandler::OnWritable,
250 base::Unretained(this))); 250 base::Unretained(this)));
251 handle_watcher_.ArmOrNotify();
252 251
253 bool defer = false; 252 bool defer = false;
254 scoped_refptr<net::IOBufferWithSize> buffer; 253 scoped_refptr<net::IOBufferWithSize> buffer;
255 if (!AllocateWriterIOBuffer(&buffer, &defer)) { 254 if (!AllocateWriterIOBuffer(&buffer, &defer)) {
256 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); 255 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
257 return; 256 return;
258 } 257 }
259 if (!defer) { 258 if (!defer) {
260 if (static_cast<size_t>(buffer->size()) >= kMinAllocationSize) { 259 if (static_cast<size_t>(buffer->size()) >= kMinAllocationSize) {
261 *buf = buffer_ = buffer; 260 *buf = buffer_ = buffer;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { 381 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) {
383 g_allocation_size = size; 382 g_allocation_size = size;
384 } 383 }
385 384
386 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, 385 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data,
387 uint32_t* available) { 386 uint32_t* available) {
388 MojoResult result = mojo::BeginWriteDataRaw( 387 MojoResult result = mojo::BeginWriteDataRaw(
389 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); 388 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE);
390 if (result == MOJO_RESULT_OK) 389 if (result == MOJO_RESULT_OK)
391 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); 390 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize));
392 else if (result == MOJO_RESULT_SHOULD_WAIT)
393 handle_watcher_.ArmOrNotify();
394 return result; 391 return result;
395 } 392 }
396 393
397 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { 394 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) {
398 MojoResult result = mojo::EndWriteDataRaw(shared_writer_->writer(), written); 395 return mojo::EndWriteDataRaw(shared_writer_->writer(), written);
399 if (result == MOJO_RESULT_OK)
400 handle_watcher_.ArmOrNotify();
401 return result;
402 } 396 }
403 397
404 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata( 398 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata(
405 net::URLRequest* request) { 399 net::URLRequest* request) {
406 return request->response_info().metadata.get(); 400 return request->response_info().metadata.get();
407 } 401 }
408 402
409 void MojoAsyncResourceHandler::OnResponseCompleted( 403 void MojoAsyncResourceHandler::OnResponseCompleted(
410 const net::URLRequestStatus& status, 404 const net::URLRequestStatus& status,
411 std::unique_ptr<ResourceController> controller) { 405 std::unique_ptr<ResourceController> controller) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, 578 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK,
585 weak_factory_.GetWeakPtr())); 579 weak_factory_.GetWeakPtr()));
586 } 580 }
587 581
588 void MojoAsyncResourceHandler::OnUploadProgressACK() { 582 void MojoAsyncResourceHandler::OnUploadProgressACK() {
589 if (upload_progress_tracker_) 583 if (upload_progress_tracker_)
590 upload_progress_tracker_->OnAckReceived(); 584 upload_progress_tracker_->OnAckReceived();
591 } 585 }
592 586
593 } // namespace content 587 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698