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