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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp

Issue 2660213003: Split requestResource into request preparation and loading (Closed)
Patch Set: refactor so it makes more sense Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 rights reserved. 6 rights reserved.
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // Aims to count Resource only referenced from MemoryCache (i.e. what would be 446 // Aims to count Resource only referenced from MemoryCache (i.e. what would be
447 // dead if MemoryCache holds weak references to Resource). Currently we check 447 // dead if MemoryCache holds weak references to Resource). Currently we check
448 // references to Resource from ResourceClient and |m_preloads| only, because 448 // references to Resource from ResourceClient and |m_preloads| only, because
449 // they are major sources of references. 449 // they are major sources of references.
450 if (resource && !resource->isAlive() && 450 if (resource && !resource->isAlive() &&
451 (!m_preloads || !m_preloads->contains(resource))) { 451 (!m_preloads || !m_preloads->contains(resource))) {
452 DEFINE_RESOURCE_HISTOGRAM("Dead."); 452 DEFINE_RESOURCE_HISTOGRAM("Dead.");
453 } 453 }
454 } 454 }
455 455
456 Resource* ResourceFetcher::requestResource( 456 bool ResourceFetcher::prepareRequest(FetchRequest& request,
457 FetchRequest& request, 457 const ResourceFactory& factory,
458 const ResourceFactory& factory, 458 const SubstituteData& substituteData,
459 const SubstituteData& substituteData) { 459 unsigned long identifier,
460 Resource*& resource) {
Nate Chapin 2017/01/31 19:40:22 "Resource*&" is dubious. Maybe return an enum: en
460 ResourceRequest& resourceRequest = request.mutableResourceRequest(); 461 ResourceRequest& resourceRequest = request.mutableResourceRequest();
461 462
462 unsigned long identifier = createUniqueIdentifier();
463 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker(
464 identifier, resourceRequest);
465 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime");
466 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || 463 DCHECK(request.options().synchronousPolicy == RequestAsynchronously ||
467 factory.type() == Resource::Raw || 464 factory.type() == Resource::Raw ||
468 factory.type() == Resource::XSLStyleSheet); 465 factory.type() == Resource::XSLStyleSheet);
469 466
470 context().populateResourceRequest( 467 context().populateResourceRequest(
471 factory.type(), request.clientHintsPreferences(), 468 factory.type(), request.clientHintsPreferences(),
472 request.getResourceWidth(), resourceRequest); 469 request.getResourceWidth(), resourceRequest);
473 470
474 // TODO(dproy): Remove this. http://crbug.com/659666
475 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url",
476 urlForTraceEvent(request.url()));
477
478 if (!request.url().isValid()) 471 if (!request.url().isValid())
479 return nullptr; 472 return false;
480 473
481 resourceRequest.setPriority(computeLoadPriority( 474 resourceRequest.setPriority(computeLoadPriority(
482 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible, 475 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible,
483 request.defer(), request.forPreload())); 476 request.defer(), request.forPreload()));
484 initializeResourceRequest(resourceRequest, factory.type(), request.defer()); 477 initializeResourceRequest(resourceRequest, factory.type(), request.defer());
485 network_instrumentation::resourcePrioritySet(identifier, 478 network_instrumentation::resourcePrioritySet(identifier,
486 resourceRequest.priority()); 479 resourceRequest.priority());
487 480
488 ResourceRequestBlockedReason blockedReason = context().canRequest( 481 ResourceRequestBlockedReason blockedReason = context().canRequest(
489 factory.type(), resourceRequest, 482 factory.type(), resourceRequest,
490 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), 483 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()),
491 request.options(), request.forPreload(), request.getOriginRestriction()); 484 request.options(), request.forPreload(), request.getOriginRestriction());
492 if (blockedReason != ResourceRequestBlockedReason::None) { 485 if (blockedReason != ResourceRequestBlockedReason::None) {
493 DCHECK(!substituteData.forceSynchronousLoad()); 486 DCHECK(!substituteData.forceSynchronousLoad());
494 return resourceForBlockedRequest(request, factory, blockedReason); 487 resource = resourceForBlockedRequest(request, factory, blockedReason);
488 return false;
495 } 489 }
496 490
497 context().willStartLoadingResource( 491 context().willStartLoadingResource(
498 identifier, resourceRequest, factory.type(), 492 identifier, resourceRequest, factory.type(),
499 request.options().initiatorInfo.name, request.forPreload()); 493 request.options().initiatorInfo.name, request.forPreload());
500 if (!request.url().isValid()) 494 if (!request.url().isValid())
501 return nullptr; 495 return false;
496
497 resourceRequest.setAllowStoredCredentials(
498 request.options().allowCredentials == AllowStoredCredentials);
499 return true;
500 }
501
502 Resource* ResourceFetcher::requestResource(
503 FetchRequest& request,
504 const ResourceFactory& factory,
505 const SubstituteData& substituteData) {
506 unsigned long identifier = createUniqueIdentifier();
507 ResourceRequest& resourceRequest = request.mutableResourceRequest();
508 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker(
509 identifier, resourceRequest);
510 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime");
511 // TODO(dproy): Remove this. http://crbug.com/659666
512 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url",
513 urlForTraceEvent(request.url()));
514
515 Resource* resource = nullptr;
516
517 if (!prepareRequest(request, factory, substituteData, identifier, resource))
518 return resource;
502 519
503 bool isDataUrl = resourceRequest.url().protocolIsData(); 520 bool isDataUrl = resourceRequest.url().protocolIsData();
504 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; 521 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive;
505 Resource* resource(nullptr);
506 if (isStaticData) { 522 if (isStaticData) {
507 resource = resourceForStaticData(request, factory, substituteData); 523 resource = resourceForStaticData(request, factory, substituteData);
508 // Abort the request if the archive doesn't contain the resource, except in 524 // Abort the request if the archive doesn't contain the resource, except in
509 // the case of data URLs which might have resources such as fonts that need 525 // the case of data URLs which might have resources such as fonts that need
510 // to be decoded only on demand. These data URLs are allowed to be 526 // to be decoded only on demand. These data URLs are allowed to be
511 // processed using the normal ResourceFetcher machinery. 527 // processed using the normal ResourceFetcher machinery.
512 if (!resource && !isDataUrl && m_archive) 528 if (!resource && !isDataUrl && m_archive)
513 return nullptr; 529 return nullptr;
514 } 530 }
515 if (!resource) { 531 if (!resource) {
516 resource = 532 resource =
517 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); 533 memoryCache()->resourceForURL(request.url(), getCacheIdentifier());
518 } 534 }
519 535
520 // See if we can use an existing resource from the cache. If so, we need to 536 // See if we can use an existing resource from the cache. If so, we need to
521 // move it to be load blocking. 537 // move it to be load blocking.
522 moveCachedNonBlockingResourceToBlocking(resource, request); 538 moveCachedNonBlockingResourceToBlocking(resource, request);
523 539
524 const RevalidationPolicy policy = determineRevalidationPolicy( 540 const RevalidationPolicy policy = determineRevalidationPolicy(
525 factory.type(), request, resource, isStaticData); 541 factory.type(), request, resource, isStaticData);
526 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", 542 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy",
527 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); 543 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy);
528 544
529 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); 545 updateMemoryCacheStats(resource, policy, request, factory, isStaticData);
530 546
531 resourceRequest.setAllowStoredCredentials(
532 request.options().allowCredentials == AllowStoredCredentials);
533
534 switch (policy) { 547 switch (policy) {
535 case Reload: 548 case Reload:
536 memoryCache()->remove(resource); 549 memoryCache()->remove(resource);
537 // Fall through 550 // Fall through
538 case Load: 551 case Load:
539 resource = createResourceForLoading(request, request.charset(), factory); 552 resource = createResourceForLoading(request, request.charset(), factory);
540 break; 553 break;
541 case Revalidate: 554 case Revalidate:
542 initializeRevalidation(resourceRequest, resource); 555 initializeRevalidation(resourceRequest, resource);
543 break; 556 break;
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 visitor->trace(m_context); 1519 visitor->trace(m_context);
1507 visitor->trace(m_archive); 1520 visitor->trace(m_archive);
1508 visitor->trace(m_loaders); 1521 visitor->trace(m_loaders);
1509 visitor->trace(m_nonBlockingLoaders); 1522 visitor->trace(m_nonBlockingLoaders);
1510 visitor->trace(m_documentResources); 1523 visitor->trace(m_documentResources);
1511 visitor->trace(m_preloads); 1524 visitor->trace(m_preloads);
1512 visitor->trace(m_resourceTimingInfoMap); 1525 visitor->trace(m_resourceTimingInfoMap);
1513 } 1526 }
1514 1527
1515 } // namespace blink 1528 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698