Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()); |
| 115 m_histograms.fontLoaded(m_isInterventionTriggered); | 115 m_histograms.fontLoaded(m_font, m_display, 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())); |
| 125 if (m_font->otsParsingMessage().length() > 1) | 125 if (m_font->otsParsingMessage().length() > 1) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 144 switchToFailurePeriod(); | 144 switchToFailurePeriod(); |
| 145 } | 145 } |
| 146 | 146 |
| 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_font, m_display, m_isInterventionTriggered); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void RemoteFontFaceSource::switchToSwapPeriod() { | 157 void RemoteFontFaceSource::switchToSwapPeriod() { |
| 158 ASSERT(m_period == BlockPeriod); | 158 ASSERT(m_period == BlockPeriod); |
| 159 m_period = SwapPeriod; | 159 m_period = SwapPeriod; |
| 160 | 160 |
| 161 pruneTable(); | 161 pruneTable(); |
| 162 if (m_face) { | 162 if (m_face) { |
| 163 m_fontSelector->fontFaceInvalidated(); | 163 m_fontSelector->fontFaceInvalidated(); |
| 164 m_face->didBecomeVisibleFallback(this); | 164 m_face->didBecomeVisibleFallback(this); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 m_loadStartTime = currentTimeMS(); | 252 m_loadStartTime = currentTimeMS(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted( | 255 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted( |
| 256 DisplayPeriod period) { | 256 DisplayPeriod period) { |
| 257 if (period == BlockPeriod && !m_blankPaintTime) | 257 if (period == BlockPeriod && !m_blankPaintTime) |
| 258 m_blankPaintTime = currentTimeMS(); | 258 m_blankPaintTime = currentTimeMS(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded( | 261 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded( |
| 262 const FontResource* font, | |
| 263 const FontDisplay display, | |
| 262 bool isInterventionTriggered) { | 264 bool isInterventionTriggered) { |
| 263 if (!m_isLongLimitExceeded) | 265 if (!m_isLongLimitExceeded) |
| 264 recordInterventionResult(isInterventionTriggered); | 266 recordInterventionResult(font, display, isInterventionTriggered); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded( | 269 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded( |
| 270 const FontResource* font, | |
| 271 const FontDisplay display, | |
| 268 bool isInterventionTriggered) { | 272 bool isInterventionTriggered) { |
| 269 m_isLongLimitExceeded = true; | 273 m_isLongLimitExceeded = true; |
| 270 maySetDataSource(FromNetwork); | 274 maySetDataSource(FromNetwork); |
| 271 recordInterventionResult(isInterventionTriggered); | 275 recordInterventionResult(font, display, isInterventionTriggered); |
| 272 } | 276 } |
| 273 | 277 |
| 274 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime( | 278 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime( |
| 275 const FontResource* font) { | 279 const FontResource* font) { |
| 276 if (m_blankPaintTime <= 0) | 280 if (m_blankPaintTime <= 0) |
| 277 return; | 281 return; |
| 278 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); | 282 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); |
| 279 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, | 283 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, |
| 280 ("WebFont.BlankTextShownTime", 0, 10000, 50)); | 284 ("WebFont.BlankTextShownTime", 0, 10000, 50)); |
| 281 blankTextShownTimeHistogram.count(duration); | 285 blankTextShownTimeHistogram.count(duration); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 ("WebFont.DownloadTime.4.Over1MB", 0, 10000, 50)); | 384 ("WebFont.DownloadTime.4.Over1MB", 0, 10000, 50)); |
| 381 DEFINE_STATIC_LOCAL( | 385 DEFINE_STATIC_LOCAL( |
| 382 CustomCountHistogram, missedCacheOver1mbHistogram, | 386 CustomCountHistogram, missedCacheOver1mbHistogram, |
| 383 ("WebFont.MissedCache.DownloadTime.4.Over1MB", 0, 10000, 50)); | 387 ("WebFont.MissedCache.DownloadTime.4.Over1MB", 0, 10000, 50)); |
| 384 over1mbHistogram.count(duration); | 388 over1mbHistogram.count(duration); |
| 385 if (m_dataSource == FromNetwork) | 389 if (m_dataSource == FromNetwork) |
| 386 missedCacheOver1mbHistogram.count(duration); | 390 missedCacheOver1mbHistogram.count(duration); |
| 387 } | 391 } |
| 388 | 392 |
| 389 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult( | 393 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult( |
| 394 const FontResource* font, | |
| 395 const FontDisplay display, | |
| 390 bool isTriggered) { | 396 bool isTriggered) { |
| 391 CHECK_NE(FromUnknown, m_dataSource); | 397 CHECK_NE(FromUnknown, m_dataSource); |
| 392 | 398 |
| 393 // interventionResult takes 0-3 values. | 399 // interventionResult takes 0-3 values. |
| 394 int interventionResult = 0; | 400 int interventionResult = 0; |
| 395 if (m_isLongLimitExceeded) | 401 if (m_isLongLimitExceeded) |
| 396 interventionResult |= 1 << 0; | 402 interventionResult |= 1 << 0; |
| 397 if (isTriggered) | 403 if (isTriggered) |
| 398 interventionResult |= 1 << 1; | 404 interventionResult |= 1 << 1; |
| 399 const int boundary = 1 << 2; | 405 const int boundary = 1 << 2; |
| 400 | 406 |
| 401 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, | 407 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, |
| 402 ("WebFont.InterventionResult", boundary)); | 408 ("WebFont.InterventionResult", boundary)); |
| 403 DEFINE_STATIC_LOCAL(EnumerationHistogram, missedCacheInterventionHistogram, | 409 DEFINE_STATIC_LOCAL(EnumerationHistogram, missedCacheInterventionHistogram, |
| 404 ("WebFont.InterventionResult.MissedCache", boundary)); | 410 ("WebFont.InterventionResult.MissedCache", boundary)); |
| 405 interventionHistogram.count(interventionResult); | 411 interventionHistogram.count(interventionResult); |
| 406 if (m_dataSource == FromNetwork) | 412 |
|
Takashi Toyoshima
2016/10/19 06:36:52
As you changed, this method is called from two pla
tbansal1
2016/10/19 08:27:56
I need to check this to make sure, but when this m
Takashi Toyoshima
2016/10/19 10:16:28
That's true for the current implementation. But we
tbansal1
2016/10/20 00:10:58
Agreed. That;s why I am not checking for pending s
| |
| 413 // Do not record the result if the font failed to load since the failure | |
| 414 // could have happened either due to slow connection or unavailability of the | |
| 415 // server. | |
| 416 if (m_dataSource == FromNetwork && !font->isCORSFailed() && | |
| 417 display == FontDisplayAuto && font->getStatus() != Resource::LoadError) { | |
|
Takashi Toyoshima
2016/10/19 06:36:52
I slightly prefer to pass the |display| at m_histo
tbansal1
2016/10/20 00:10:58
Done.
Takashi Toyoshima
2016/10/20 10:12:44
Thanks!
| |
| 407 missedCacheInterventionHistogram.count(interventionResult); | 418 missedCacheInterventionHistogram.count(interventionResult); |
| 419 } | |
| 408 } | 420 } |
| 409 | 421 |
| 410 RemoteFontFaceSource::FontLoadHistograms::CacheHitMetrics | 422 RemoteFontFaceSource::FontLoadHistograms::CacheHitMetrics |
| 411 RemoteFontFaceSource::FontLoadHistograms::dataSourceMetricsValue() { | 423 RemoteFontFaceSource::FontLoadHistograms::dataSourceMetricsValue() { |
| 412 switch (m_dataSource) { | 424 switch (m_dataSource) { |
| 413 case FromDataURL: | 425 case FromDataURL: |
| 414 return DataUrl; | 426 return DataUrl; |
| 415 case FromMemoryCache: | 427 case FromMemoryCache: |
| 416 return MemoryHit; | 428 return MemoryHit; |
| 417 case FromDiskCache: | 429 case FromDiskCache: |
| 418 return DiskHit; | 430 return DiskHit; |
| 419 case FromNetwork: | 431 case FromNetwork: |
| 420 return Miss; | 432 return Miss; |
| 421 case FromUnknown: | 433 case FromUnknown: |
| 422 // Fall through. | 434 // Fall through. |
| 423 default: | 435 default: |
| 424 NOTREACHED(); | 436 NOTREACHED(); |
| 425 } | 437 } |
| 426 return Miss; | 438 return Miss; |
| 427 } | 439 } |
| 428 | 440 |
| 429 } // namespace blink | 441 } // namespace blink |
| OLD | NEW |