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

Side by Side Diff: third_party/WebKit/Source/core/html/canvas/CanvasFontCache.cpp

Issue 2858963002: Replace ASSERT with DCHECK in core/ (Closed)
Patch Set: WorkerBackingThread Created 3 years, 7 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/html/canvas/CanvasFontCache.h" 5 #include "core/html/canvas/CanvasFontCache.h"
6 6
7 #include "core/css/parser/CSSParser.h" 7 #include "core/css/parser/CSSParser.h"
8 #include "core/css/resolver/StyleResolver.h" 8 #include "core/css/resolver/StyleResolver.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/style/ComputedStyle.h" 10 #include "core/style/ComputedStyle.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 unsigned CanvasFontCache::HardMaxFonts() { 51 unsigned CanvasFontCache::HardMaxFonts() {
52 return document_->hidden() ? CanvasFontCacheHiddenMaxFonts 52 return document_->hidden() ? CanvasFontCacheHiddenMaxFonts
53 : CanvasFontCacheHardMaxFonts; 53 : CanvasFontCacheHardMaxFonts;
54 } 54 }
55 55
56 bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string, 56 bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string,
57 Font& resolved_font) { 57 Font& resolved_font) {
58 HashMap<String, Font>::iterator i = 58 HashMap<String, Font>::iterator i =
59 fonts_resolved_using_default_style_.find(font_string); 59 fonts_resolved_using_default_style_.find(font_string);
60 if (i != fonts_resolved_using_default_style_.end()) { 60 if (i != fonts_resolved_using_default_style_.end()) {
61 ASSERT(font_lru_list_.Contains(font_string)); 61 DCHECK(font_lru_list_.Contains(font_string));
62 font_lru_list_.erase(font_string); 62 font_lru_list_.erase(font_string);
63 font_lru_list_.insert(font_string); 63 font_lru_list_.insert(font_string);
64 resolved_font = i->value; 64 resolved_font = i->value;
65 return true; 65 return true;
66 } 66 }
67 67
68 // Addition to LRU list taken care of inside parseFont 68 // Addition to LRU list taken care of inside parseFont
69 MutableStylePropertySet* parsed_style = ParseFont(font_string); 69 MutableStylePropertySet* parsed_style = ParseFont(font_string);
70 if (!parsed_style) 70 if (!parsed_style)
71 return false; 71 return false;
72 72
73 RefPtr<ComputedStyle> font_style = 73 RefPtr<ComputedStyle> font_style =
74 ComputedStyle::Clone(*default_font_style_.Get()); 74 ComputedStyle::Clone(*default_font_style_.Get());
75 document_->EnsureStyleResolver().ComputeFont(font_style.Get(), *parsed_style); 75 document_->EnsureStyleResolver().ComputeFont(font_style.Get(), *parsed_style);
76 fonts_resolved_using_default_style_.insert(font_string, 76 fonts_resolved_using_default_style_.insert(font_string,
77 font_style->GetFont()); 77 font_style->GetFont());
78 resolved_font = fonts_resolved_using_default_style_.find(font_string)->value; 78 resolved_font = fonts_resolved_using_default_style_.find(font_string)->value;
79 return true; 79 return true;
80 } 80 }
81 81
82 MutableStylePropertySet* CanvasFontCache::ParseFont(const String& font_string) { 82 MutableStylePropertySet* CanvasFontCache::ParseFont(const String& font_string) {
83 MutableStylePropertySet* parsed_style; 83 MutableStylePropertySet* parsed_style;
84 MutableStylePropertyMap::iterator i = fetched_fonts_.find(font_string); 84 MutableStylePropertyMap::iterator i = fetched_fonts_.find(font_string);
85 if (i != fetched_fonts_.end()) { 85 if (i != fetched_fonts_.end()) {
86 ASSERT(font_lru_list_.Contains(font_string)); 86 DCHECK(font_lru_list_.Contains(font_string));
87 parsed_style = i->value; 87 parsed_style = i->value;
88 font_lru_list_.erase(font_string); 88 font_lru_list_.erase(font_string);
89 font_lru_list_.insert(font_string); 89 font_lru_list_.insert(font_string);
90 } else { 90 } else {
91 parsed_style = MutableStylePropertySet::Create(kHTMLStandardMode); 91 parsed_style = MutableStylePropertySet::Create(kHTMLStandardMode);
92 CSSParser::ParseValue(parsed_style, CSSPropertyFont, font_string, true); 92 CSSParser::ParseValue(parsed_style, CSSPropertyFont, font_string, true);
93 if (parsed_style->IsEmpty()) 93 if (parsed_style->IsEmpty())
94 return nullptr; 94 return nullptr;
95 // According to 95 // According to
96 // http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html, 96 // http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html,
(...skipping 14 matching lines...) Expand all
111 fonts_resolved_using_default_style_.erase(font_lru_list_.front()); 111 fonts_resolved_using_default_style_.erase(font_lru_list_.front());
112 font_lru_list_.RemoveFirst(); 112 font_lru_list_.RemoveFirst();
113 } 113 }
114 } 114 }
115 SchedulePruningIfNeeded(); 115 SchedulePruningIfNeeded();
116 116
117 return parsed_style; 117 return parsed_style;
118 } 118 }
119 119
120 void CanvasFontCache::DidProcessTask() { 120 void CanvasFontCache::DidProcessTask() {
121 ASSERT(pruning_scheduled_); 121 DCHECK(pruning_scheduled_);
122 ASSERT(main_cache_purge_preventer_); 122 DCHECK(main_cache_purge_preventer_);
123 while (fetched_fonts_.size() > MaxFonts()) { 123 while (fetched_fonts_.size() > MaxFonts()) {
124 fetched_fonts_.erase(font_lru_list_.front()); 124 fetched_fonts_.erase(font_lru_list_.front());
125 fonts_resolved_using_default_style_.erase(font_lru_list_.front()); 125 fonts_resolved_using_default_style_.erase(font_lru_list_.front());
126 font_lru_list_.RemoveFirst(); 126 font_lru_list_.RemoveFirst();
127 } 127 }
128 main_cache_purge_preventer_.reset(); 128 main_cache_purge_preventer_.reset();
129 Platform::Current()->CurrentThread()->RemoveTaskObserver(this); 129 Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
130 pruning_scheduled_ = false; 130 pruning_scheduled_ = false;
131 } 131 }
132 132
133 void CanvasFontCache::SchedulePruningIfNeeded() { 133 void CanvasFontCache::SchedulePruningIfNeeded() {
134 if (pruning_scheduled_) 134 if (pruning_scheduled_)
135 return; 135 return;
136 ASSERT(!main_cache_purge_preventer_); 136 DCHECK(!main_cache_purge_preventer_);
137 main_cache_purge_preventer_ = WTF::WrapUnique(new FontCachePurgePreventer); 137 main_cache_purge_preventer_ = WTF::WrapUnique(new FontCachePurgePreventer);
138 Platform::Current()->CurrentThread()->AddTaskObserver(this); 138 Platform::Current()->CurrentThread()->AddTaskObserver(this);
139 pruning_scheduled_ = true; 139 pruning_scheduled_ = true;
140 } 140 }
141 141
142 bool CanvasFontCache::IsInCache(const String& font_string) { 142 bool CanvasFontCache::IsInCache(const String& font_string) {
143 return fetched_fonts_.find(font_string) != fetched_fonts_.end(); 143 return fetched_fonts_.find(font_string) != fetched_fonts_.end();
144 } 144 }
145 145
146 void CanvasFontCache::PruneAll() { 146 void CanvasFontCache::PruneAll() {
147 fetched_fonts_.clear(); 147 fetched_fonts_.clear();
148 font_lru_list_.clear(); 148 font_lru_list_.clear();
149 fonts_resolved_using_default_style_.clear(); 149 fonts_resolved_using_default_style_.clear();
150 } 150 }
151 151
152 DEFINE_TRACE(CanvasFontCache) { 152 DEFINE_TRACE(CanvasFontCache) {
153 visitor->Trace(fetched_fonts_); 153 visitor->Trace(fetched_fonts_);
154 visitor->Trace(document_); 154 visitor->Trace(document_);
155 } 155 }
156 156
157 } // namespace blink 157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698