| 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 22 matching lines...) Expand all Loading... |
| 33 : WebEffectiveConnectionType::TypeSlow2G; | 33 : WebEffectiveConnectionType::TypeSlow2G; |
| 34 | 34 |
| 35 return WebEffectiveConnectionType::TypeOffline <= type && type <= thresholdT
ype; | 35 return WebEffectiveConnectionType::TypeOffline <= type && type <= thresholdT
ype; |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool isConnectionTypeSlow() | 38 bool isConnectionTypeSlow() |
| 39 { | 39 { |
| 40 return networkStateNotifier().connectionType() == WebConnectionTypeCellular2
G; | 40 return networkStateNotifier().connectionType() == WebConnectionTypeCellular2
G; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool shouldTriggerWebFontsIntervention(Document* document, FontDisplay display,
bool isLoadedFromMemoryCache) | 43 bool shouldTriggerWebFontsIntervention(Document* document, FontDisplay display,
bool isLoadedFromMemoryCache, bool isLoadedFromDataURL) |
| 44 { | 44 { |
| 45 if (isLoadedFromMemoryCache) | |
| 46 return false; | |
| 47 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) | 45 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) |
| 48 return true; | 46 return true; |
| 47 if (isLoadedFromMemoryCache || isLoadedFromDataURL) |
| 48 return false; |
| 49 | 49 |
| 50 bool isV2Enabled = RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabl
ed() || RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); | 50 bool isV2Enabled = RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabl
ed() || RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); |
| 51 | 51 |
| 52 bool networkIsSlow = isV2Enabled ? isEffectiveConnectionTypeSlowFor(document
) : isConnectionTypeSlow(); | 52 bool networkIsSlow = isV2Enabled ? isEffectiveConnectionTypeSlowFor(document
) : isConnectionTypeSlow(); |
| 53 | 53 |
| 54 return networkIsSlow && display == FontDisplayAuto; | 54 return networkIsSlow && display == FontDisplayAuto; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector*
fontSelector, FontDisplay display) | 59 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector*
fontSelector, FontDisplay display) |
| 60 : m_font(font) | 60 : m_font(font) |
| 61 , m_fontSelector(fontSelector) | 61 , m_fontSelector(fontSelector) |
| 62 , m_display(display) | 62 , m_display(display) |
| 63 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) | 63 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) |
| 64 , m_isInterventionTriggered(false) | 64 , m_isInterventionTriggered(false) |
| 65 , m_isLoadedFromMemoryCache(font->isLoaded()) | 65 , m_isLoadedFromMemoryCache(font->isLoaded()) |
| 66 { | 66 { |
| 67 ThreadState::current()->registerPreFinalizer(this); | 67 ThreadState::current()->registerPreFinalizer(this); |
| 68 m_font->addClient(this); | 68 m_font->addClient(this); |
| 69 | 69 |
| 70 if (shouldTriggerWebFontsIntervention(m_fontSelector->document(), display, m
_isLoadedFromMemoryCache)) { | 70 if (shouldTriggerWebFontsIntervention(m_fontSelector->document(), display, m
_isLoadedFromMemoryCache, m_font->url().protocolIsData())) { |
| 71 | 71 |
| 72 m_isInterventionTriggered = true; | 72 m_isInterventionTriggered = true; |
| 73 m_period = SwapPeriod; | 73 m_period = SwapPeriod; |
| 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())); | 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())); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 RemoteFontFaceSource::~RemoteFontFaceSource() | 78 RemoteFontFaceSource::~RemoteFontFaceSource() |
| 79 { | 79 { |
| 80 } | 80 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool RemoteFontFaceSource::isValid() const | 112 bool RemoteFontFaceSource::isValid() const |
| 113 { | 113 { |
| 114 return !m_font->errorOccurred(); | 114 return !m_font->errorOccurred(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void RemoteFontFaceSource::notifyFinished(Resource*) | 117 void RemoteFontFaceSource::notifyFinished(Resource*) |
| 118 { | 118 { |
| 119 m_histograms.recordRemoteFont(m_font.get()); | 119 m_histograms.recordRemoteFont(m_font.get()); |
| 120 m_histograms.fontLoaded(m_isInterventionTriggered, m_isLoadedFromMemoryCache
|| m_font->response().wasCached()); | 120 m_histograms.fontLoaded(m_isInterventionTriggered, !m_isLoadedFromMemoryCach
e && !m_font->url().protocolIsData() && !m_font->response().wasCached()); |
| 121 | 121 |
| 122 m_font->ensureCustomFontData(); | 122 m_font->ensureCustomFontData(); |
| 123 // FIXME: Provide more useful message such as OTS rejection reason. | 123 // FIXME: Provide more useful message such as OTS rejection reason. |
| 124 // See crbug.com/97467 | 124 // See crbug.com/97467 |
| 125 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document
()) { | 125 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document
()) { |
| 126 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())); |
| 127 if (m_font->otsParsingMessage().length() > 1) | 127 if (m_font->otsParsingMessage().length() > 1) |
| 128 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())); |
| 129 } | 129 } |
| 130 | 130 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (!m_loadStartTime) | 231 if (!m_loadStartTime) |
| 232 m_loadStartTime = currentTimeMS(); | 232 m_loadStartTime = currentTimeMS(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod
period) | 235 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod
period) |
| 236 { | 236 { |
| 237 if (period == BlockPeriod && !m_blankPaintTime) | 237 if (period == BlockPeriod && !m_blankPaintTime) |
| 238 m_blankPaintTime = currentTimeMS(); | 238 m_blankPaintTime = currentTimeMS(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded(bool isInterventionTri
ggered, bool isLoadedFromCache) | 241 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded(bool isInterventionTri
ggered, bool isLoadedFromNetwork) |
| 242 { | 242 { |
| 243 if (!m_isLongLimitExceeded) | 243 if (!m_isLongLimitExceeded) |
| 244 recordInterventionResult(isInterventionTriggered, isLoadedFromCache); | 244 recordInterventionResult(isInterventionTriggered, isLoadedFromNetwork); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded(bool isInterven
tionTriggered) | 247 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded(bool isInterven
tionTriggered) |
| 248 { | 248 { |
| 249 m_isLongLimitExceeded = true; | 249 m_isLongLimitExceeded = true; |
| 250 recordInterventionResult(isInterventionTriggered, false); | 250 recordInterventionResult(isInterventionTriggered, false); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime(const FontReso
urce* font) | 253 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime(const FontReso
urce* font) |
| 254 { | 254 { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 307 } |
| 308 if (size < 1024 * 1024) { | 308 if (size < 1024 * 1024) { |
| 309 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)); |
| 310 under1mbHistogram.count(duration); | 310 under1mbHistogram.count(duration); |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 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)); |
| 314 over1mbHistogram.count(duration); | 314 over1mbHistogram.count(duration); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult(bool isT
riggered, bool isLoadedFromCache) | 317 void RemoteFontFaceSource::FontLoadHistograms::recordInterventionResult(bool isT
riggered, bool isLoadedFromNetwork) |
| 318 { | 318 { |
| 319 // interventionResult takes 0-3 values. | 319 // interventionResult takes 0-3 values. |
| 320 int interventionResult = 0; | 320 int interventionResult = 0; |
| 321 if (m_isLongLimitExceeded) | 321 if (m_isLongLimitExceeded) |
| 322 interventionResult |= 1 << 0; | 322 interventionResult |= 1 << 0; |
| 323 if (isTriggered) | 323 if (isTriggered) |
| 324 interventionResult |= 1 << 1; | 324 interventionResult |= 1 << 1; |
| 325 const int boundary = 1 << 2; | 325 const int boundary = 1 << 2; |
| 326 | 326 |
| 327 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)); | 328 DEFINE_STATIC_LOCAL(EnumerationHistogram, missCachedInterventionHistogram, (
"WebFont.MissCachedInterventionResult", boundary)); |
| 329 interventionHistogram.count(interventionResult); | 329 interventionHistogram.count(interventionResult); |
| 330 if (!isLoadedFromCache) | 330 if (isLoadedFromNetwork) |
| 331 missCachedInterventionHistogram.count(interventionResult); | 331 missCachedInterventionHistogram.count(interventionResult); |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |