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/fetch/ResourceLoader.h" | |
| 12 #include "core/inspector/ConsoleMessage.h" | 13 #include "core/inspector/ConsoleMessage.h" |
| 13 #include "core/loader/FrameLoaderClient.h" | 14 #include "core/loader/FrameLoaderClient.h" |
| 14 #include "core/page/NetworkStateNotifier.h" | 15 #include "core/page/NetworkStateNotifier.h" |
| 15 #include "platform/Histogram.h" | 16 #include "platform/Histogram.h" |
| 16 #include "platform/RuntimeEnabledFeatures.h" | 17 #include "platform/RuntimeEnabledFeatures.h" |
| 17 #include "platform/fonts/FontCache.h" | 18 #include "platform/fonts/FontCache.h" |
| 18 #include "platform/fonts/FontDescription.h" | 19 #include "platform/fonts/FontDescription.h" |
| 19 #include "platform/fonts/SimpleFontData.h" | 20 #include "platform/fonts/SimpleFontData.h" |
| 20 #include "public/platform/WebEffectiveConnectionType.h" | 21 #include "public/platform/WebEffectiveConnectionType.h" |
| 21 #include "wtf/CurrentTime.h" | 22 #include "wtf/CurrentTime.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, | 54 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
| 54 CSSFontSelector* fontSelector, | 55 CSSFontSelector* fontSelector, |
| 55 FontDisplay display) | 56 FontDisplay display) |
| 56 : m_font(font), | 57 : m_font(font), |
| 57 m_fontSelector(fontSelector), | 58 m_fontSelector(fontSelector), |
| 58 m_display(display), | 59 m_display(display), |
| 59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), | 60 m_period(BlockPeriod), |
| 60 m_histograms(font->url().protocolIsData() | 61 m_histograms(font->url().protocolIsData() |
| 61 ? FontLoadHistograms::FromDataURL | 62 ? FontLoadHistograms::FromDataURL |
| 62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache | 63 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache |
| 63 : FontLoadHistograms::FromUnknown, | 64 : FontLoadHistograms::FromUnknown, |
| 64 m_display), | 65 m_display), |
| 65 m_isInterventionTriggered(false) { | 66 m_isInterventionTriggered(false) { |
| 66 ThreadState::current()->registerPreFinalizer(this); | 67 ThreadState::current()->registerPreFinalizer(this); |
| 67 m_font->addClient(this); | 68 m_font->addClient(this); |
| 68 | 69 |
| 69 if (shouldTriggerWebFontsIntervention()) { | 70 if (shouldTriggerWebFontsIntervention()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 155 |
| 155 if (m_display == FontDisplayBlock || | 156 if (m_display == FontDisplayBlock || |
| 156 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) | 157 (!m_isInterventionTriggered && m_display == FontDisplayAuto)) |
| 157 switchToSwapPeriod(); | 158 switchToSwapPeriod(); |
| 158 else if (m_display == FontDisplayFallback) | 159 else if (m_display == FontDisplayFallback) |
| 159 switchToFailurePeriod(); | 160 switchToFailurePeriod(); |
| 160 | 161 |
| 161 m_histograms.longLimitExceeded(m_isInterventionTriggered); | 162 m_histograms.longLimitExceeded(m_isInterventionTriggered); |
| 162 } | 163 } |
| 163 | 164 |
| 165 void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) { | |
| 166 DCHECK(m_font->isLoading()); | |
| 167 DCHECK(m_font->loader()->isCacheAwareLoadingActivated()); | |
| 168 if (m_display == FontDisplaySwap) | |
| 169 switchToSwapPeriod(); | |
| 170 } | |
| 171 | |
| 164 void RemoteFontFaceSource::switchToSwapPeriod() { | 172 void RemoteFontFaceSource::switchToSwapPeriod() { |
| 165 ASSERT(m_period == BlockPeriod); | 173 DCHECK_EQ(m_period, BlockPeriod); |
| 166 m_period = SwapPeriod; | 174 m_period = SwapPeriod; |
| 167 | 175 |
| 168 pruneTable(); | 176 pruneTable(); |
| 169 if (m_face) { | 177 if (m_face) { |
| 170 m_fontSelector->fontFaceInvalidated(); | 178 m_fontSelector->fontFaceInvalidated(); |
| 171 m_face->didBecomeVisibleFallback(this); | 179 m_face->didBecomeVisibleFallback(this); |
| 172 } | 180 } |
| 173 | 181 |
| 174 m_histograms.recordFallbackTime(m_font.get()); | 182 m_histograms.recordFallbackTime(m_font.get()); |
| 175 } | 183 } |
| 176 | 184 |
| 177 void RemoteFontFaceSource::switchToFailurePeriod() { | 185 void RemoteFontFaceSource::switchToFailurePeriod() { |
| 178 if (m_period == BlockPeriod) | 186 if (m_period == BlockPeriod) |
| 179 switchToSwapPeriod(); | 187 switchToSwapPeriod(); |
| 180 ASSERT(m_period == SwapPeriod); | 188 DCHECK_EQ(m_period, SwapPeriod); |
| 181 m_period = FailurePeriod; | 189 m_period = FailurePeriod; |
| 182 } | 190 } |
| 183 | 191 |
| 184 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { | 192 bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { |
| 185 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) | 193 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()) |
| 186 return true; | 194 return true; |
| 187 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache || | 195 if (m_histograms.dataSource() == FontLoadHistograms::FromMemoryCache || |
| 188 m_histograms.dataSource() == FontLoadHistograms::FromDataURL) | 196 m_histograms.dataSource() == FontLoadHistograms::FromDataURL) |
| 189 return false; | 197 return false; |
| 190 | 198 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 } | 244 } |
| 237 | 245 |
| 238 void RemoteFontFaceSource::beginLoadIfNeeded() { | 246 void RemoteFontFaceSource::beginLoadIfNeeded() { |
| 239 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { | 247 if (m_fontSelector->document() && m_font->stillNeedsLoad()) { |
| 240 m_fontSelector->document()->fetcher()->startLoad(m_font); | 248 m_fontSelector->document()->fetcher()->startLoad(m_font); |
| 241 if (!m_font->isLoaded()) | 249 if (!m_font->isLoaded()) |
| 242 m_font->startLoadLimitTimers(); | 250 m_font->startLoadLimitTimers(); |
| 243 m_histograms.loadStarted(); | 251 m_histograms.loadStarted(); |
| 244 } | 252 } |
| 245 | 253 |
| 254 if (m_display == FontDisplaySwap && m_font->isLoading() && | |
| 255 !m_font->loader()->isCacheAwareLoadingActivated()) { | |
| 256 // |m_period| might be modified if font load timeout callbacks are called | |
| 257 // during |m_font->addClient()| in constructor. Currently this should not | |
| 258 // happen with |m_display == FontDisplaySwap|. | |
| 259 DCHECK_EQ(m_period, BlockPeriod); | |
| 260 m_period = SwapPeriod; | |
|
Kunihiko Sakamoto
2016/11/02 03:46:36
Does this mean the text is displayed with fallback
Shao-Chuan Lee
2016/11/02 04:22:40
In this case CAL is not activated and disk cache m
Kunihiko Sakamoto
2016/11/02 05:49:16
Got it, but...
I'm afraid that this code implicitl
Shao-Chuan Lee
2016/11/02 06:24:10
The original design of cache-aware loading is to c
Kunihiko Sakamoto
2016/11/02 07:46:42
Let me check if my understanding is correct...
-
| |
| 261 } | |
| 262 | |
| 246 if (m_face) | 263 if (m_face) |
| 247 m_face->didBeginLoad(); | 264 m_face->didBeginLoad(); |
| 248 } | 265 } |
| 249 | 266 |
| 250 DEFINE_TRACE(RemoteFontFaceSource) { | 267 DEFINE_TRACE(RemoteFontFaceSource) { |
| 251 visitor->trace(m_font); | 268 visitor->trace(m_font); |
| 252 visitor->trace(m_fontSelector); | 269 visitor->trace(m_fontSelector); |
| 253 CSSFontFaceSource::trace(visitor); | 270 CSSFontFaceSource::trace(visitor); |
| 254 FontResourceClient::trace(visitor); | 271 FontResourceClient::trace(visitor); |
| 255 } | 272 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 return Miss; | 469 return Miss; |
| 453 case FromUnknown: | 470 case FromUnknown: |
| 454 // Fall through. | 471 // Fall through. |
| 455 default: | 472 default: |
| 456 NOTREACHED(); | 473 NOTREACHED(); |
| 457 } | 474 } |
| 458 return Miss; | 475 return Miss; |
| 459 } | 476 } |
| 460 | 477 |
| 461 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |