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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/async_resource_handler.h" 5 #include "content/browser/loader/async_resource_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 public: 184 public:
185 DependentIOBuffer(ResourceBuffer* backing, char* memory) 185 DependentIOBuffer(ResourceBuffer* backing, char* memory)
186 : net::WrappedIOBuffer(memory), 186 : net::WrappedIOBuffer(memory),
187 backing_(backing) { 187 backing_(backing) {
188 } 188 }
189 private: 189 private:
190 ~DependentIOBuffer() override {} 190 ~DependentIOBuffer() override {}
191 scoped_refptr<ResourceBuffer> backing_; 191 scoped_refptr<ResourceBuffer> backing_;
192 }; 192 };
193 193
194 AsyncResourceHandler::AsyncResourceHandler( 194 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request,
195 net::URLRequest* request, 195 ResourceDispatcherHostImpl* rdh,
196 ResourceDispatcherHostImpl* rdh) 196 bool using_mojo_data_handle)
197 : ResourceHandler(request), 197 : ResourceHandler(request),
198 ResourceMessageDelegate(request), 198 ResourceMessageDelegate(request),
199 rdh_(rdh), 199 rdh_(rdh),
200 pending_data_count_(0), 200 pending_data_count_(0),
201 allocation_size_(0), 201 allocation_size_(0),
202 did_defer_(false), 202 did_defer_(false),
203 has_checked_for_sufficient_resources_(false), 203 has_checked_for_sufficient_resources_(false),
204 sent_received_response_msg_(false), 204 sent_received_response_msg_(false),
205 sent_data_buffer_msg_(false), 205 sent_data_buffer_msg_(false),
206 using_mojo_data_handle_(using_mojo_data_handle),
206 inlining_helper_(new InliningHelper), 207 inlining_helper_(new InliningHelper),
207 last_upload_position_(0), 208 last_upload_position_(0),
208 waiting_for_upload_progress_ack_(false), 209 waiting_for_upload_progress_ack_(false),
209 reported_transfer_size_(0) { 210 reported_transfer_size_(0) {
210 InitializeResourceBufferConstants(); 211 InitializeResourceBufferConstants();
211 } 212 }
212 213
213 AsyncResourceHandler::~AsyncResourceHandler() { 214 AsyncResourceHandler::~AsyncResourceHandler() {
214 if (has_checked_for_sufficient_resources_) 215 if (has_checked_for_sufficient_resources_)
215 rdh_->FinishedWithResourcesForRequest(request()); 216 rdh_->FinishedWithResourcesForRequest(request());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // If the parent handler downloaded the resource to a file, grant the child 364 // If the parent handler downloaded the resource to a file, grant the child
364 // read permissions on it. 365 // read permissions on it.
365 if (!response->head.download_file_path.empty()) { 366 if (!response->head.download_file_path.empty()) {
366 rdh_->RegisterDownloadedTempFile( 367 rdh_->RegisterDownloadedTempFile(
367 info->GetChildID(), info->GetRequestID(), 368 info->GetChildID(), info->GetRequestID(),
368 response->head.download_file_path); 369 response->head.download_file_path);
369 } 370 }
370 371
371 response->head.request_start = request()->creation_time(); 372 response->head.request_start = request()->creation_time();
372 response->head.response_start = TimeTicks::Now(); 373 response->head.response_start = TimeTicks::Now();
374 if (using_mojo_data_handle_) {
375 MojoCreateDataPipeOptions options;
376 options.struct_size = sizeof(MojoCreateDataPipeOptions);
377 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
378 options.element_num_bytes = 1;
379 options.capacity_num_bytes = kMaxAllocationSize;
380 mojo::DataPipe data_pipe(options);
381
382 writer_ = std::move(data_pipe.producer_handle);
383 GetRequestInfo()->InstallBodyReader(std::move(data_pipe.consumer_handle));
384 }
385
373 info->filter()->Send(new ResourceMsg_ReceivedResponse(GetRequestID(), 386 info->filter()->Send(new ResourceMsg_ReceivedResponse(GetRequestID(),
374 response->head)); 387 response->head));
375 sent_received_response_msg_ = true; 388 sent_received_response_msg_ = true;
376 389
377 if (request()->response_info().metadata.get()) { 390 if (request()->response_info().metadata.get()) {
378 std::vector<char> copy(request()->response_info().metadata->data(), 391 std::vector<char> copy(request()->response_info().metadata->data(),
379 request()->response_info().metadata->data() + 392 request()->response_info().metadata->data() +
380 request()->response_info().metadata->size()); 393 request()->response_info().metadata->size());
381 info->filter()->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(), 394 info->filter()->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(),
382 copy)); 395 copy));
(...skipping 21 matching lines...) Expand all
404 } 417 }
405 418
406 bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, 419 bool AsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
407 int* buf_size, 420 int* buf_size,
408 int min_size) { 421 int min_size) {
409 DCHECK_EQ(-1, min_size); 422 DCHECK_EQ(-1, min_size);
410 423
411 if (!CheckForSufficientResource()) 424 if (!CheckForSufficientResource())
412 return false; 425 return false;
413 426
427 if (using_mojo_data_handle_) {
428 void* buffer = nullptr;
429 uint32_t available = 0;
430 MojoResult result = mojo::BeginWriteDataRaw(
431 writer_.get(), &buffer, &available, MOJO_WRITE_DATA_FLAG_NONE);
432 // Note that we cannot handle SHOULD_WAIT here. It should be handled in
433 // OnReadCompleted.
434 if (result == MOJO_RESULT_OK) {
435 *buf = new net::WrappedIOBuffer(static_cast<const char*>(buffer));
436 *buf_size = available;
437 return true;
438 }
439 return false;
440 }
414 // Return early if InliningHelper allocates the buffer, so that we should 441 // Return early if InliningHelper allocates the buffer, so that we should
415 // inline the data into the IPC message without allocating SharedMemory. 442 // inline the data into the IPC message without allocating SharedMemory.
416 if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size)) 443 if (inlining_helper_->PrepareInlineBufferIfApplicable(buf, buf_size))
417 return true; 444 return true;
418 445
419 if (!EnsureResourceBufferIsInitialized()) 446 if (!EnsureResourceBufferIsInitialized())
420 return false; 447 return false;
421 448
422 DCHECK(buffer_->CanAllocate()); 449 DCHECK(buffer_->CanAllocate());
423 char* memory = buffer_->Allocate(&allocation_size_); 450 char* memory = buffer_->Allocate(&allocation_size_);
424 CHECK(memory); 451 CHECK(memory);
425 452
426 *buf = new DependentIOBuffer(buffer_.get(), memory); 453 *buf = new DependentIOBuffer(buffer_.get(), memory);
427 *buf_size = allocation_size_; 454 *buf_size = allocation_size_;
428 455
429 return true; 456 return true;
430 } 457 }
431 458
432 bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { 459 bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
433 DCHECK_GE(bytes_read, 0); 460 DCHECK_GE(bytes_read, 0);
434 461
435 if (!bytes_read) 462 if (!bytes_read)
436 return true; 463 return true;
437 464
465 if (using_mojo_data_handle_) {
466 MojoResult result = mojo::EndWriteDataRaw(writer_.get(), bytes_read);
467 if (result != MOJO_RESULT_OK)
468 return false;
469 void* buffer = nullptr;
470 uint32_t available = 0;
471 // To see if we can continue writing.
472 result = mojo::BeginWriteDataRaw(writer_.get(), &buffer, &available,
473 MOJO_WRITE_DATA_FLAG_NONE);
474 if (result == MOJO_RESULT_SHOULD_WAIT ||
475 (result == MOJO_RESULT_OK && available == 0)) {
476 *defer = did_defer_ = true;
477 OnDefer();
478 handle_watcher_.Start(writer_.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
479 MOJO_DEADLINE_INDEFINITE,
480 base::Bind(&AsyncResourceHandler::OnWritable,
481 base::Unretained(this)));
482 }
483 if (result == MOJO_RESULT_OK)
484 mojo::EndWriteDataRaw(writer_.get(), 0);
485 return true;
486 }
487
438 ResourceMessageFilter* filter = GetFilter(); 488 ResourceMessageFilter* filter = GetFilter();
439 if (!filter) 489 if (!filter)
440 return false; 490 return false;
441 491
442 int encoded_data_length = CalculateEncodedDataLengthToReport(); 492 int encoded_data_length = CalculateEncodedDataLengthToReport();
443 493
444 // Return early if InliningHelper handled the received data. 494 // Return early if InliningHelper handled the received data.
445 if (inlining_helper_->SendInlinedDataIfApplicable( 495 if (inlining_helper_->SendInlinedDataIfApplicable(
446 bytes_read, encoded_data_length, filter, GetRequestID())) 496 bytes_read, encoded_data_length, filter, GetRequestID()))
447 return true; 497 return true;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 elapsed_time, 1, 100000, 100); 651 elapsed_time, 1, 100000, 100);
602 } else { 652 } else {
603 UMA_HISTOGRAM_CUSTOM_COUNTS( 653 UMA_HISTOGRAM_CUSTOM_COUNTS(
604 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 654 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
605 elapsed_time, 1, 100000, 100); 655 elapsed_time, 1, 100000, 100);
606 } 656 }
607 657
608 inlining_helper_->RecordHistogram(elapsed_time); 658 inlining_helper_->RecordHistogram(elapsed_time);
609 } 659 }
610 660
661 void AsyncResourceHandler::OnWritable(MojoResult result) {
662 ResumeIfDeferred();
663 }
664
611 } // namespace content 665 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698