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 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/dom/PresentationAttributeStyle.h" | 31 #include "core/dom/PresentationAttributeStyle.h" |
32 | 32 |
33 #include "core/css/StylePropertySet.h" | 33 #include "core/css/StylePropertySet.h" |
34 #include "core/dom/Attribute.h" | 34 #include "core/dom/Attribute.h" |
35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
36 #include "core/html/HTMLInputElement.h" | 36 #include "core/html/HTMLInputElement.h" |
37 #include "platform/Timer.h" | 37 #include "platform/Timer.h" |
| 38 #include "public/platform/Platform.h" |
| 39 #include "public/platform/WebScheduler.h" |
| 40 #include "public/platform/WebThread.h" |
38 #include "wtf/HashFunctions.h" | 41 #include "wtf/HashFunctions.h" |
39 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
40 #include "wtf/text/CString.h" | 43 #include "wtf/text/CString.h" |
41 #include <algorithm> | 44 #include <algorithm> |
42 | 45 |
43 namespace blink { | 46 namespace blink { |
44 | 47 |
45 using namespace HTMLNames; | 48 using namespace HTMLNames; |
46 | 49 |
47 struct PresentationAttributeCacheKey { | 50 struct PresentationAttributeCacheKey { |
(...skipping 21 matching lines...) Expand all Loading... |
69 using PresentationAttributeCache = | 72 using PresentationAttributeCache = |
70 HeapHashMap<unsigned, | 73 HeapHashMap<unsigned, |
71 Member<PresentationAttributeCacheEntry>, | 74 Member<PresentationAttributeCacheEntry>, |
72 AlreadyHashed>; | 75 AlreadyHashed>; |
73 static PresentationAttributeCache& presentationAttributeCache() { | 76 static PresentationAttributeCache& presentationAttributeCache() { |
74 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, | 77 DEFINE_STATIC_LOCAL(PresentationAttributeCache, cache, |
75 (new PresentationAttributeCache)); | 78 (new PresentationAttributeCache)); |
76 return cache; | 79 return cache; |
77 } | 80 } |
78 | 81 |
| 82 // This is a singleton (held via DEFINE_STATIC_LOCAL). |
| 83 // Thus it is appropriate to use the main thread's timer task runner, rather |
| 84 // than one associated with a particular frame. |
79 class PresentationAttributeCacheCleaner { | 85 class PresentationAttributeCacheCleaner { |
80 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); | 86 WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); |
81 USING_FAST_MALLOC(PresentationAttributeCacheCleaner); | 87 USING_FAST_MALLOC(PresentationAttributeCacheCleaner); |
82 | 88 |
83 public: | 89 public: |
84 PresentationAttributeCacheCleaner() | 90 PresentationAttributeCacheCleaner() |
85 : m_hitCount(0), | 91 : m_hitCount(0), |
86 m_cleanTimer(this, &PresentationAttributeCacheCleaner::cleanCache) {} | 92 m_cleanTimer( |
| 93 Platform::current()->mainThread()->scheduler()->timerTaskRunner(), |
| 94 this, |
| 95 &PresentationAttributeCacheCleaner::cleanCache) {} |
87 | 96 |
88 void didHitPresentationAttributeCache() { | 97 void didHitPresentationAttributeCache() { |
89 if (presentationAttributeCache().size() < | 98 if (presentationAttributeCache().size() < |
90 minimumPresentationAttributeCacheSizeForCleaning) | 99 minimumPresentationAttributeCacheSizeForCleaning) |
91 return; | 100 return; |
92 | 101 |
93 m_hitCount++; | 102 m_hitCount++; |
94 | 103 |
95 if (!m_cleanTimer.isActive()) | 104 if (!m_cleanTimer.isActive()) |
96 m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds, | 105 m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds, |
97 BLINK_FROM_HERE); | 106 BLINK_FROM_HERE); |
98 } | 107 } |
99 | 108 |
100 private: | 109 private: |
101 static const unsigned presentationAttributeCacheCleanTimeInSeconds = 60; | 110 static const unsigned presentationAttributeCacheCleanTimeInSeconds = 60; |
102 static const unsigned minimumPresentationAttributeCacheSizeForCleaning = 100; | 111 static const unsigned minimumPresentationAttributeCacheSizeForCleaning = 100; |
103 static const unsigned minimumPresentationAttributeCacheHitCountPerMinute = | 112 static const unsigned minimumPresentationAttributeCacheHitCountPerMinute = |
104 (100 * presentationAttributeCacheCleanTimeInSeconds) / 60; | 113 (100 * presentationAttributeCacheCleanTimeInSeconds) / 60; |
105 | 114 |
106 void cleanCache(TimerBase* timer) { | 115 void cleanCache(TimerBase* timer) { |
107 DCHECK_EQ(timer, &m_cleanTimer); | 116 DCHECK_EQ(timer, &m_cleanTimer); |
108 unsigned hitCount = m_hitCount; | 117 unsigned hitCount = m_hitCount; |
109 m_hitCount = 0; | 118 m_hitCount = 0; |
110 if (hitCount > minimumPresentationAttributeCacheHitCountPerMinute) | 119 if (hitCount > minimumPresentationAttributeCacheHitCountPerMinute) |
111 return; | 120 return; |
112 presentationAttributeCache().clear(); | 121 presentationAttributeCache().clear(); |
113 } | 122 } |
114 | 123 |
115 unsigned m_hitCount; | 124 unsigned m_hitCount; |
116 Timer<PresentationAttributeCacheCleaner> m_cleanTimer; | 125 TaskRunnerTimer<PresentationAttributeCacheCleaner> m_cleanTimer; |
117 }; | 126 }; |
118 | 127 |
119 static bool attributeNameSort(const std::pair<StringImpl*, AtomicString>& p1, | 128 static bool attributeNameSort(const std::pair<StringImpl*, AtomicString>& p1, |
120 const std::pair<StringImpl*, AtomicString>& p2) { | 129 const std::pair<StringImpl*, AtomicString>& p2) { |
121 // Sort based on the attribute name pointers. It doesn't matter what the order | 130 // Sort based on the attribute name pointers. It doesn't matter what the order |
122 // is as long as it is always the same. | 131 // is as long as it is always the same. |
123 return p1.first < p2.first; | 132 return p1.first < p2.first; |
124 } | 133 } |
125 | 134 |
126 static void makePresentationAttributeCacheKey( | 135 static void makePresentationAttributeCacheKey( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 presentationAttributeCache().clear(); | 224 presentationAttributeCache().clear(); |
216 presentationAttributeCache().set(cacheHash, newEntry); | 225 presentationAttributeCache().set(cacheHash, newEntry); |
217 } else { | 226 } else { |
218 cacheValue->value = newEntry; | 227 cacheValue->value = newEntry; |
219 } | 228 } |
220 | 229 |
221 return style; | 230 return style; |
222 } | 231 } |
223 | 232 |
224 } // namespace blink | 233 } // namespace blink |
OLD | NEW |