| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 DCHECK_NE(WebEffectiveConnectionType::TypeUnknown, thresholdType); | 43 DCHECK_NE(WebEffectiveConnectionType::TypeUnknown, thresholdType); |
| 44 | 44 |
| 45 return WebEffectiveConnectionType::TypeOffline <= type && | 45 return WebEffectiveConnectionType::TypeOffline <= type && |
| 46 type <= thresholdType; | 46 type <= thresholdType; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool isConnectionTypeSlow() { | 49 bool isConnectionTypeSlow() { |
| 50 return networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; | 50 return networkStateNotifier().connectionType() == WebConnectionTypeCellular2G; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool isInterventionV2Enabled() { |
| 54 return RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabled() || |
| 55 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() || |
| 56 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); |
| 57 } |
| 58 |
| 53 } // namespace | 59 } // namespace |
| 54 | 60 |
| 55 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, | 61 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
| 56 CSSFontSelector* fontSelector, | 62 CSSFontSelector* fontSelector, |
| 57 FontDisplay display) | 63 FontDisplay display) |
| 58 : m_font(font), | 64 : m_font(font), |
| 59 m_fontSelector(fontSelector), | 65 m_fontSelector(fontSelector), |
| 60 m_display(display), | 66 m_display(display), |
| 61 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), | 67 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), |
| 62 m_histograms(font->url().protocolIsData() | 68 m_histograms(font->url().protocolIsData() |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 m_period = FailurePeriod; | 196 m_period = FailurePeriod; |
| 191 } | 197 } |
| 192 | 198 |
| 193 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { | 199 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { |
| 194 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) | 200 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) |
| 195 return true; | 201 return true; |
| 196 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache || | 202 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache || |
| 197 m_histograms.dataSource() == FontLoadHistograms::FromDataURL) | 203 m_histograms.dataSource() == FontLoadHistograms::FromDataURL) |
| 198 return false; | 204 return false; |
| 199 | 205 |
| 200 bool isV2Enabled = | |
| 201 RuntimeEnabledFeatures::webFontsInterventionV2With2GEnabled() || | |
| 202 RuntimeEnabledFeatures::webFontsInterventionV2With3GEnabled() || | |
| 203 RuntimeEnabledFeatures::webFontsInterventionV2WithSlow2GEnabled(); | |
| 204 | |
| 205 bool networkIsSlow = | 206 bool networkIsSlow = |
| 206 isV2Enabled ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document()) | 207 isInterventionV2Enabled() |
| 207 : isConnectionTypeSlow(); | 208 ? isEffectiveConnectionTypeSlowFor(m_fontSelector->document()) |
| 209 : isConnectionTypeSlow(); |
| 208 | 210 |
| 209 return networkIsSlow && m_display == FontDisplayAuto; | 211 return networkIsSlow && m_display == FontDisplayAuto; |
| 210 } | 212 } |
| 211 | 213 |
| 212 bool RemoteFontFaceSource::isLowPriorityLoadingAllowedForRemoteFont() const { | 214 bool RemoteFontFaceSource::isLowPriorityLoadingAllowedForRemoteFont() const { |
| 213 return m_isInterventionTriggered; | 215 return m_isInterventionTriggered && isInterventionV2Enabled(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( | 218 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( |
| 217 const FontDescription& fontDescription) { | 219 const FontDescription& fontDescription) { |
| 218 if (m_period == FailurePeriod || !isValid()) | 220 if (m_period == FailurePeriod || !isValid()) |
| 219 return nullptr; | 221 return nullptr; |
| 220 if (!isLoaded()) | 222 if (!isLoaded()) |
| 221 return createLoadingFallbackFontData(fontDescription); | 223 return createLoadingFallbackFontData(fontDescription); |
| 222 DCHECK(m_customFontData); | 224 DCHECK(m_customFontData); |
| 223 | 225 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 return Miss; | 480 return Miss; |
| 479 case FromUnknown: | 481 case FromUnknown: |
| 480 // Fall through. | 482 // Fall through. |
| 481 default: | 483 default: |
| 482 NOTREACHED(); | 484 NOTREACHED(); |
| 483 } | 485 } |
| 484 return Miss; | 486 return Miss; |
| 485 } | 487 } |
| 486 | 488 |
| 487 } // namespace blink | 489 } // namespace blink |
| OLD | NEW |