| OLD | NEW |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool RemoteFontFaceSource::isValid() const { | 106 bool RemoteFontFaceSource::isValid() const { |
| 107 return !m_font->errorOccurred(); | 107 return !m_font->errorOccurred(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RemoteFontFaceSource::notifyFinished(Resource*) { | 110 void RemoteFontFaceSource::notifyFinished(Resource*) { |
| 111 m_histograms.maySetDataSource(m_font->response().wasCached() | 111 m_histograms.maySetDataSource(m_font->response().wasCached() |
| 112 ? FontLoadHistograms::FromDiskCache | 112 ? FontLoadHistograms::FromDiskCache |
| 113 : FontLoadHistograms::FromNetwork); | 113 : FontLoadHistograms::FromNetwork); |
| 114 m_histograms.recordRemoteFont(m_font.get()); | 114 m_histograms.recordRemoteFont(m_font.get(), m_isInterventionTriggered); |
| 115 m_histograms.fontLoaded(m_isInterventionTriggered); | 115 m_histograms.fontLoaded(m_isInterventionTriggered); |
| 116 | 116 |
| 117 m_font->ensureCustomFontData(); | 117 m_font->ensureCustomFontData(); |
| 118 // FIXME: Provide more useful message such as OTS rejection reason. | 118 // FIXME: Provide more useful message such as OTS rejection reason. |
| 119 // See crbug.com/97467 | 119 // See crbug.com/97467 |
| 120 if (m_font->getStatus() == Resource::DecodeError && | 120 if (m_font->getStatus() == Resource::DecodeError && |
| 121 m_fontSelector->document()) { | 121 m_fontSelector->document()) { |
| 122 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 122 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |
| 123 OtherMessageSource, WarningMessageLevel, | 123 OtherMessageSource, WarningMessageLevel, |
| 124 "Failed to decode downloaded font: " + m_font->url().elidedString())); | 124 "Failed to decode downloaded font: " + m_font->url().elidedString())); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (m_blankPaintTime <= 0) | 276 if (m_blankPaintTime <= 0) |
| 277 return; | 277 return; |
| 278 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); | 278 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); |
| 279 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, | 279 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, |
| 280 ("WebFont.BlankTextShownTime", 0, 10000, 50)); | 280 ("WebFont.BlankTextShownTime", 0, 10000, 50)); |
| 281 blankTextShownTimeHistogram.count(duration); | 281 blankTextShownTimeHistogram.count(duration); |
| 282 m_blankPaintTime = -1; | 282 m_blankPaintTime = -1; |
| 283 } | 283 } |
| 284 | 284 |
| 285 void RemoteFontFaceSource::FontLoadHistograms::recordRemoteFont( | 285 void RemoteFontFaceSource::FontLoadHistograms::recordRemoteFont( |
| 286 const FontResource* font) { | 286 const FontResource* font, |
| 287 bool isInterventionTriggered) { |
| 287 DEFINE_STATIC_LOCAL(EnumerationHistogram, cacheHitHistogram, | 288 DEFINE_STATIC_LOCAL(EnumerationHistogram, cacheHitHistogram, |
| 288 ("WebFont.CacheHit", CacheHitEnumMax)); | 289 ("WebFont.CacheHit", CacheHitEnumMax)); |
| 289 cacheHitHistogram.count(dataSourceMetricsValue()); | 290 cacheHitHistogram.count(dataSourceMetricsValue()); |
| 290 | 291 |
| 291 if (m_dataSource == FromDiskCache || m_dataSource == FromNetwork) { | 292 if (m_dataSource == FromDiskCache || m_dataSource == FromNetwork) { |
| 292 DCHECK_NE(m_loadStartTime, 0); | 293 DCHECK_NE(m_loadStartTime, 0); |
| 293 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); | 294 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); |
| 294 recordLoadTimeHistogram(font, duration); | 295 recordLoadTimeHistogram(font, duration, isInterventionTriggered); |
| 295 | 296 |
| 296 enum { CORSFail, CORSSuccess, CORSEnumMax }; | 297 enum { CORSFail, CORSSuccess, CORSEnumMax }; |
| 297 int corsValue = font->isCORSFailed() ? CORSFail : CORSSuccess; | 298 int corsValue = font->isCORSFailed() ? CORSFail : CORSSuccess; |
| 298 DEFINE_STATIC_LOCAL(EnumerationHistogram, corsHistogram, | 299 DEFINE_STATIC_LOCAL(EnumerationHistogram, corsHistogram, |
| 299 ("WebFont.CORSSuccess", CORSEnumMax)); | 300 ("WebFont.CORSSuccess", CORSEnumMax)); |
| 300 corsHistogram.count(corsValue); | 301 corsHistogram.count(corsValue); |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 | 304 |
| 304 void RemoteFontFaceSource::FontLoadHistograms::maySetDataSource( | 305 void RemoteFontFaceSource::FontLoadHistograms::maySetDataSource( |
| 305 DataSource dataSource) { | 306 DataSource dataSource) { |
| 306 if (m_dataSource != FromUnknown) | 307 if (m_dataSource != FromUnknown) |
| 307 return; | 308 return; |
| 308 // Classify as memory cache hit if |m_loadStartTime| is not set, i.e. | 309 // Classify as memory cache hit if |m_loadStartTime| is not set, i.e. |
| 309 // this RemoteFontFaceSource instance didn't trigger FontResource | 310 // this RemoteFontFaceSource instance didn't trigger FontResource |
| 310 // loading. | 311 // loading. |
| 311 if (m_loadStartTime == 0) | 312 if (m_loadStartTime == 0) |
| 312 m_dataSource = FromMemoryCache; | 313 m_dataSource = FromMemoryCache; |
| 313 else | 314 else |
| 314 m_dataSource = dataSource; | 315 m_dataSource = dataSource; |
| 315 } | 316 } |
| 316 | 317 |
| 317 void RemoteFontFaceSource::FontLoadHistograms::recordLoadTimeHistogram( | 318 void RemoteFontFaceSource::FontLoadHistograms::recordLoadTimeHistogram( |
| 318 const FontResource* font, | 319 const FontResource* font, |
| 319 int duration) { | 320 int duration, |
| 321 bool isInterventionTriggered) { |
| 320 CHECK_NE(FromUnknown, m_dataSource); | 322 CHECK_NE(FromUnknown, m_dataSource); |
| 321 | 323 |
| 322 if (font->errorOccurred()) { | 324 if (font->errorOccurred()) { |
| 323 DEFINE_STATIC_LOCAL(CustomCountHistogram, loadErrorHistogram, | 325 DEFINE_STATIC_LOCAL(CustomCountHistogram, loadErrorHistogram, |
| 324 ("WebFont.DownloadTime.LoadError", 0, 10000, 50)); | 326 ("WebFont.DownloadTime.LoadError", 0, 10000, 50)); |
| 325 DEFINE_STATIC_LOCAL( | 327 DEFINE_STATIC_LOCAL( |
| 326 CustomCountHistogram, missedCacheLoadErrorHistogram, | 328 CustomCountHistogram, missedCacheLoadErrorHistogram, |
| 327 ("WebFont.MissedCache.DownloadTime.LoadError", 0, 10000, 50)); | 329 ("WebFont.MissedCache.DownloadTime.LoadError", 0, 10000, 50)); |
| 328 loadErrorHistogram.count(duration); | 330 loadErrorHistogram.count(duration); |
| 329 if (m_dataSource == FromNetwork) | 331 if (m_dataSource == FromNetwork) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 342 if (m_dataSource == FromNetwork) | 344 if (m_dataSource == FromNetwork) |
| 343 missedCacheUnder10kHistogram.count(duration); | 345 missedCacheUnder10kHistogram.count(duration); |
| 344 return; | 346 return; |
| 345 } | 347 } |
| 346 if (size < 50 * 1024) { | 348 if (size < 50 * 1024) { |
| 347 DEFINE_STATIC_LOCAL(CustomCountHistogram, under50kHistogram, | 349 DEFINE_STATIC_LOCAL(CustomCountHistogram, under50kHistogram, |
| 348 ("WebFont.DownloadTime.1.10KBTo50KB", 0, 10000, 50)); | 350 ("WebFont.DownloadTime.1.10KBTo50KB", 0, 10000, 50)); |
| 349 DEFINE_STATIC_LOCAL( | 351 DEFINE_STATIC_LOCAL( |
| 350 CustomCountHistogram, missedCacheUnder50kHistogram, | 352 CustomCountHistogram, missedCacheUnder50kHistogram, |
| 351 ("WebFont.MissedCache.DownloadTime.1.10KBTo50KB", 0, 10000, 50)); | 353 ("WebFont.MissedCache.DownloadTime.1.10KBTo50KB", 0, 10000, 50)); |
| 354 // Breakdowns metrics to understand WebFonts intervention. |
| 355 // Now we only cover this 10KBto50KB range because 70% of requests are |
| 356 // covered in this range, and having metrics for all size cases cost. |
| 357 DEFINE_STATIC_LOCAL(CustomCountHistogram, |
| 358 missedCacheAndInterventionTriggeredUnder50kHistogram, |
| 359 ("WebFont.MissedCacheAndInterventionTriggered." |
| 360 "DownloadTime.1.10KBTo50KB", |
| 361 0, 10000, 50)); |
| 362 DEFINE_STATIC_LOCAL(CustomCountHistogram, |
| 363 missedCacheAndInterventionNotTriggeredUnder50kHistogram, |
| 364 ("WebFont.MissedCacheAndInterventionNotTriggered." |
| 365 "DownloadTime.1.10KBTo50KB", |
| 366 0, 10000, 50)); |
| 352 under50kHistogram.count(duration); | 367 under50kHistogram.count(duration); |
| 353 if (m_dataSource == FromNetwork) | 368 if (m_dataSource == FromNetwork) { |
| 354 missedCacheUnder50kHistogram.count(duration); | 369 missedCacheUnder50kHistogram.count(duration); |
| 370 if (isInterventionTriggered) |
| 371 missedCacheAndInterventionTriggeredUnder50kHistogram.count(duration); |
| 372 else |
| 373 missedCacheAndInterventionNotTriggeredUnder50kHistogram.count(duration); |
| 374 } |
| 355 return; | 375 return; |
| 356 } | 376 } |
| 357 if (size < 100 * 1024) { | 377 if (size < 100 * 1024) { |
| 358 DEFINE_STATIC_LOCAL(CustomCountHistogram, under100kHistogram, | 378 DEFINE_STATIC_LOCAL(CustomCountHistogram, under100kHistogram, |
| 359 ("WebFont.DownloadTime.2.50KBTo100KB", 0, 10000, 50)); | 379 ("WebFont.DownloadTime.2.50KBTo100KB", 0, 10000, 50)); |
| 360 DEFINE_STATIC_LOCAL( | 380 DEFINE_STATIC_LOCAL( |
| 361 CustomCountHistogram, missedCacheUnder100kHistogram, | 381 CustomCountHistogram, missedCacheUnder100kHistogram, |
| 362 ("WebFont.MissedCache.DownloadTime.2.50KBTo100KB", 0, 10000, 50)); | 382 ("WebFont.MissedCache.DownloadTime.2.50KBTo100KB", 0, 10000, 50)); |
| 363 under100kHistogram.count(duration); | 383 under100kHistogram.count(duration); |
| 364 if (m_dataSource == FromNetwork) | 384 if (m_dataSource == FromNetwork) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 return Miss; | 440 return Miss; |
| 421 case FromUnknown: | 441 case FromUnknown: |
| 422 // Fall through. | 442 // Fall through. |
| 423 default: | 443 default: |
| 424 NOTREACHED(); | 444 NOTREACHED(); |
| 425 } | 445 } |
| 426 return Miss; | 446 return Miss; |
| 427 } | 447 } |
| 428 | 448 |
| 429 } // namespace blink | 449 } // namespace blink |
| OLD | NEW |