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