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

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

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

Powered by Google App Engine
This is Rietveld 408576698