Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Side by Side Diff: third_party/WebKit/Source/core/css/CSSValuePool.cpp

Issue 1863793003: Make CSSValuePool thread local to ensure correct parsing in colors on workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase with master Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 27
28 #include "core/css/CSSValueList.h" 28 #include "core/css/CSSValueList.h"
29 #include "core/css/parser/CSSParser.h" 29 #include "core/css/parser/CSSParser.h"
30 #include "core/style/ComputedStyle.h" 30 #include "core/style/ComputedStyle.h"
31 #include "wtf/Threading.h" 31 #include "wtf/Threading.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 CSSValuePool& cssValuePool() 35 CSSValuePool& cssValuePool()
36 { 36 {
37 DCHECK(isMainThread());
37 DEFINE_STATIC_LOCAL(CSSValuePool, pool, (new CSSValuePool)); 38 DEFINE_STATIC_LOCAL(CSSValuePool, pool, (new CSSValuePool));
38 return pool; 39 return pool;
39 } 40 }
40 41
41 CSSValuePool::CSSValuePool() 42 CSSValuePool::CSSValuePool()
42 : m_inheritedValue(CSSInheritedValue::create()) 43 : m_inheritedValue(CSSInheritedValue::create())
43 , m_implicitInitialValue(CSSInitialValue::createImplicit()) 44 , m_implicitInitialValue(CSSInitialValue::createImplicit())
44 , m_explicitInitialValue(CSSInitialValue::createExplicit()) 45 , m_explicitInitialValue(CSSInitialValue::createExplicit())
45 , m_unsetValue(CSSUnsetValue::create()) 46 , m_unsetValue(CSSUnsetValue::create())
46 , m_colorTransparent(CSSColorValue::create(Color::transparent)) 47 , m_colorTransparent(CSSColorValue::create(Color::transparent))
(...skipping 25 matching lines...) Expand all
72 { 73 {
73 // These are the empty and deleted values of the hash table. 74 // These are the empty and deleted values of the hash table.
74 if (rgbValue == Color::transparent) 75 if (rgbValue == Color::transparent)
75 return m_colorTransparent; 76 return m_colorTransparent;
76 if (rgbValue == Color::white) 77 if (rgbValue == Color::white)
77 return m_colorWhite; 78 return m_colorWhite;
78 // Just because it is common. 79 // Just because it is common.
79 if (rgbValue == Color::black) 80 if (rgbValue == Color::black)
80 return m_colorBlack; 81 return m_colorBlack;
81 82
82 if (!isMainThread()) {
83 // TODO (crbug.com/599659): Make CSS color parsing work properly in a
84 // worker thread.
85 // Currently, ColorValueCache is not thread-safe; so we avoid interactin g
86 // with it on a non-main thread.
87 return CSSColorValue::create(rgbValue);
88 }
89
90 // Just wipe out the cache and start rebuilding if it gets too big. 83 // Just wipe out the cache and start rebuilding if it gets too big.
91 const unsigned maximumColorCacheSize = 512; 84 const unsigned maximumColorCacheSize = 512;
92 if (m_colorValueCache.size() > maximumColorCacheSize) 85 if (m_colorValueCache.size() > maximumColorCacheSize)
93 m_colorValueCache.clear(); 86 m_colorValueCache.clear();
94 87
95 RawPtr<CSSColorValue> dummyValue = nullptr; 88 RawPtr<CSSColorValue> dummyValue = nullptr;
96 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e); 89 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e);
97 if (entry.isNewEntry) 90 if (entry.isNewEntry)
98 entry.storedValue->value = CSSColorValue::create(rgbValue); 91 entry.storedValue->value = CSSColorValue::create(rgbValue);
99 92
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 visitor->trace(m_colorWhite); 167 visitor->trace(m_colorWhite);
175 visitor->trace(m_colorBlack); 168 visitor->trace(m_colorBlack);
176 visitor->trace(m_pixelValueCache); 169 visitor->trace(m_pixelValueCache);
177 visitor->trace(m_percentValueCache); 170 visitor->trace(m_percentValueCache);
178 visitor->trace(m_numberValueCache); 171 visitor->trace(m_numberValueCache);
179 visitor->trace(m_fontFaceValueCache); 172 visitor->trace(m_fontFaceValueCache);
180 visitor->trace(m_fontFamilyValueCache); 173 visitor->trace(m_fontFamilyValueCache);
181 } 174 }
182 175
183 } // namespace blink 176 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSValuePool.h ('k') | third_party/WebKit/Source/core/css/parser/CSSParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698