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" |
| 11 #include "core/fetch/ResourceFetcher.h" | 11 #include "core/fetch/ResourceFetcher.h" |
| 12 #include "core/inspector/ConsoleMessage.h" | 12 #include "core/inspector/ConsoleMessage.h" |
| 13 #include "core/loader/FrameLoaderClient.h" | 13 #include "core/loader/FrameLoaderClient.h" |
| 14 #include "core/page/NetworkStateNotifier.h" | 14 #include "core/page/NetworkStateNotifier.h" |
| 15 #include "platform/Histogram.h" | 15 #include "platform/Histogram.h" |
| 16 #include "platform/RuntimeEnabledFeatures.h" | 16 #include "platform/RuntimeEnabledFeatures.h" |
| 17 #include "platform/fonts/FontCache.h" | 17 #include "platform/fonts/FontCache.h" |
| 18 #include "platform/fonts/FontDescription.h" | 18 #include "platform/fonts/FontDescription.h" |
| 19 #include "platform/fonts/SimpleFontData.h" | 19 #include "platform/fonts/SimpleFontData.h" |
| 20 #include "public/platform/WebEffectiveConnectionType.h" | 20 #include "public/platform/WebEffectiveConnectionType.h" |
| 21 #include "wtf/CurrentTime.h" | 21 #include "wtf/CurrentTime.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 bool isEffectiveConnectionTypeSlowFor(Document* document) | 27 bool isEffectiveConnectionTypeSlowFor(Document* document) |
| 28 { | 28 { |
| 29 WebEffectiveConnectionType type = document->frame()->loader().client()-> getEffectiveConnectionType(); | 29 WebEffectiveConnectionType type = document->frame()->loader().client()->getE ffectiveConnectionType(); |
| 30 | 30 |
| 31 WebEffectiveConnectionType thresholdType = RuntimeEnabledFeatures::webFo ntsInterventionV2With2GEnabled() | 31 WebEffectiveConnectionType thresholdType = RuntimeEnabledFeatures::webFontsI nterventionV2With2GEnabled() |
| 32 ? WebEffectiveConnectionType::Type2G | 32 ? WebEffectiveConnectionType::Type2G |
| 33 : WebEffectiveConnectionType::TypeSlow2G; | 33 : WebEffectiveConnectionType::TypeSlow2G; |
| 34 | 34 |
| 35 return WebEffectiveConnectionType::TypeOffline <= type && type <= thresh oldType; | 35 return WebEffectiveConnectionType::TypeOffline <= type && type <= thresholdT ype; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool isConnectionTypeSlow() | 38 bool isConnectionTypeSlow() |
| 39 { | 39 { |
| 40 return networkStateNotifier().connectionType() == WebConnectionTypeCellu lar2G; | 40 return networkStateNotifier().connectionType() == WebConnectionTypeCellular2 G; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool shouldTriggerWebFontsIntervention(Document* document, FontDisplay displ ay) | 43 bool shouldTriggerWebFontsIntervention(Document* document, FontDisplay display, bool isLoadedFromMemoryCache) |
| 44 { | 44 { |
| 45 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) | 45 if (isLoadedFromMemoryCache) |
| 46 return true; | 46 return false; |
|
Kunihiko Sakamoto
2016/06/27 09:07:45
So, we no longer trigger the intervention for memo
Takashi Toyoshima
2016/06/27 09:39:40
Done.
| |
| 47 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) | |
| 48 return true; | |
| 47 | 49 |
| 48 bool isV2Enabled = RuntimeEnabledFeatures::webFontsInterventionV2With2GE nabled() || RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); | 50 bool isV2Enabled = RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabl ed() || RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); |
| 49 | 51 |
| 50 bool networkIsSlow = isV2Enabled ? isEffectiveConnectionTypeSlowFor(docu ment) : isConnectionTypeSlow(); | 52 bool networkIsSlow = isV2Enabled ? isEffectiveConnectionTypeSlowFor(document ) : isConnectionTypeSlow(); |
| 51 | 53 |
| 52 return networkIsSlow && display == FontDisplayAuto; | 54 return networkIsSlow && display == FontDisplayAuto; |
| 53 } | 55 } |
| 54 | 56 |
| 55 } // namespace | 57 } // namespace |
| 56 | 58 |
| 57 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector* fontSelector, FontDisplay display) | 59 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector* fontSelector, FontDisplay display) |
| 58 : m_font(font) | 60 : m_font(font) |
| 59 , m_fontSelector(fontSelector) | 61 , m_fontSelector(fontSelector) |
| 60 , m_display(display) | 62 , m_display(display) |
| 61 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) | 63 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) |
| 62 , m_isInterventionTriggered(false) | 64 , m_isInterventionTriggered(false) |
| 65 , m_isLoadedFromMemoryCache(font->isLoaded()) | |
| 63 { | 66 { |
| 64 ThreadState::current()->registerPreFinalizer(this); | 67 ThreadState::current()->registerPreFinalizer(this); |
| 65 m_font->addClient(this); | 68 m_font->addClient(this); |
| 66 | 69 |
| 67 if (shouldTriggerWebFontsIntervention(m_fontSelector->document(), display)) { | 70 if (shouldTriggerWebFontsIntervention(m_fontSelector->document(), display, m _isLoadedFromMemoryCache)) { |
| 68 | 71 |
| 69 m_isInterventionTriggered = true; | 72 m_isInterventionTriggered = true; |
| 70 m_period = SwapPeriod; | 73 m_period = SwapPeriod; |
| 71 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, InfoMessageLevel, "Slow network is detected. Fallback font will be used while loading: " + m_font->url().elidedString())); | 74 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, InfoMessageLevel, "Slow network is detected. Fallback font will be used while loading: " + m_font->url().elidedString())); |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 | 77 |
| 75 RemoteFontFaceSource::~RemoteFontFaceSource() | 78 RemoteFontFaceSource::~RemoteFontFaceSource() |
| 76 { | 79 { |
| 77 } | 80 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 107 } | 110 } |
| 108 | 111 |
| 109 bool RemoteFontFaceSource::isValid() const | 112 bool RemoteFontFaceSource::isValid() const |
| 110 { | 113 { |
| 111 return !m_font->errorOccurred(); | 114 return !m_font->errorOccurred(); |
| 112 } | 115 } |
| 113 | 116 |
| 114 void RemoteFontFaceSource::notifyFinished(Resource*) | 117 void RemoteFontFaceSource::notifyFinished(Resource*) |
| 115 { | 118 { |
| 116 m_histograms.recordRemoteFont(m_font.get()); | 119 m_histograms.recordRemoteFont(m_font.get()); |
| 117 m_histograms.fontLoaded(m_isInterventionTriggered); | 120 m_histograms.fontLoaded(m_isInterventionTriggered, m_isLoadedFromMemoryCache || m_font->response().wasCached()); |
|
Takashi Toyoshima
2016/06/27 08:55:10
wasCached() returns disk cache result.
So, if the
| |
| 118 | 121 |
| 119 m_font->ensureCustomFontData(); | 122 m_font->ensureCustomFontData(); |
| 120 // FIXME: Provide more useful message such as OTS rejection reason. | 123 // FIXME: Provide more useful message such as OTS rejection reason. |
| 121 // See crbug.com/97467 | 124 // See crbug.com/97467 |
| 122 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document ()) { | 125 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document ()) { |
| 123 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, WarningMessageLevel, "Failed to decode downloaded font: " + m_f ont->url().elidedString())); | 126 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, WarningMessageLevel, "Failed to decode downloaded font: " + m_f ont->url().elidedString())); |
| 124 if (m_font->otsParsingMessage().length() > 1) | 127 if (m_font->otsParsingMessage().length() > 1) |
| 125 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create (OtherMessageSource, WarningMessageLevel, "OTS parsing error: " + m_font->otsPar singMessage())); | 128 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create (OtherMessageSource, WarningMessageLevel, "OTS parsing error: " + m_font->otsPar singMessage())); |
| 126 } | 129 } |
| 127 | 130 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 if (!m_loadStartTime) | 231 if (!m_loadStartTime) |
| 229 m_loadStartTime = currentTimeMS(); | 232 m_loadStartTime = currentTimeMS(); |
| 230 } | 233 } |
| 231 | 234 |
| 232 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period) | 235 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period) |
| 233 { | 236 { |
| 234 if (period == BlockPeriod && !m_blankPaintTime) | 237 if (period == BlockPeriod && !m_blankPaintTime) |
| 235 m_blankPaintTime = currentTimeMS(); | 238 m_blankPaintTime = currentTimeMS(); |
| 236 } | 239 } |
| 237 | 240 |
| 238 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded(bool isInterventionTri ggered) | 241 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded(bool isInterventionTri ggered, bool isLoadedFromCache) |
| 239 { | 242 { |
| 240 if (!m_isLongLimitExceeded) | 243 if (!m_isLongLimitExceeded) |
| 241 recordInterventionResult(isInterventionTriggered); | 244 recordInterventionResult(isInterventionTriggered, isLoadedFromCache); |
| 242 } | 245 } |
| 243 | 246 |
| 244 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded(bool isInterven tionTriggered) | 247 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded(bool isInterven tionTriggered) |
| 245 { | 248 { |
| 246 m_isLongLimitExceeded = true; | 249 m_isLongLimitExceeded = true; |
| 247 recordInterventionResult(isInterventionTriggered); | 250 recordInterventionResult(isInterventionTriggered, false); |
| 248 } | 251 } |
| 249 | 252 |
| 250 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime(const FontReso urce* font) | 253 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime(const FontReso urce* font) |
| 251 { | 254 { |
| 252 if (m_blankPaintTime <= 0) | 255 if (m_blankPaintTime <= 0) |
| 253 return; | 256 return; |
| 254 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); | 257 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); |
| 255 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, ("Web Font.BlankTextShownTime", 0, 10000, 50)); | 258 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, ("Web Font.BlankTextShownTime", 0, 10000, 50)); |
| 256 blankTextShownTimeHistogram.count(duration); | 259 blankTextShownTimeHistogram.count(duration); |
| 257 m_blankPaintTime = -1; | 260 m_blankPaintTime = -1; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 } | 307 } |
| 305 if (size < 1024 * 1024) { | 308 if (size < 1024 * 1024) { |
| 306 DEFINE_STATIC_LOCAL(CustomCountHistogram, under1mbHistogram, ("WebFont.D ownloadTime.3.100KBTo1MB", 0, 10000, 50)); | 309 DEFINE_STATIC_LOCAL(CustomCountHistogram, under1mbHistogram, ("WebFont.D ownloadTime.3.100KBTo1MB", 0, 10000, 50)); |
| 307 under1mbHistogram.count(duration); | 310 under1mbHistogram.count(duration); |
| 308 return; | 311 return; |
| 309 } | 312 } |
| 310 DEFINE_STATIC_LOCAL(CustomCountHistogram, over1mbHistogram, ("WebFont.Downlo adTime.4.Over1MB", 0, 10000, 50)); | 313 DEFINE_STATIC_LOCAL(CustomCountHistogram, over1mbHistogram, ("WebFont.Downlo adTime.4.Over1MB", 0, 10000, 50)); |
| 311 over1mbHistogram.count(duration); | 314 over1mbHistogram.count(duration); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult(bool tri ggered) | 317 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult(bool tri ggered, bool loadedFromCache) |
| 315 { | 318 { |
| 316 // interventionResult takes 0-3 values. | 319 // interventionResult takes 0-3 values. |
| 317 int interventionResult = 0; | 320 int interventionResult = 0; |
| 318 if (m_isLongLimitExceeded) | 321 if (m_isLongLimitExceeded) |
| 319 interventionResult |= 1 << 0; | 322 interventionResult |= 1 << 0; |
| 320 if (triggered) | 323 if (triggered) |
| 321 interventionResult |= 1 << 1; | 324 interventionResult |= 1 << 1; |
| 322 const int boundary = 1 << 2; | 325 const int boundary = 1 << 2; |
| 323 | 326 |
| 324 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary)); | 327 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary)); |
| 328 DEFINE_STATIC_LOCAL(EnumerationHistogram, missCachedInterventionHistogram, ( "WebFont.MissCachedInterventionResult", boundary)); | |
| 325 interventionHistogram.count(interventionResult); | 329 interventionHistogram.count(interventionResult); |
| 330 if (!loadedFromCache) | |
|
tbansal1
2016/06/27 15:54:13
Will the accuracy histogram be logged if the font
Takashi Toyoshima
2016/06/28 05:42:52
That's good point.
Let me check if we do not trigg
| |
| 331 missCachedInterventionHistogram.count(interventionResult); | |
| 326 } | 332 } |
| 327 | 333 |
| 328 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |