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 #ifndef CSSLazyParsingState_h | 5 #ifndef CSSLazyParsingState_h |
6 #define CSSLazyParsingState_h | 6 #define CSSLazyParsingState_h |
7 | 7 |
8 #include "core/css/CSSSelectorList.h" | 8 #include "core/css/CSSSelectorList.h" |
9 #include "core/css/StyleSheetContents.h" | 9 #include "core/css/StyleSheetContents.h" |
10 #include "core/css/parser/CSSParserMode.h" | 10 #include "core/css/parser/CSSParserMode.h" |
11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
12 #include "wtf/text/WTFString.h" | 12 #include "wtf/text/WTFString.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class CSSLazyPropertyParserImpl; | 16 class CSSLazyPropertyParserImpl; |
17 class CSSParserTokenRange; | 17 class CSSParserTokenRange; |
18 | 18 |
19 // This class helps lazy parsing by retaining necessary state. It should not | 19 // This class helps lazy parsing by retaining necessary state. It should not |
20 // outlive the StyleSheetContents that initiated the parse, as it retains a raw | 20 // outlive the StyleSheetContents that initiated the parse, as it retains a raw |
21 // reference to the UseCounter associated with the style sheet. | 21 // reference to the UseCounter associated with the style sheet. |
22 class CSSLazyParsingState | 22 class CSSLazyParsingState |
23 : public GarbageCollectedFinalized<CSSLazyParsingState> { | 23 : public GarbageCollectedFinalized<CSSLazyParsingState> { |
24 public: | 24 public: |
25 CSSLazyParsingState(const CSSParserContext&, | 25 CSSLazyParsingState(const CSSParserContext*, |
26 Vector<String> escapedStrings, | 26 Vector<String> escapedStrings, |
27 const String& sheetText, | 27 const String& sheetText, |
28 StyleSheetContents*); | 28 StyleSheetContents*); |
29 | 29 |
30 // Helper method used to bump m_totalStyleRules. | 30 // Helper method used to bump m_totalStyleRules. |
31 CSSLazyPropertyParserImpl* createLazyParser(const CSSParserTokenRange& block); | 31 CSSLazyPropertyParserImpl* createLazyParser(const CSSParserTokenRange& block); |
32 | 32 |
33 const CSSParserContext& context(); | 33 const CSSParserContext* context(); |
34 | 34 |
35 void countRuleParsed(); | 35 void countRuleParsed(); |
36 | 36 |
37 bool shouldLazilyParseProperties(const CSSSelectorList&, | 37 bool shouldLazilyParseProperties(const CSSSelectorList&, |
38 const CSSParserTokenRange& block) const; | 38 const CSSParserTokenRange& block) const; |
39 | 39 |
40 DECLARE_TRACE(); | 40 DECLARE_TRACE(); |
41 | 41 |
42 // Exposed for tests. This enum is used to back a histogram, so new values | 42 // Exposed for tests. This enum is used to back a histogram, so new values |
43 // must be appended to the end, before UsageLastValue. | 43 // must be appended to the end, before UsageLastValue. |
44 enum CSSRuleUsage { | 44 enum CSSRuleUsage { |
45 UsageGe0 = 0, | 45 UsageGe0 = 0, |
46 UsageGt10 = 1, | 46 UsageGt10 = 1, |
47 UsageGt25 = 2, | 47 UsageGt25 = 2, |
48 UsageGt50 = 3, | 48 UsageGt50 = 3, |
49 UsageGt75 = 4, | 49 UsageGt75 = 4, |
50 UsageGt90 = 5, | 50 UsageGt90 = 5, |
51 UsageAll = 6, | 51 UsageAll = 6, |
52 | 52 |
53 // This value must be last. | 53 // This value must be last. |
54 UsageLastValue = 7 | 54 UsageLastValue = 7 |
55 }; | 55 }; |
56 | 56 |
57 private: | 57 private: |
58 void recordUsageMetrics(); | 58 void recordUsageMetrics(); |
59 | 59 |
60 CSSParserContext m_context; | 60 Member<const CSSParserContext> m_context; |
61 Vector<String> m_escapedStrings; | 61 Vector<String> m_escapedStrings; |
62 // Also referenced on the css resource. | 62 // Also referenced on the css resource. |
63 String m_sheetText; | 63 String m_sheetText; |
64 | 64 |
65 // Weak to ensure lazy state will never cause the contents to live longer than | 65 // Weak to ensure lazy state will never cause the contents to live longer than |
66 // it should (we DCHECK this fact). | 66 // it should (we DCHECK this fact). |
67 WeakMember<StyleSheetContents> m_owningContents; | 67 WeakMember<StyleSheetContents> m_owningContents; |
68 | 68 |
69 // Cache the document as a proxy for caching the UseCounter. Grabbing the | 69 // Cache the document as a proxy for caching the UseCounter. Grabbing the |
70 // UseCounter per every property parse is a bit more expensive. | 70 // UseCounter per every property parse is a bit more expensive. |
71 WeakMember<Document> m_document; | 71 WeakMember<Document> m_document; |
72 | 72 |
73 // Used for calculating the % of rules that ended up being parsed. | 73 // Used for calculating the % of rules that ended up being parsed. |
74 int m_parsedStyleRules; | 74 int m_parsedStyleRules; |
75 int m_totalStyleRules; | 75 int m_totalStyleRules; |
76 | 76 |
77 int m_styleRulesNeededForNextMilestone; | 77 int m_styleRulesNeededForNextMilestone; |
78 | 78 |
79 int m_usage; | 79 int m_usage; |
80 | 80 |
81 // Whether or not use counting is enabled for parsing. This will usually be | 81 // Whether or not use counting is enabled for parsing. This will usually be |
82 // true, except for when stylesheets with @imports are removed from the page. | 82 // true, except for when stylesheets with @imports are removed from the page. |
83 // See StyleRuleImport::setCSSStyleSheet. | 83 // See StyleRuleImport::setCSSStyleSheet. |
84 const bool m_shouldUseCount; | 84 const bool m_shouldUseCount; |
85 }; | 85 }; |
86 | 86 |
87 } // namespace blink | 87 } // namespace blink |
88 | 88 |
89 #endif // CSSLazyParsingState_h | 89 #endif // CSSLazyParsingState_h |
OLD | NEW |