| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/css/parser/CSSLazyParsingState.h" | 5 #include "core/css/parser/CSSLazyParsingState.h" |
| 6 #include "core/css/parser/CSSLazyPropertyParserImpl.h" | 6 #include "core/css/parser/CSSLazyPropertyParserImpl.h" |
| 7 #include "core/css/parser/CSSParserTokenRange.h" | 7 #include "core/css/parser/CSSParserTokenRange.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
| 10 #include "platform/Histogram.h" | 10 #include "platform/Histogram.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext* context, | 14 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext* context, |
| 15 Vector<String> escapedStrings, | 15 Vector<String> escapedStrings, |
| 16 const String& sheetText, | 16 const String& sheetText, |
| 17 StyleSheetContents* contents) | 17 StyleSheetContents* contents) |
| 18 : m_context(context), | 18 : m_context(context), |
| 19 m_escapedStrings(std::move(escapedStrings)), | 19 m_escapedStrings(std::move(escapedStrings)), |
| 20 m_sheetText(sheetText), | 20 m_sheetText(sheetText), |
| 21 m_owningContents(contents), | 21 m_owningContents(contents), |
| 22 m_parsedStyleRules(0), | 22 m_parsedStyleRules(0), |
| 23 m_totalStyleRules(0), | 23 m_totalStyleRules(0), |
| 24 m_styleRulesNeededForNextMilestone(0), | 24 m_styleRulesNeededForNextMilestone(0), |
| 25 m_usage(UsageGe0), | 25 m_usage(UsageGe0), |
| 26 m_shouldUseCount(m_context->isUseCounterRecordingEnabled()) { | 26 m_shouldUseCount(m_context->isUseCounterRecordingEnabled()) {} |
| 27 |
| 28 void CSSLazyParsingState::finishInitialParsing() { |
| 27 recordUsageMetrics(); | 29 recordUsageMetrics(); |
| 28 } | 30 } |
| 29 | 31 |
| 30 CSSLazyPropertyParserImpl* CSSLazyParsingState::createLazyParser( | 32 CSSLazyPropertyParserImpl* CSSLazyParsingState::createLazyParser( |
| 31 const CSSParserTokenRange& block) { | 33 const CSSParserTokenRange& block) { |
| 32 ++m_totalStyleRules; | 34 ++m_totalStyleRules; |
| 33 return new CSSLazyPropertyParserImpl(std::move(block), this); | 35 return new CSSLazyPropertyParserImpl(std::move(block), this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 const CSSParserContext* CSSLazyParsingState::context() { | 38 const CSSParserContext* CSSLazyParsingState::context() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (current->relation() != CSSSelector::SubSelector) | 86 if (current->relation() != CSSSelector::SubSelector) |
| 85 break; | 87 break; |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 return true; | 90 return true; |
| 89 } | 91 } |
| 90 | 92 |
| 91 void CSSLazyParsingState::recordUsageMetrics() { | 93 void CSSLazyParsingState::recordUsageMetrics() { |
| 92 DEFINE_STATIC_LOCAL(EnumerationHistogram, usageHistogram, | 94 DEFINE_STATIC_LOCAL(EnumerationHistogram, usageHistogram, |
| 93 ("Style.LazyUsage.Percent", UsageLastValue)); | 95 ("Style.LazyUsage.Percent", UsageLastValue)); |
| 96 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesHistogram, |
| 97 ("Style.TotalLazyRules", 0, 100000, 50)); |
| 98 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesFullUsageHistogram, |
| 99 ("Style.TotalLazyRules.FullUsage", 0, 100000, 50)); |
| 94 switch (m_usage) { | 100 switch (m_usage) { |
| 95 case UsageGe0: | 101 case UsageGe0: |
| 102 totalRulesHistogram.count(m_totalStyleRules); |
| 96 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .1; | 103 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .1; |
| 97 break; | 104 break; |
| 98 case UsageGt10: | 105 case UsageGt10: |
| 99 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .25; | 106 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .25; |
| 100 break; | 107 break; |
| 101 case UsageGt25: | 108 case UsageGt25: |
| 102 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .5; | 109 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .5; |
| 103 break; | 110 break; |
| 104 case UsageGt50: | 111 case UsageGt50: |
| 105 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .75; | 112 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .75; |
| 106 break; | 113 break; |
| 107 case UsageGt75: | 114 case UsageGt75: |
| 108 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .9; | 115 m_styleRulesNeededForNextMilestone = m_totalStyleRules * .9; |
| 109 break; | 116 break; |
| 110 case UsageGt90: | 117 case UsageGt90: |
| 111 m_styleRulesNeededForNextMilestone = m_totalStyleRules - 1; | 118 m_styleRulesNeededForNextMilestone = m_totalStyleRules - 1; |
| 112 break; | 119 break; |
| 113 case UsageAll: | 120 case UsageAll: |
| 121 totalRulesFullUsageHistogram.count(m_totalStyleRules); |
| 114 m_styleRulesNeededForNextMilestone = m_totalStyleRules; | 122 m_styleRulesNeededForNextMilestone = m_totalStyleRules; |
| 115 break; | 123 break; |
| 116 } | 124 } |
| 117 | 125 |
| 118 usageHistogram.count(m_usage); | 126 usageHistogram.count(m_usage); |
| 119 } | 127 } |
| 120 | 128 |
| 121 DEFINE_TRACE(CSSLazyParsingState) { | 129 DEFINE_TRACE(CSSLazyParsingState) { |
| 122 visitor->trace(m_owningContents); | 130 visitor->trace(m_owningContents); |
| 123 visitor->trace(m_document); | 131 visitor->trace(m_document); |
| 124 visitor->trace(m_context); | 132 visitor->trace(m_context); |
| 125 } | 133 } |
| 126 | 134 |
| 127 } // namespace blink | 135 } // namespace blink |
| OLD | NEW |