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

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

Issue 1378743002: Refactor the API for setting dynamic resource load priorities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better names / cleanup Created 5 years, 2 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 /* 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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 void FrameFetchContext::countClientHintsResourceWidth() 671 void FrameFetchContext::countClientHintsResourceWidth()
672 { 672 {
673 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth); 673 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth);
674 } 674 }
675 675
676 void FrameFetchContext::countClientHintsViewportWidth() 676 void FrameFetchContext::countClientHintsViewportWidth()
677 { 677 {
678 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth); 678 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth);
679 } 679 }
680 680
681 bool FrameFetchContext::fetchIncreasePriorities() const 681 ResourceLoadPriority FrameFetchContext::modifyPriorityForExperiments(ResourceLoa dPriority priority, Resource::Type type, const FetchRequest& request, ResourcePr iority::VisibilityStatus visibility)
682 {
683 return frame()->settings() && frame()->settings()->fetchIncreasePriorities() ;
684 }
685
686 ResourceLoadPriority FrameFetchContext::modifyPriorityForExperiments(ResourceLoa dPriority priority, Resource::Type type, const FetchRequest& request)
687 { 682 {
688 // An image fetch is used to distinguish between "early" and "late" scripts in a document 683 // An image fetch is used to distinguish between "early" and "late" scripts in a document
689 if (type == Resource::Image) 684 if (type == Resource::Image)
690 m_imageFetched = true; 685 m_imageFetched = true;
691 686
692 // If Settings is null, we can't verify any experiments are in force. 687 // If Settings is null, we can't verify any experiments are in force.
693 if (!frame()->settings()) 688 if (!frame()->settings())
694 return priority; 689 return priority;
695 690
696 // If enabled, drop the priority of all resources in a subframe. 691 // If enabled, drop the priority of all resources in a subframe.
697 if (frame()->settings()->lowPriorityIframes() && !frame()->isMainFrame()) 692 if (frame()->settings()->lowPriorityIframes() && !frame()->isMainFrame())
698 return ResourceLoadPriorityVeryLow; 693 return ResourceLoadPriorityVeryLow;
699 694
700 // Async/Defer scripts. 695 // Async/Defer scripts.
701 if (type == Resource::Script && FetchRequest::LazyLoad == request.defer()) 696 if (type == Resource::Script && FetchRequest::LazyLoad == request.defer())
702 return frame()->settings()->fetchIncreaseAsyncScriptPriority() ? Resourc eLoadPriorityMedium : ResourceLoadPriorityLow; 697 return frame()->settings()->fetchIncreaseAsyncScriptPriority() ? Resourc eLoadPriorityMedium : ResourceLoadPriorityLow;
703 698
704 // Runtime experiment that change how we prioritize resources. 699 // Runtime experiment that change how we prioritize resources.
705 // The toggles do not depend on each other and can be flipped individually 700 // The toggles do not depend on each other and can be flipped individually
706 // though the cumulative result will depend on the interaction between them. 701 // though the cumulative result will depend on the interaction between them.
707 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing 702 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing
708 703
709 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel 704 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel
710 // and parser-blocking scripts and visible images by 2. 705 // and parser-blocking scripts and visible images by 2.
711 // This is used in conjunction with logic on the Chrome side to raise the th reshold 706 // This is used in conjunction with logic on the Chrome side to raise the th reshold
712 // of "layout-blocking" resources and provide a boost to resources that are needed 707 // of "layout-blocking" resources and provide a boost to resources that are needed
713 // as soon as possible for something currently on the screen. 708 // as soon as possible for something currently on the screen.
714 int modifiedPriority = static_cast<int>(priority); 709 int modifiedPriority = static_cast<int>(priority);
715 if (fetchIncreasePriorities()) { 710 if (frame()->settings()->fetchIncreasePriorities()) {
716 if (type == Resource::CSSStyleSheet || type == Resource::Script || type == Resource::Font || type == Resource::Image) 711 if (type == Resource::CSSStyleSheet || type == Resource::Script || type == Resource::Font || type == Resource::Image)
717 modifiedPriority++; 712 modifiedPriority++;
718 } 713 }
719 714
715 // Always give visible resources a bump, and an additional bump if generally increasing priorities.
716 if (visibility == ResourcePriority::Visible) {
717 modifiedPriority++;
718 if (frame()->settings()->fetchIncreasePriorities())
719 modifiedPriority++;
720 }
721
720 if (frame()->settings()->fetchIncreaseFontPriority() && type == Resource::Fo nt) 722 if (frame()->settings()->fetchIncreaseFontPriority() && type == Resource::Fo nt)
721 modifiedPriority++; 723 modifiedPriority++;
722 724
723 if (type == Resource::Script) { 725 if (type == Resource::Script) {
724 // Reduce the priority of late-body scripts. 726 // Reduce the priority of late-body scripts.
725 if (frame()->settings()->fetchDeferLateScripts() && request.forPreload() && m_imageFetched) 727 if (frame()->settings()->fetchDeferLateScripts() && request.forPreload() && m_imageFetched)
726 modifiedPriority--; 728 modifiedPriority--;
727 // Parser-blocking scripts. 729 // Parser-blocking scripts.
728 if (fetchIncreasePriorities() && !request.forPreload()) 730 if (frame()->settings()->fetchIncreasePriorities() && !request.forPreloa d())
729 modifiedPriority++; 731 modifiedPriority++;
730 } 732 }
731 733
732 // Clamp priority 734 // Clamp priority
733 modifiedPriority = std::min(static_cast<int>(ResourceLoadPriorityHighest), s td::max(static_cast<int>(ResourceLoadPriorityLowest), modifiedPriority)); 735 modifiedPriority = std::min(static_cast<int>(ResourceLoadPriorityHighest), s td::max(static_cast<int>(ResourceLoadPriorityLowest), modifiedPriority));
734 return static_cast<ResourceLoadPriority>(modifiedPriority); 736 return static_cast<ResourceLoadPriority>(modifiedPriority);
735 } 737 }
736 738
737 WebTaskRunner* FrameFetchContext::loadingTaskRunner() const 739 WebTaskRunner* FrameFetchContext::loadingTaskRunner() const
738 { 740 {
739 return frame()->frameScheduler()->loadingTaskRunner(); 741 return frame()->frameScheduler()->loadingTaskRunner();
740 } 742 }
741 743
742 DEFINE_TRACE(FrameFetchContext) 744 DEFINE_TRACE(FrameFetchContext)
743 { 745 {
744 visitor->trace(m_document); 746 visitor->trace(m_document);
745 visitor->trace(m_documentLoader); 747 visitor->trace(m_documentLoader);
746 FetchContext::trace(visitor); 748 FetchContext::trace(visitor);
747 } 749 }
748 750
749 } // namespace blink 751 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698