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

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

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: rebase 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), 124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
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_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, 248 handle_watcher_.Watch(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 251
252 bool defer = false; 252 bool defer = false;
253 scoped_refptr<net::IOBufferWithSize> buffer; 253 scoped_refptr<net::IOBufferWithSize> buffer;
254 if (!AllocateWriterIOBuffer(&buffer, &defer)) { 254 if (!AllocateWriterIOBuffer(&buffer, &defer)) {
255 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); 255 controller->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
256 return; 256 return;
257 } 257 }
258 if (!defer) { 258 if (!defer) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) { 381 void MojoAsyncResourceHandler::SetAllocationSizeForTesting(size_t size) {
382 g_allocation_size = size; 382 g_allocation_size = size;
383 } 383 }
384 384
385 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data, 385 MojoResult MojoAsyncResourceHandler::BeginWrite(void** data,
386 uint32_t* available) { 386 uint32_t* available) {
387 MojoResult result = mojo::BeginWriteDataRaw( 387 MojoResult result = mojo::BeginWriteDataRaw(
388 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); 388 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE);
389 if (result == MOJO_RESULT_OK) 389 if (result == MOJO_RESULT_OK)
390 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); 390 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize));
391 else if (result == MOJO_RESULT_SHOULD_WAIT)
392 handle_watcher_.ArmOrNotify();
391 return result; 393 return result;
392 } 394 }
393 395
394 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { 396 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) {
395 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); 397 MojoResult result = mojo::EndWriteDataRaw(shared_writer_->writer(), written);
398 if (result == MOJO_RESULT_OK)
399 handle_watcher_.ArmOrNotify();
400 return result;
396 } 401 }
397 402
398 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata( 403 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata(
399 net::URLRequest* request) { 404 net::URLRequest* request) {
400 return request->response_info().metadata.get(); 405 return request->response_info().metadata.get();
401 } 406 }
402 407
403 void MojoAsyncResourceHandler::OnResponseCompleted( 408 void MojoAsyncResourceHandler::OnResponseCompleted(
404 const net::URLRequestStatus& status, 409 const net::URLRequestStatus& status,
405 std::unique_ptr<ResourceController> controller) { 410 std::unique_ptr<ResourceController> controller) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, 583 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK,
579 weak_factory_.GetWeakPtr())); 584 weak_factory_.GetWeakPtr()));
580 } 585 }
581 586
582 void MojoAsyncResourceHandler::OnUploadProgressACK() { 587 void MojoAsyncResourceHandler::OnUploadProgressACK() {
583 if (upload_progress_tracker_) 588 if (upload_progress_tracker_)
584 upload_progress_tracker_->OnAckReceived(); 589 upload_progress_tracker_->OnAckReceived();
585 } 590 }
586 591
587 } // namespace content 592 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698