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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: incorporated kinuko's comment Created 4 years 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 allocation_size_(0), 210 allocation_size_(0),
211 did_defer_(false), 211 did_defer_(false),
212 has_checked_for_sufficient_resources_(false), 212 has_checked_for_sufficient_resources_(false),
213 sent_received_response_msg_(false), 213 sent_received_response_msg_(false),
214 sent_data_buffer_msg_(false), 214 sent_data_buffer_msg_(false),
215 inlining_helper_(new InliningHelper), 215 inlining_helper_(new InliningHelper),
216 last_upload_position_(0), 216 last_upload_position_(0),
217 waiting_for_upload_progress_ack_(false), 217 waiting_for_upload_progress_ack_(false),
218 reported_transfer_size_(0), 218 reported_transfer_size_(0),
219 reported_encoded_body_length_(0) { 219 reported_encoded_body_length_(0) {
220 DCHECK(GetRequestInfo()->requester_info().IsRenderer());
220 InitializeResourceBufferConstants(); 221 InitializeResourceBufferConstants();
221 } 222 }
222 223
223 AsyncResourceHandler::~AsyncResourceHandler() { 224 AsyncResourceHandler::~AsyncResourceHandler() {
224 if (has_checked_for_sufficient_resources_) 225 if (has_checked_for_sufficient_resources_)
225 rdh_->FinishedWithResourcesForRequest(request()); 226 rdh_->FinishedWithResourcesForRequest(request());
226 } 227 }
227 228
228 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) { 229 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) {
229 bool handled = true; 230 bool handled = true;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 waiting_for_upload_progress_ack_ = true; 294 waiting_for_upload_progress_ack_ = true;
294 last_upload_ticks_ = TimeTicks::Now(); 295 last_upload_ticks_ = TimeTicks::Now();
295 last_upload_position_ = progress.position(); 296 last_upload_position_ = progress.position();
296 } 297 }
297 } 298 }
298 299
299 bool AsyncResourceHandler::OnRequestRedirected( 300 bool AsyncResourceHandler::OnRequestRedirected(
300 const net::RedirectInfo& redirect_info, 301 const net::RedirectInfo& redirect_info,
301 ResourceResponse* response, 302 ResourceResponse* response,
302 bool* defer) { 303 bool* defer) {
303 const ResourceRequestInfoImpl* info = GetRequestInfo(); 304 ResourceMessageFilter* filter = GetFilter();
304 if (!info->filter()) 305 if (!filter)
305 return false; 306 return false;
306 307
307 *defer = did_defer_ = true; 308 *defer = did_defer_ = true;
308 OnDefer(); 309 OnDefer();
309 310
310 NetLogObserver::PopulateResponseInfo(request(), response); 311 NetLogObserver::PopulateResponseInfo(request(), response);
311 response->head.encoded_data_length = request()->GetTotalReceivedBytes(); 312 response->head.encoded_data_length = request()->GetTotalReceivedBytes();
312 reported_transfer_size_ = 0; 313 reported_transfer_size_ = 0;
313 response->head.request_start = request()->creation_time(); 314 response->head.request_start = request()->creation_time();
314 response->head.response_start = TimeTicks::Now(); 315 response->head.response_start = TimeTicks::Now();
315 // TODO(davidben): Is it necessary to pass the new first party URL for 316 // TODO(davidben): Is it necessary to pass the new first party URL for
316 // cookies? The only case where it can change is top-level navigation requests 317 // cookies? The only case where it can change is top-level navigation requests
317 // and hopefully those will eventually all be owned by the browser. It's 318 // and hopefully those will eventually all be owned by the browser. It's
318 // possible this is still needed while renderer-owned ones exist. 319 // possible this is still needed while renderer-owned ones exist.
319 return info->filter()->Send(new ResourceMsg_ReceivedRedirect( 320 return filter->Send(new ResourceMsg_ReceivedRedirect(
320 GetRequestID(), redirect_info, response->head)); 321 GetRequestID(), redirect_info, response->head));
321 } 322 }
322 323
323 bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 324 bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
324 bool* defer) { 325 bool* defer) {
325 // For changes to the main frame, inform the renderer of the new URL's 326 // For changes to the main frame, inform the renderer of the new URL's
326 // per-host settings before the request actually commits. This way the 327 // per-host settings before the request actually commits. This way the
327 // renderer will be able to set these precisely at the time the 328 // renderer will be able to set these precisely at the time the
328 // request commits, avoiding the possibility of e.g. zooming the old content 329 // request commits, avoiding the possibility of e.g. zooming the old content
329 // or of having to layout the new content twice. 330 // or of having to layout the new content twice.
330 331
331 response_started_ticks_ = base::TimeTicks::Now(); 332 response_started_ticks_ = base::TimeTicks::Now();
332 333
333 progress_timer_.Stop(); 334 progress_timer_.Stop();
334 const ResourceRequestInfoImpl* info = GetRequestInfo(); 335 const ResourceRequestInfoImpl* info = GetRequestInfo();
mmenke 2016/11/21 19:51:55 nit: Move this down to just above the line where
horo 2016/11/22 01:12:07 Done.
335 if (!info->filter()) 336 ResourceMessageFilter* filter = GetFilter();
337 if (!filter)
336 return false; 338 return false;
337 339
338 // We want to send a final upload progress message prior to sending the 340 // We want to send a final upload progress message prior to sending the
339 // response complete message even if we're waiting for an ack to to a 341 // response complete message even if we're waiting for an ack to to a
340 // previous upload progress message. 342 // previous upload progress message.
341 if (info->is_upload_progress_enabled()) { 343 if (info->is_upload_progress_enabled()) {
342 waiting_for_upload_progress_ack_ = false; 344 waiting_for_upload_progress_ack_ = false;
343 ReportUploadProgress(); 345 ReportUploadProgress();
344 } 346 }
345 347
346 if (rdh_->delegate()) { 348 if (rdh_->delegate()) {
347 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(), 349 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
348 response); 350 response);
349 } 351 }
350 352
351 NetLogObserver::PopulateResponseInfo(request(), response); 353 NetLogObserver::PopulateResponseInfo(request(), response);
352 response->head.encoded_data_length = request()->raw_header_size(); 354 response->head.encoded_data_length = request()->raw_header_size();
353 355
354 // If the parent handler downloaded the resource to a file, grant the child 356 // If the parent handler downloaded the resource to a file, grant the child
355 // read permissions on it. 357 // read permissions on it.
356 if (!response->head.download_file_path.empty()) { 358 if (!response->head.download_file_path.empty()) {
357 rdh_->RegisterDownloadedTempFile( 359 rdh_->RegisterDownloadedTempFile(
358 info->GetChildID(), info->GetRequestID(), 360 info->GetChildID(), info->GetRequestID(),
359 response->head.download_file_path); 361 response->head.download_file_path);
360 } 362 }
361 363
362 response->head.request_start = request()->creation_time(); 364 response->head.request_start = request()->creation_time();
363 response->head.response_start = TimeTicks::Now(); 365 response->head.response_start = TimeTicks::Now();
364 info->filter()->Send(new ResourceMsg_ReceivedResponse(GetRequestID(), 366 filter->Send(
365 response->head)); 367 new ResourceMsg_ReceivedResponse(GetRequestID(), response->head));
366 sent_received_response_msg_ = true; 368 sent_received_response_msg_ = true;
367 369
368 if (request()->response_info().metadata.get()) { 370 if (request()->response_info().metadata.get()) {
369 std::vector<char> copy(request()->response_info().metadata->data(), 371 std::vector<char> copy(request()->response_info().metadata->data(),
370 request()->response_info().metadata->data() + 372 request()->response_info().metadata->data() +
371 request()->response_info().metadata->size()); 373 request()->response_info().metadata->size());
372 info->filter()->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(), 374 filter->Send(new ResourceMsg_ReceivedCachedMetadata(GetRequestID(), copy));
373 copy));
374 } 375 }
375 376
376 inlining_helper_->OnResponseReceived(*response); 377 inlining_helper_->OnResponseReceived(*response);
377 return true; 378 return true;
378 } 379 }
379 380
380 bool AsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { 381 bool AsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
381 if (GetRequestInfo()->is_upload_progress_enabled() && 382 if (GetRequestInfo()->is_upload_progress_enabled() &&
382 request()->has_upload()) { 383 request()->has_upload()) {
383 ReportUploadProgress(); 384 ReportUploadProgress();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 ResourceMessageFilter* filter = GetFilter(); 474 ResourceMessageFilter* filter = GetFilter();
474 if (filter) { 475 if (filter) {
475 filter->Send(new ResourceMsg_DataDownloaded( 476 filter->Send(new ResourceMsg_DataDownloaded(
476 GetRequestID(), bytes_downloaded, encoded_data_length)); 477 GetRequestID(), bytes_downloaded, encoded_data_length));
477 } 478 }
478 } 479 }
479 480
480 void AsyncResourceHandler::OnResponseCompleted( 481 void AsyncResourceHandler::OnResponseCompleted(
481 const net::URLRequestStatus& status, 482 const net::URLRequestStatus& status,
482 bool* defer) { 483 bool* defer) {
483 const ResourceRequestInfoImpl* info = GetRequestInfo(); 484 const ResourceRequestInfoImpl* info = GetRequestInfo();
mmenke 2016/11/21 19:51:55 Move is to just above first use.
horo 2016/11/22 01:12:07 Done.
484 if (!info->filter()) 485 ResourceMessageFilter* filter = GetFilter();
486 if (!filter)
485 return; 487 return;
486 488
487 // If we crash here, figure out what URL the renderer was requesting. 489 // If we crash here, figure out what URL the renderer was requesting.
488 // http://crbug.com/107692 490 // http://crbug.com/107692
489 char url_buf[128]; 491 char url_buf[128];
490 base::strlcpy(url_buf, request()->url().spec().c_str(), arraysize(url_buf)); 492 base::strlcpy(url_buf, request()->url().spec().c_str(), arraysize(url_buf));
491 base::debug::Alias(url_buf); 493 base::debug::Alias(url_buf);
492 494
493 // TODO(gavinp): Remove this CHECK when we figure out the cause of 495 // TODO(gavinp): Remove this CHECK when we figure out the cause of
494 // http://crbug.com/124680 . This check mirrors closely check in 496 // http://crbug.com/124680 . This check mirrors closely check in
(...skipping 12 matching lines...) Expand all
507 // the ERR_ABORTED error code). 509 // the ERR_ABORTED error code).
508 DCHECK(!was_ignored_by_handler || error_code == net::ERR_ABORTED); 510 DCHECK(!was_ignored_by_handler || error_code == net::ERR_ABORTED);
509 511
510 ResourceRequestCompletionStatus request_complete_data; 512 ResourceRequestCompletionStatus request_complete_data;
511 request_complete_data.error_code = error_code; 513 request_complete_data.error_code = error_code;
512 request_complete_data.was_ignored_by_handler = was_ignored_by_handler; 514 request_complete_data.was_ignored_by_handler = was_ignored_by_handler;
513 request_complete_data.exists_in_cache = request()->response_info().was_cached; 515 request_complete_data.exists_in_cache = request()->response_info().was_cached;
514 request_complete_data.completion_time = TimeTicks::Now(); 516 request_complete_data.completion_time = TimeTicks::Now();
515 request_complete_data.encoded_data_length = 517 request_complete_data.encoded_data_length =
516 request()->GetTotalReceivedBytes(); 518 request()->GetTotalReceivedBytes();
517 info->filter()->Send( 519 filter->Send(
518 new ResourceMsg_RequestComplete(GetRequestID(), request_complete_data)); 520 new ResourceMsg_RequestComplete(GetRequestID(), request_complete_data));
519 521
520 if (status.is_success()) 522 if (status.is_success())
521 RecordHistogram(); 523 RecordHistogram();
522 } 524 }
523 525
524 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() { 526 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() {
525 DCHECK(has_checked_for_sufficient_resources_); 527 DCHECK(has_checked_for_sufficient_resources_);
526 528
527 if (buffer_.get() && buffer_->IsInitialized()) 529 if (buffer_.get() && buffer_->IsInitialized())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } else { 589 } else {
588 UMA_HISTOGRAM_CUSTOM_COUNTS( 590 UMA_HISTOGRAM_CUSTOM_COUNTS(
589 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 591 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
590 elapsed_time, 1, 100000, 100); 592 elapsed_time, 1, 100000, 100);
591 } 593 }
592 594
593 inlining_helper_->RecordHistogram(elapsed_time); 595 inlining_helper_->RecordHistogram(elapsed_time);
594 } 596 }
595 597
596 } // namespace content 598 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698