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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, | 53 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
54 CSSFontSelector* fontSelector, | 54 CSSFontSelector* fontSelector, |
55 FontDisplay display) | 55 FontDisplay display) |
56 : m_font(font), | 56 : m_font(font), |
57 m_fontSelector(fontSelector), | 57 m_fontSelector(fontSelector), |
58 m_display(display), | 58 m_display(display), |
59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), | 59 m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), |
60 m_histograms(font->url().protocolIsData() | 60 m_histograms(font->url().protocolIsData() |
61 ? FontLoadHistograms::FromDataURL | 61 ? FontLoadHistograms::FromDataURL |
62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache | 62 : font->isLoaded() ? FontLoadHistograms::FromMemoryCache |
63 : FontLoadHistograms::FromUnknown), | 63 : FontLoadHistograms::FromUnknown, |
64 m_display), | |
64 m_isInterventionTriggered(false) { | 65 m_isInterventionTriggered(false) { |
65 ThreadState::current()->registerPreFinalizer(this); | 66 ThreadState::current()->registerPreFinalizer(this); |
66 m_font->addClient(this); | 67 m_font->addClient(this); |
67 | 68 |
68 if (shouldTriggerWebFontsIntervention()) { | 69 if (shouldTriggerWebFontsIntervention()) { |
69 m_isInterventionTriggered = true; | 70 m_isInterventionTriggered = true; |
70 m_period = SwapPeriod; | 71 m_period = SwapPeriod; |
71 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 72 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |
72 OtherMessageSource, InfoMessageLevel, | 73 OtherMessageSource, InfoMessageLevel, |
73 "Slow network is detected. Fallback font will be used while loading: " + | 74 "Slow network is detected. Fallback font will be used while loading: " + |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 106 |
106 bool RemoteFontFaceSource::isValid() const { | 107 bool RemoteFontFaceSource::isValid() const { |
107 return !m_font->errorOccurred(); | 108 return !m_font->errorOccurred(); |
108 } | 109 } |
109 | 110 |
110 void RemoteFontFaceSource::notifyFinished(Resource*) { | 111 void RemoteFontFaceSource::notifyFinished(Resource*) { |
111 m_histograms.maySetDataSource(m_font->response().wasCached() | 112 m_histograms.maySetDataSource(m_font->response().wasCached() |
112 ? FontLoadHistograms::FromDiskCache | 113 ? FontLoadHistograms::FromDiskCache |
113 : FontLoadHistograms::FromNetwork); | 114 : FontLoadHistograms::FromNetwork); |
114 m_histograms.recordRemoteFont(m_font.get()); | 115 m_histograms.recordRemoteFont(m_font.get()); |
115 m_histograms.fontLoaded(m_isInterventionTriggered); | 116 m_histograms.fontLoaded(m_font->isCORSFailed(), |
117 m_font->getStatus() == Resource::LoadError, | |
kinuko
2016/10/21 17:07:11
nit: if these two are only used in &&'ed bool chec
tbansal1
2016/10/21 17:14:32
I thought about this, but concluded that it might
| |
118 m_isInterventionTriggered); | |
116 | 119 |
117 m_font->ensureCustomFontData(); | 120 m_font->ensureCustomFontData(); |
118 // FIXME: Provide more useful message such as OTS rejection reason. | 121 // FIXME: Provide more useful message such as OTS rejection reason. |
119 // See crbug.com/97467 | 122 // See crbug.com/97467 |
120 if (m_font->getStatus() == Resource::DecodeError && | 123 if (m_font->getStatus() == Resource::DecodeError && |
121 m_fontSelector->document()) { | 124 m_fontSelector->document()) { |
122 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( | 125 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create( |
123 OtherMessageSource, WarningMessageLevel, | 126 OtherMessageSource, WarningMessageLevel, |
124 "Failed to decode downloaded font: " + m_font->url().elidedString())); | 127 "Failed to decode downloaded font: " + m_font->url().elidedString())); |
125 if (m_font->otsParsingMessage().length() > 1) | 128 if (m_font->otsParsingMessage().length() > 1) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 m_loadStartTime = currentTimeMS(); | 259 m_loadStartTime = currentTimeMS(); |
257 } | 260 } |
258 | 261 |
259 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted( | 262 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted( |
260 DisplayPeriod period) { | 263 DisplayPeriod period) { |
261 if (period == BlockPeriod && !m_blankPaintTime) | 264 if (period == BlockPeriod && !m_blankPaintTime) |
262 m_blankPaintTime = currentTimeMS(); | 265 m_blankPaintTime = currentTimeMS(); |
263 } | 266 } |
264 | 267 |
265 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded( | 268 void RemoteFontFaceSource::FontLoadHistograms::fontLoaded( |
269 bool isCorsFailed, | |
270 bool loadError, | |
266 bool isInterventionTriggered) { | 271 bool isInterventionTriggered) { |
267 if (!m_isLongLimitExceeded) | 272 if (!m_isLongLimitExceeded && m_fontDisplay == FontDisplayAuto && |
273 !isCorsFailed && !loadError) { | |
268 recordInterventionResult(isInterventionTriggered); | 274 recordInterventionResult(isInterventionTriggered); |
275 } | |
269 } | 276 } |
270 | 277 |
271 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded( | 278 void RemoteFontFaceSource::FontLoadHistograms::longLimitExceeded( |
272 bool isInterventionTriggered) { | 279 bool isInterventionTriggered) { |
273 m_isLongLimitExceeded = true; | 280 m_isLongLimitExceeded = true; |
274 maySetDataSource(FromNetwork); | 281 maySetDataSource(FromNetwork); |
275 recordInterventionResult(isInterventionTriggered); | 282 if (m_fontDisplay == FontDisplayAuto) |
283 recordInterventionResult(isInterventionTriggered); | |
276 } | 284 } |
277 | 285 |
278 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime( | 286 void RemoteFontFaceSource::FontLoadHistograms::recordFallbackTime( |
279 const FontResource* font) { | 287 const FontResource* font) { |
280 if (m_blankPaintTime <= 0) | 288 if (m_blankPaintTime <= 0) |
281 return; | 289 return; |
282 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); | 290 int duration = static_cast<int>(currentTimeMS() - m_blankPaintTime); |
283 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, | 291 DEFINE_STATIC_LOCAL(CustomCountHistogram, blankTextShownTimeHistogram, |
284 ("WebFont.BlankTextShownTime", 0, 10000, 50)); | 292 ("WebFont.BlankTextShownTime", 0, 10000, 50)); |
285 blankTextShownTimeHistogram.count(duration); | 293 blankTextShownTimeHistogram.count(duration); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return Miss; | 432 return Miss; |
425 case FromUnknown: | 433 case FromUnknown: |
426 // Fall through. | 434 // Fall through. |
427 default: | 435 default: |
428 NOTREACHED(); | 436 NOTREACHED(); |
429 } | 437 } |
430 return Miss; | 438 return Miss; |
431 } | 439 } |
432 | 440 |
433 } // namespace blink | 441 } // namespace blink |
OLD | NEW |