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

Side by Side Diff: Source/core/loader/FrameFetchContext.cpp

Issue 1304063016: Refactor the API for setting dynamic resource load priorities (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/FrameFetchContext.h ('k') | Source/core/loader/FrameFetchContextTest.cpp » ('j') | 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 void FrameFetchContext::countClientHintsResourceWidth() 667 void FrameFetchContext::countClientHintsResourceWidth()
668 { 668 {
669 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth); 669 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth);
670 } 670 }
671 671
672 void FrameFetchContext::countClientHintsViewportWidth() 672 void FrameFetchContext::countClientHintsViewportWidth()
673 { 673 {
674 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth); 674 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth);
675 } 675 }
676 676
677 bool FrameFetchContext::fetchIncreasePriorities() const 677 ResourceLoadPriority FrameFetchContext::modifyPriorityForExperiments(ResourceLoa dPriority priority, Resource::Type type, const FetchRequest& request, ResourcePr iority::VisibilityStatus visibility)
678 {
679 return frame()->settings() && frame()->settings()->fetchIncreasePriorities() ;
680 }
681
682 ResourceLoadPriority FrameFetchContext::modifyPriorityForExperiments(ResourceLoa dPriority priority, Resource::Type type, const FetchRequest& request)
683 { 678 {
684 // An image fetch is used to distinguish between "early" and "late" scripts in a document 679 // An image fetch is used to distinguish between "early" and "late" scripts in a document
685 if (type == Resource::Image) 680 if (type == Resource::Image)
686 m_imageFetched = true; 681 m_imageFetched = true;
687 682
688 // If Settings is null, we can't verify any experiments are in force. 683 // If Settings is null, we can't verify any experiments are in force.
689 if (!frame()->settings()) 684 if (!frame()->settings())
690 return priority; 685 return priority;
691 686
692 // If enabled, drop the priority of all resources in a subframe. 687 // If enabled, drop the priority of all resources in a subframe.
693 if (frame()->settings()->lowPriorityIframes() && !frame()->isMainFrame()) 688 if (frame()->settings()->lowPriorityIframes() && !frame()->isMainFrame())
694 return ResourceLoadPriorityVeryLow; 689 return ResourceLoadPriorityVeryLow;
695 690
696 // Async/Defer scripts. 691 // Async/Defer scripts.
697 if (type == Resource::Script && FetchRequest::LazyLoad == request.defer()) 692 if (type == Resource::Script && FetchRequest::LazyLoad == request.defer())
698 return frame()->settings()->fetchIncreaseAsyncScriptPriority() ? Resourc eLoadPriorityMedium : ResourceLoadPriorityLow; 693 return frame()->settings()->fetchIncreaseAsyncScriptPriority() ? Resourc eLoadPriorityMedium : ResourceLoadPriorityLow;
699 694
700 // Runtime experiment that change how we prioritize resources. 695 // Runtime experiment that change how we prioritize resources.
701 // The toggles do not depend on each other and can be flipped individually 696 // The toggles do not depend on each other and can be flipped individually
702 // though the cumulative result will depend on the interaction between them. 697 // though the cumulative result will depend on the interaction between them.
703 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing 698 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing
704 699
705 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel 700 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel
706 // and parser-blocking scripts and visible images by 2. 701 // and parser-blocking scripts and visible images by 2.
707 // This is used in conjunction with logic on the Chrome side to raise the th reshold 702 // This is used in conjunction with logic on the Chrome side to raise the th reshold
708 // of "layout-blocking" resources and provide a boost to resources that are needed 703 // of "layout-blocking" resources and provide a boost to resources that are needed
709 // as soon as possible for something currently on the screen. 704 // as soon as possible for something currently on the screen.
710 int modifiedPriority = static_cast<int>(priority); 705 int modifiedPriority = static_cast<int>(priority);
711 if (fetchIncreasePriorities()) { 706 if (frame()->settings()->fetchIncreasePriorities()) {
712 if (type == Resource::CSSStyleSheet || type == Resource::Script || type == Resource::Font || type == Resource::Image) 707 if (type == Resource::CSSStyleSheet || type == Resource::Script || type == Resource::Font || type == Resource::Image)
713 modifiedPriority++; 708 modifiedPriority++;
714 } 709 }
715 710
711 // Always give visible resources a bump, and an additional bump if generally increasing priorities.
712 if (visibility == ResourcePriority::Visible) {
713 modifiedPriority++;
714 if (frame()->settings()->fetchIncreasePriorities())
715 modifiedPriority++;
716 }
717
716 if (frame()->settings()->fetchIncreaseFontPriority() && type == Resource::Fo nt) 718 if (frame()->settings()->fetchIncreaseFontPriority() && type == Resource::Fo nt)
717 modifiedPriority++; 719 modifiedPriority++;
718 720
719 if (type == Resource::Script) { 721 if (type == Resource::Script) {
720 // Reduce the priority of late-body scripts. 722 // Reduce the priority of late-body scripts.
721 if (frame()->settings()->fetchDeferLateScripts() && request.forPreload() && m_imageFetched) 723 if (frame()->settings()->fetchDeferLateScripts() && request.forPreload() && m_imageFetched)
722 modifiedPriority--; 724 modifiedPriority--;
723 // Parser-blocking scripts. 725 // Parser-blocking scripts.
724 if (fetchIncreasePriorities() && !request.forPreload()) 726 if (frame()->settings()->fetchIncreasePriorities() && !request.forPreloa d())
725 modifiedPriority++; 727 modifiedPriority++;
726 } 728 }
727 729
728 // Clamp priority 730 // Clamp priority
729 modifiedPriority = std::min(static_cast<int>(ResourceLoadPriorityHighest), s td::max(static_cast<int>(ResourceLoadPriorityLowest), modifiedPriority)); 731 modifiedPriority = std::min(static_cast<int>(ResourceLoadPriorityHighest), s td::max(static_cast<int>(ResourceLoadPriorityLowest), modifiedPriority));
730 return static_cast<ResourceLoadPriority>(modifiedPriority); 732 return static_cast<ResourceLoadPriority>(modifiedPriority);
731 } 733 }
732 734
733 DEFINE_TRACE(FrameFetchContext) 735 DEFINE_TRACE(FrameFetchContext)
734 { 736 {
735 visitor->trace(m_document); 737 visitor->trace(m_document);
736 visitor->trace(m_documentLoader); 738 visitor->trace(m_documentLoader);
737 FetchContext::trace(visitor); 739 FetchContext::trace(visitor);
738 } 740 }
739 741
740 } // namespace blink 742 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/FrameFetchContext.h ('k') | Source/core/loader/FrameFetchContextTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698