Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp

Issue 1829403002: Clean up font loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Resource_status
Patch Set: Another rebase! Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/FontLoader.h" 9 #include "core/css/CSSFontSelector.h"
10 #include "core/dom/Document.h"
11 #include "core/inspector/ConsoleMessage.h"
10 #include "core/page/NetworkStateNotifier.h" 12 #include "core/page/NetworkStateNotifier.h"
11 #include "platform/Histogram.h" 13 #include "platform/Histogram.h"
12 #include "platform/RuntimeEnabledFeatures.h" 14 #include "platform/RuntimeEnabledFeatures.h"
13 #include "platform/fonts/FontCache.h" 15 #include "platform/fonts/FontCache.h"
14 #include "platform/fonts/FontDescription.h" 16 #include "platform/fonts/FontDescription.h"
15 #include "platform/fonts/SimpleFontData.h" 17 #include "platform/fonts/SimpleFontData.h"
16 #include "wtf/CurrentTime.h" 18 #include "wtf/CurrentTime.h"
17 19
18 namespace blink { 20 namespace blink {
19 21
20 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, FontLoader* fontL oader, FontDisplay display) 22 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, CSSFontSelector* fontSelector, FontDisplay display)
21 : m_font(font) 23 : m_font(font)
22 , m_fontLoader(fontLoader) 24 , m_fontSelector(fontSelector)
23 , m_display(display) 25 , m_display(display)
24 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) 26 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod)
25 , m_isInterventionTriggered(false) 27 , m_isInterventionTriggered(false)
26 { 28 {
27 ThreadState::current()->registerPreFinalizer(this); 29 ThreadState::current()->registerPreFinalizer(this);
28 m_font->addClient(this); 30 m_font->addClient(this);
29 31
30 if (RuntimeEnabledFeatures::webFontsInterventionEnabled()) { 32 if (RuntimeEnabledFeatures::webFontsInterventionEnabled()) {
31 // TODO(crbug.com/515343): Consider to use better signals. 33 // TODO(crbug.com/515343): Consider to use better signals.
32 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled() 34 if (RuntimeEnabledFeatures::webFontsInterventionTriggerEnabled()
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 bool RemoteFontFaceSource::isLoaded() const 72 bool RemoteFontFaceSource::isLoaded() const
71 { 73 {
72 return m_font->isLoaded(); 74 return m_font->isLoaded();
73 } 75 }
74 76
75 bool RemoteFontFaceSource::isValid() const 77 bool RemoteFontFaceSource::isValid() const
76 { 78 {
77 return !m_font->errorOccurred(); 79 return !m_font->errorOccurred();
78 } 80 }
79 81
80 void RemoteFontFaceSource::didStartFontLoad(FontResource*)
81 {
82 // We may send duplicated reports when multiple CSSFontFaceSource are
83 // registered at this FontResource. Associating the same URL to different
84 // font-family causes the case, but we treat them as indivisual resources.
85 m_histograms.loadStarted();
86 }
87
88 void RemoteFontFaceSource::fontLoaded(FontResource*) 82 void RemoteFontFaceSource::fontLoaded(FontResource*)
89 { 83 {
90 m_histograms.recordRemoteFont(m_font.get()); 84 m_histograms.recordRemoteFont(m_font.get());
91 m_histograms.fontLoaded(m_isInterventionTriggered); 85 m_histograms.fontLoaded(m_isInterventionTriggered);
92 86
93 m_font->ensureCustomFontData(); 87 m_font->ensureCustomFontData();
94 if (m_font->getStatus() == Resource::DecodeError) 88 // FIXME: Provide more useful message such as OTS rejection reason.
95 m_fontLoader->didFailToDecode(m_font.get()); 89 // See crbug.com/97467
90 if (m_font->getStatus() == Resource::DecodeError && m_fontSelector->document ()) {
91 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create(Oth erMessageSource, WarningMessageLevel, "Failed to decode downloaded font: " + m_f ont->url().elidedString()));
92 if (m_font->otsParsingMessage().length() > 1)
93 m_fontSelector->document()->addConsoleMessage(ConsoleMessage::create (OtherMessageSource, WarningMessageLevel, "OTS parsing error: " + m_font->otsPar singMessage()));
94 }
96 95
97 pruneTable(); 96 pruneTable();
98 if (m_face) { 97 if (m_face) {
99 m_fontLoader->fontFaceInvalidated(); 98 m_fontSelector->fontFaceInvalidated();
100 m_face->fontLoaded(this); 99 m_face->fontLoaded(this);
101 } 100 }
102 // Should not do anything after this line since the m_face->fontLoaded() 101 // Should not do anything after this line since the m_face->fontLoaded()
103 // above may trigger deleting this object. 102 // above may trigger deleting this object.
104 } 103 }
105 104
106 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) 105 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*)
107 { 106 {
108 if (m_display == FontDisplayFallback) 107 if (m_display == FontDisplayFallback)
109 switchToSwapPeriod(); 108 switchToSwapPeriod();
(...skipping 11 matching lines...) Expand all
121 m_histograms.longLimitExceeded(m_isInterventionTriggered); 120 m_histograms.longLimitExceeded(m_isInterventionTriggered);
122 } 121 }
123 122
124 void RemoteFontFaceSource::switchToSwapPeriod() 123 void RemoteFontFaceSource::switchToSwapPeriod()
125 { 124 {
126 ASSERT(m_period == BlockPeriod); 125 ASSERT(m_period == BlockPeriod);
127 m_period = SwapPeriod; 126 m_period = SwapPeriod;
128 127
129 pruneTable(); 128 pruneTable();
130 if (m_face) { 129 if (m_face) {
131 m_fontLoader->fontFaceInvalidated(); 130 m_fontSelector->fontFaceInvalidated();
132 m_face->didBecomeVisibleFallback(this); 131 m_face->didBecomeVisibleFallback(this);
133 } 132 }
134 133
135 m_histograms.recordFallbackTime(m_font.get()); 134 m_histograms.recordFallbackTime(m_font.get());
136 } 135 }
137 136
138 void RemoteFontFaceSource::switchToFailurePeriod() 137 void RemoteFontFaceSource::switchToFailurePeriod()
139 { 138 {
140 if (m_period == BlockPeriod) 139 if (m_period == BlockPeriod)
141 switchToSwapPeriod(); 140 switchToSwapPeriod();
(...skipping 25 matching lines...) Expand all
167 if (!temporaryFont) { 166 if (!temporaryFont) {
168 ASSERT_NOT_REACHED(); 167 ASSERT_NOT_REACHED();
169 return nullptr; 168 return nullptr;
170 } 169 }
171 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback); 170 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback);
172 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); 171 return SimpleFontData::create(temporaryFont->platformData(), cssFontData);
173 } 172 }
174 173
175 void RemoteFontFaceSource::beginLoadIfNeeded() 174 void RemoteFontFaceSource::beginLoadIfNeeded()
176 { 175 {
177 if (m_font->stillNeedsLoad()) 176 if (m_fontSelector->document() && m_font->stillNeedsLoad()) {
178 m_fontLoader->addFontToBeginLoading(m_font.get()); 177 m_font->load(m_fontSelector->document()->fetcher());
178 m_histograms.loadStarted();
179 }
180 m_font->startLoadLimitTimersIfNeeded();
179 181
180 if (m_face) 182 if (m_face)
181 m_face->didBeginLoad(); 183 m_face->didBeginLoad();
182 } 184 }
183 185
184 DEFINE_TRACE(RemoteFontFaceSource) 186 DEFINE_TRACE(RemoteFontFaceSource)
185 { 187 {
186 visitor->trace(m_font); 188 visitor->trace(m_font);
187 visitor->trace(m_fontLoader); 189 visitor->trace(m_fontSelector);
188 CSSFontFaceSource::trace(visitor); 190 CSSFontFaceSource::trace(visitor);
189 } 191 }
190 192
191 void RemoteFontFaceSource::FontLoadHistograms::loadStarted() 193 void RemoteFontFaceSource::FontLoadHistograms::loadStarted()
192 { 194 {
193 if (!m_loadStartTime) 195 if (!m_loadStartTime)
194 m_loadStartTime = currentTimeMS(); 196 m_loadStartTime = currentTimeMS();
195 } 197 }
196 198
197 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period) 199 void RemoteFontFaceSource::FontLoadHistograms::fallbackFontPainted(DisplayPeriod period)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 interventionResult |= 1 << 0; 288 interventionResult |= 1 << 0;
287 if (triggered) 289 if (triggered)
288 interventionResult |= 1 << 1; 290 interventionResult |= 1 << 1;
289 const int boundary = 1 << 2; 291 const int boundary = 1 << 2;
290 292
291 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary)); 293 DEFINE_STATIC_LOCAL(EnumerationHistogram, interventionHistogram, ("WebFont.I nterventionResult", boundary));
292 interventionHistogram.count(interventionResult); 294 interventionHistogram.count(interventionResult);
293 } 295 }
294 296
295 } // namespace blink 297 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698