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

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

Issue 2431503002: Log web fonts intervention result more accurately (Closed)
Patch Set: Addressed comments 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
« no previous file with comments | « third_party/WebKit/Source/core/css/RemoteFontFaceSource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, 53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font,
54 CSSFontSelector* fontSelector, 54 CSSFontSelector* fontSelector,
55 FontDisplay display) 55 FontDisplay display)
56 : m_font(font), 56 : m_font(font),
57 m_fontSelector(fontSelector), 57 m_fontSelector(fontSelector),
58 m_display(display), 58 m_display(display),
59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), 59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod),
60 m_histograms(font->url().protocolIsData() 60 m_histograms(font->url().protocolIsData()
61 ? FontLoadHistograms::FromDataURL 61 ? FontLoadHistograms::FromDataURL
62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache 62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache
63 : FontLoadHistograms::FromUnknown), 63 : FontLoadHistograms::FromUnknown,
64 m_display),
64 m_isInterventionTriggered(false) { 65 m_isInterventionTriggered(false) {
65 ThreadState::current()->registerPreFinalizer(this); 66 ThreadState::current()->registerPreFinalizer(this);
66 m_font->addClient(this); 67 m_font->addClient(this);
67 68
68 if (shouldTriggerWebFontsIntervention()) { 69 if (shouldTriggerWebFontsIntervention()) {
69 m_isInterventionTriggered = true; 70 m_isInterventionTriggered = true;
70 m_period = SwapPeriod; 71 m_period = SwapPeriod;
71 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( 72 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(
72 OtherMessageSource, InfoMessageLevel, 73 OtherMessageSource, InfoMessageLevel,
73 "Slow network is detected. Fallback font will be used while loading: " + 74 "Slow network is detected. Fallback font will be used while loading: " +
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 bool RemoteFontFaceSource::isValid() const { 107 bool RemoteFontFaceSource::isValid() const {
107 return !m_font->errorOccurred(); 108 return !m_font->errorOccurred();
108 } 109 }
109 110
110 void RemoteFontFaceSource::notifyFinished(Resource*) { 111 void RemoteFontFaceSource::notifyFinished(Resource*) {
111 m_histograms.maySetDataSource(m_font->response().wasCached() 112 m_histograms.maySetDataSource(m_font->response().wasCached()
112 ? FontLoadHistograms::FromDiskCache 113 ? FontLoadHistograms::FromDiskCache
113 : FontLoadHistograms::FromNetwork); 114 : FontLoadHistograms::FromNetwork);
114 m_histograms.recordRemoteFont(m_font.get()); 115 m_histograms.recordRemoteFont(m_font.get());
115 m_histograms.fontLoaded(m_isInterventionTriggered); 116 m_histograms.fontLoaded(m_font->isCORSFailed(),
117 m_font->getStatus() == Resource::LoadError,
118 m_isInterventionTriggered);
116 119
117 m_font->ensureCustomFontData(); 120 m_font->ensureCustomFontData();
118 // FIXME: Provide more useful message such as OTS rejection reason. 121 // FIXME: Provide more useful message such as OTS rejection reason.
119 // See crbug.com/97467 122 // See crbug.com/97467
120 if (m_font->getStatus() == Resource::DecodeError && 123 if (m_font->getStatus() == Resource::DecodeError &&
121 m_fontSelector->document()) { 124 m_fontSelector->document()) {
122 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( 125 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(
123 OtherMessageSource, WarningMessageLevel, 126 OtherMessageSource, WarningMessageLevel,
124 "Failed to decode downloaded font: " + m_font->url().elidedString())); 127 "Failed to decode downloaded font: " + m_font->url().elidedString()));
125 if (m_font->otsParsingMessage().length() > 1) 128 if (m_font->otsParsingMessage().length() > 1)
(...skipping 18 matching lines...) Expand all
144 switchToFailurePeriod(); 147 switchToFailurePeriod();
145 } 148 }
146 149
147 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { 150 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) {
148 if (m_display == FontDisplayBlock || 151 if (m_display == FontDisplayBlock ||
149 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) 152 (!m_isInterventionTriggered && m_display == FontDisplayAuto))
150 switchToSwapPeriod(); 153 switchToSwapPeriod();
151 else if (m_display == FontDisplayFallback) 154 else if (m_display == FontDisplayFallback)
152 switchToFailurePeriod(); 155 switchToFailurePeriod();
153 156
154 m_histograms.longLimitExceeded(m_isInterventionTriggered); 157 m_histograms.longLimitExceeded(m_font->isCORSFailed(),
158 m_font->getStatus() == Resource::LoadError,
159 m_isInterventionTriggered);
155 } 160 }
156 161
157 void RemoteFontFaceSource::switchToSwapPeriod() { 162 void RemoteFontFaceSource::switchToSwapPeriod() {
158 ASSERT(m_period == BlockPeriod); 163 ASSERT(m_period == BlockPeriod);
159 m_period = SwapPeriod; 164 m_period = SwapPeriod;
160 165
161 pruneTable(); 166 pruneTable();
162 if (m_face) { 167 if (m_face) {
163 m_fontSelector->fontFaceInvalidated(); 168 m_fontSelector->fontFaceInvalidated();
164 m_face->didBecomeVisibleFallback(this); 169 m_face->didBecomeVisibleFallback(this);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 m_loadStartTime = currentTimeMS(); 257 m_loadStartTime = currentTimeMS();
253 } 258 }
254 259
255 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted( 260 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(
256 DisplayPeriod period) { 261 DisplayPeriod period) {
257 if (period == BlockPeriod && !m_blankPaintTime) 262 if (period == BlockPeriod && !m_blankPaintTime)
258 m_blankPaintTime = currentTimeMS(); 263 m_blankPaintTime = currentTimeMS();
259 } 264 }
260 265
261 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded( 266 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded(
267 bool isCorsFailed,
Takashi Toyoshima 2016/10/20 10:12:44 Probably we can just have one argument to indicate
tbansal1 2016/10/21 06:58:13 I am still using two different errors. It seems mo
268 bool loadError,
262 bool isInterventionTriggered) { 269 bool isInterventionTriggered) {
263 if (!m_isLongLimitExceeded) 270 if (!m_isLongLimitExceeded) {
Takashi Toyoshima 2016/10/20 10:12:44 Can we check error here? if (!m_isLongLimitExceed
tbansal1 2016/10/21 06:58:13 Done.
264 recordInterventionResult(isInterventionTriggered); 271 recordInterventionResult(isCorsFailed, loadError, isInterventionTriggered);
272 }
265 } 273 }
266 274
267 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded( 275 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded(
276 bool isCorsFailed,
Takashi Toyoshima 2016/10/20 10:12:44 These two arguments look curious to me, because th
tbansal1 2016/10/21 06:58:13 Done.
277 bool loadError,
268 bool isInterventionTriggered) { 278 bool isInterventionTriggered) {
269 m_isLongLimitExceeded = true; 279 m_isLongLimitExceeded = true;
270 maySetDataSource(FromNetwork); 280 maySetDataSource(FromNetwork);
271 recordInterventionResult(isInterventionTriggered); 281 recordInterventionResult(isCorsFailed, loadError, isInterventionTriggered);
272 } 282 }
273 283
274 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime( 284 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime(
275 const FontResource* font) { 285 const FontResource* font) {
276 if (m_blankPaintTime <= 0) 286 if (m_blankPaintTime <= 0)
277 return; 287 return;
278 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); 288 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime);
279 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, 289 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram,
280 ("WebFont.BlankTextShownTime", 0, 10000, 50)); 290 ("WebFont.BlankTextShownTime", 0, 10000, 50));
281 blankTextShownTimeHistogram.count(duration); 291 blankTextShownTimeHistogram.count(duration);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 ("WebFont.DownloadTime.4.Over1MB", 0, 10000, 50)); 390 ("WebFont.DownloadTime.4.Over1MB", 0, 10000, 50));
381 DEFINE_STATIC_LOCAL( 391 DEFINE_STATIC_LOCAL(
382 CustomCountHistogram, missedCacheOver1mbHistogram, 392 CustomCountHistogram, missedCacheOver1mbHistogram,
383 ("WebFont.MissedCache.DownloadTime.4.Over1MB", 0, 10000, 50)); 393 ("WebFont.MissedCache.DownloadTime.4.Over1MB", 0, 10000, 50));
384 over1mbHistogram.count(duration); 394 over1mbHistogram.count(duration);
385 if (m_dataSource == FromNetwork) 395 if (m_dataSource == FromNetwork)
386 missedCacheOver1mbHistogram.count(duration); 396 missedCacheOver1mbHistogram.count(duration);
387 } 397 }
388 398
389 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult( 399 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult(
400 bool isCorsFailed,
401 bool loadError,
390 bool isTriggered) { 402 bool isTriggered) {
391 CHECK_NE(FromUnknown, m_dataSource); 403 CHECK_NE(FromUnknown, m_dataSource);
392 404
393 // interventionResult takes 0-3 values. 405 // interventionResult takes 0-3 values.
394 int interventionResult = 0; 406 int interventionResult = 0;
395 if (m_isLongLimitExceeded) 407 if (m_isLongLimitExceeded)
396 interventionResult |= 1 << 0; 408 interventionResult |= 1 << 0;
397 if (isTriggered) 409 if (isTriggered)
398 interventionResult |= 1 << 1; 410 interventionResult |= 1 << 1;
399 const int boundary = 1 << 2; 411 const int boundary = 1 << 2;
400 412
401 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, 413 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram,
402 ("WebFont.InterventionResult", boundary)); 414 ("WebFont.InterventionResult", boundary));
403 DEFINE_STATIC_LOCAL(EnumerationHistogram, missedCacheInterventionHistogram, 415 DEFINE_STATIC_LOCAL(EnumerationHistogram, missedCacheInterventionHistogram,
404 ("WebFont.InterventionResult.MissedCache", boundary)); 416 ("WebFont.InterventionResult.MissedCache", boundary));
405 interventionHistogram.count(interventionResult); 417 interventionHistogram.count(interventionResult);
406 if (m_dataSource == FromNetwork) 418
Takashi Toyoshima 2016/10/20 10:12:44 Do you have any reason why you omit only missedCac
tbansal1 2016/10/21 06:58:13 Done.
419 // Do not record the result if the font failed to load since the failure
420 // could have happened either due to slow connection or unavailability of the
421 // server.
422 if (m_dataSource == FromNetwork && !isCorsFailed &&
423 m_fontDisplay == FontDisplayAuto && !loadError) {
407 missedCacheInterventionHistogram.count(interventionResult); 424 missedCacheInterventionHistogram.count(interventionResult);
425 }
408 } 426 }
409 427
410 RemoteFontFaceSource::FontLoadHistograms::CacheHitMetrics 428 RemoteFontFaceSource::FontLoadHistograms::CacheHitMetrics
411 RemoteFontFaceSource::FontLoadHistograms::dataSourceMetricsValue() { 429 RemoteFontFaceSource::FontLoadHistograms::dataSourceMetricsValue() {
412 switch (m_dataSource) { 430 switch (m_dataSource) {
413 case FromDataURL: 431 case FromDataURL:
414 return DataUrl; 432 return DataUrl;
415 case FromMemoryCache: 433 case FromMemoryCache:
416 return MemoryHit; 434 return MemoryHit;
417 case FromDiskCache: 435 case FromDiskCache:
418 return DiskHit; 436 return DiskHit;
419 case FromNetwork: 437 case FromNetwork:
420 return Miss; 438 return Miss;
421 case FromUnknown: 439 case FromUnknown:
422 // Fall through. 440 // Fall through.
423 default: 441 default:
424 NOTREACHED(); 442 NOTREACHED();
425 } 443 }
426 return Miss; 444 return Miss;
427 } 445 }
428 446
429 } // namespace blink 447 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/RemoteFontFaceSource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698