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

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

Issue 2390583002: [WIP] WebFonts cache-aware timeout adaption (Closed)
Patch Set: RemoteFontFaceSource cache-aware behavior, fix Created 4 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/css/RemoteFontFaceSource.h" 5 #include "core/css/RemoteFontFaceSource.h"
6 6
7 #include "core/css/CSSCustomFontData.h" 7 #include "core/css/CSSCustomFontData.h"
8 #include "core/css/CSSFontFace.h" 8 #include "core/css/CSSFontFace.h"
9 #include "core/css/CSSFontSelector.h" 9 #include "core/css/CSSFontSelector.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { 147 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) {
148 if (m_display == FontDisplayBlock || 148 if (m_display == FontDisplayBlock ||
149 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) 149 (!m_isInterventionTriggered && m_display == FontDisplayAuto))
150 switchToSwapPeriod(); 150 switchToSwapPeriod();
151 else if (m_display == FontDisplayFallback) 151 else if (m_display == FontDisplayFallback)
152 switchToFailurePeriod(); 152 switchToFailurePeriod();
153 153
154 m_histograms.longLimitExceeded(m_isInterventionTriggered); 154 m_histograms.longLimitExceeded(m_isInterventionTriggered);
155 } 155 }
156 156
157 void RemoteFontFaceSource::switchToSwapPeriod() { 157 void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) {
158 ASSERT(m_period == BlockPeriod); 158 if (m_period == SwapPeriod || m_period == FailurePeriod)
159 m_period = SwapPeriod; 159 didBecomeVisibleFallback();
Kunihiko Sakamoto 2016/10/11 08:07:38 We should move to next period here, instead of kee
Shao-Chuan Lee 2016/10/11 10:58:48 Done.
160 }
160 161
162 void RemoteFontFaceSource::didBecomeVisibleFallback() {
161 pruneTable(); 163 pruneTable();
162 if (m_face) { 164 if (m_face) {
163 m_fontSelector->fontFaceInvalidated(); 165 m_fontSelector->fontFaceInvalidated();
164 m_face->didBecomeVisibleFallback(this); 166 m_face->didBecomeVisibleFallback(this);
165 } 167 }
168 }
166 169
170 void RemoteFontFaceSource::switchToSwapPeriod() {
171 DCHECK(m_period == BlockPeriod);
172 m_period = SwapPeriod;
173 didBecomeVisibleFallback();
167 m_histograms.recordFallbackTime(m_font.get()); 174 m_histograms.recordFallbackTime(m_font.get());
168 } 175 }
169 176
170 void RemoteFontFaceSource::switchToFailurePeriod() { 177 void RemoteFontFaceSource::switchToFailurePeriod() {
171 if (m_period == BlockPeriod) 178 if (m_period == BlockPeriod)
172 switchToSwapPeriod(); 179 switchToSwapPeriod();
173 ASSERT(m_period == SwapPeriod); 180 DCHECK(m_period == SwapPeriod);
174 m_period = FailurePeriod; 181 m_period = FailurePeriod;
175 } 182 }
176 183
177 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { 184 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() {
178 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) 185 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled())
179 return true; 186 return true;
180 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache || 187 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache ||
181 m_histograms.dataSource() == FontLoadHistograms::FromDataURL) 188 m_histograms.dataSource() == FontLoadHistograms::FromDataURL)
182 return false; 189 return false;
183 190
184 bool isV2Enabled = 191 bool isV2Enabled =
185 RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabled() || 192 RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabled() ||
186 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() || 193 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() ||
187 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); 194 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled();
188 195
189 bool networkIsSlow = 196 bool networkIsSlow =
190 isV2Enabled ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document()) 197 isV2Enabled ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document())
191 : isConnectionTypeSlow(); 198 : isConnectionTypeSlow();
192 199
193 return networkIsSlow && m_display == FontDisplayAuto; 200 return networkIsSlow && m_display == FontDisplayAuto;
194 } 201 }
195 202
203 bool RemoteFontFaceSource::shouldUseInvisibleFallback() const {
204 if (m_period == BlockPeriod)
205 return true;
206 if (m_font->resourceRequest().isCacheAwareLoadingActivated()) {
207 switch (m_display) {
208 case FontDisplaySwap:
209 case FontDisplayFallback:
210 case FontDisplayOptional:
211 return true;
212 case FontDisplayAuto:
213 case FontDisplayBlock:
214 break;
215 case FontDisplayEnumMax:
216 NOTREACHED();
217 }
218 }
219 return false;
220 }
221
196 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( 222 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(
197 const FontDescription& fontDescription) { 223 const FontDescription& fontDescription) {
198 if (!isLoaded()) 224 if (!isLoaded())
199 return createLoadingFallbackFontData(fontDescription); 225 return createLoadingFallbackFontData(fontDescription);
200 226
201 if (!m_font->ensureCustomFontData() || m_period == FailurePeriod) 227 if (!m_font->ensureCustomFontData() || m_period == FailurePeriod)
202 return nullptr; 228 return nullptr;
203 229
204 m_histograms.recordFallbackTime(m_font.get()); 230 m_histograms.recordFallbackTime(m_font.get());
205 231
(...skipping 10 matching lines...) Expand all
216 // This temporary font is not retained and should not be returned. 242 // This temporary font is not retained and should not be returned.
217 FontCachePurgePreventer fontCachePurgePreventer; 243 FontCachePurgePreventer fontCachePurgePreventer;
218 SimpleFontData* temporaryFont = 244 SimpleFontData* temporaryFont =
219 FontCache::fontCache()->getNonRetainedLastResortFallbackFont( 245 FontCache::fontCache()->getNonRetainedLastResortFallbackFont(
220 fontDescription); 246 fontDescription);
221 if (!temporaryFont) { 247 if (!temporaryFont) {
222 ASSERT_NOT_REACHED(); 248 ASSERT_NOT_REACHED();
223 return nullptr; 249 return nullptr;
224 } 250 }
225 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create( 251 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(
226 this, m_period == BlockPeriod ? CSSCustomFontData::InvisibleFallback 252 this, shouldUseInvisibleFallback() ? CSSCustomFontData::InvisibleFallback
227 : CSSCustomFontData::VisibleFallback); 253 : CSSCustomFontData::VisibleFallback);
228 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); 254 return SimpleFontData::create(temporaryFont->platformData(), cssFontData);
229 } 255 }
230 256
231 void RemoteFontFaceSource::beginLoadIfNeeded() { 257 void RemoteFontFaceSource::beginLoadIfNeeded() {
232 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { 258 if (m_fontSelector->document() && m_font->stillNeedsLoad()) {
233 m_fontSelector->document()->fetcher()->startLoad(m_font); 259 m_fontSelector->document()->fetcher()->startLoad(m_font);
234 m_histograms.loadStarted(); 260 m_histograms.loadStarted();
235 } 261 }
236 m_font->startLoadLimitTimersIfNeeded(); 262 m_font->startLoadLimitTimersIfNeeded();
237 263
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return Miss; 445 return Miss;
420 case FromUnknown: 446 case FromUnknown:
421 // Fall through. 447 // Fall through.
422 default: 448 default:
423 NOTREACHED(); 449 NOTREACHED();
424 } 450 }
425 return Miss; 451 return Miss;
426 } 452 }
427 453
428 } // namespace blink 454 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RemoteFontFaceSource.h ('k') | third_party/WebKit/Source/core/fetch/FetchRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698