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 "config.h" | 5 #include "config.h" |
6 #include "core/css/RemoteFontFaceSource.h" | 6 #include "core/css/RemoteFontFaceSource.h" |
7 | 7 |
8 #include "FetchInitiatorTypeNames.h" | |
9 #include "core/css/CSSCustomFontData.h" | 8 #include "core/css/CSSCustomFontData.h" |
10 #include "core/css/CSSFontFace.h" | 9 #include "core/css/CSSFontFace.h" |
11 #include "core/css/CSSFontSelector.h" | 10 #include "core/css/FontLoader.h" |
12 #include "core/fetch/ResourceFetcher.h" | |
13 #include "platform/fonts/FontCache.h" | 11 #include "platform/fonts/FontCache.h" |
14 #include "platform/fonts/FontDescription.h" | 12 #include "platform/fonts/FontDescription.h" |
15 #include "platform/fonts/SimpleFontData.h" | 13 #include "platform/fonts/SimpleFontData.h" |
16 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
17 #include "wtf/CurrentTime.h" | 15 #include "wtf/CurrentTime.h" |
18 | 16 |
19 namespace WebCore { | 17 namespace WebCore { |
20 | 18 |
21 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, PassRefPtrWillBeR
awPtr<FontLoader> fontLoader) | 19 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, PassRefPtrWillBeR
awPtr<FontLoader> fontLoader) |
22 : m_font(font) | 20 : m_font(font) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 76 |
79 void RemoteFontFaceSource::fontLoadWaitLimitExceeded(FontResource*) | 77 void RemoteFontFaceSource::fontLoadWaitLimitExceeded(FontResource*) |
80 { | 78 { |
81 pruneTable(); | 79 pruneTable(); |
82 if (m_face) | 80 if (m_face) |
83 m_face->fontLoadWaitLimitExceeded(this); | 81 m_face->fontLoadWaitLimitExceeded(this); |
84 | 82 |
85 m_histograms.recordFallbackTime(m_font.get()); | 83 m_histograms.recordFallbackTime(m_font.get()); |
86 } | 84 } |
87 | 85 |
88 void RemoteFontFaceSource::corsFailed(FontResource*) | |
89 { | |
90 if (m_face) { | |
91 m_histograms.corsFailed(); | |
92 Document* document = m_face->fontSelector() ? m_face->fontSelector()->do
cument() : 0; | |
93 if (document) { | |
94 FetchRequest request(ResourceRequest(m_font->url()), FetchInitiatorT
ypeNames::css); | |
95 ResourcePtr<FontResource> newFontResource = document->fetcher()->fet
chFont(request); | |
96 if (newFontResource) { | |
97 m_font->removeClient(this); | |
98 m_font = newFontResource; | |
99 m_font->addClient(this); | |
100 m_fontLoader->addFontToBeginLoading(m_font.get()); | |
101 return; | |
102 } else { | |
103 pruneTable(); | |
104 } | |
105 } | |
106 m_face->fontLoaded(this); | |
107 } | |
108 } | |
109 | |
110 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri
ption& fontDescription) | 86 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri
ption& fontDescription) |
111 { | 87 { |
112 if (!isLoaded()) | 88 if (!isLoaded()) |
113 return createLoadingFallbackFontData(fontDescription); | 89 return createLoadingFallbackFontData(fontDescription); |
114 | 90 |
115 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef
. | 91 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef
. |
116 if (!m_font->ensureCustomFontData()) | 92 if (!m_font->ensureCustomFontData()) |
117 return nullptr; | 93 return nullptr; |
118 | 94 |
119 m_histograms.recordFallbackTime(m_font.get()); | 95 m_histograms.recordFallbackTime(m_font.get()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (m_loadStartTime > 0 && font && !font->isLoading()) { | 159 if (m_loadStartTime > 0 && font && !font->isLoading()) { |
184 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); | 160 int duration = static_cast<int>(currentTimeMS() - m_loadStartTime); |
185 blink::Platform::current()->histogramCustomCounts(histogramName(font), d
uration, 0, 10000, 50); | 161 blink::Platform::current()->histogramCustomCounts(histogramName(font), d
uration, 0, 10000, 50); |
186 m_loadStartTime = -1; | 162 m_loadStartTime = -1; |
187 | 163 |
188 enum { Miss, Hit, DataUrl, CacheHitEnumMax }; | 164 enum { Miss, Hit, DataUrl, CacheHitEnumMax }; |
189 int histogramValue = font->url().protocolIsData() ? DataUrl | 165 int histogramValue = font->url().protocolIsData() ? DataUrl |
190 : font->response().wasCached() ? Hit | 166 : font->response().wasCached() ? Hit |
191 : Miss; | 167 : Miss; |
192 blink::Platform::current()->histogramEnumeration("WebFont.CacheHit", his
togramValue, CacheHitEnumMax); | 168 blink::Platform::current()->histogramEnumeration("WebFont.CacheHit", his
togramValue, CacheHitEnumMax); |
193 | |
194 if (!font->errorOccurred()) { | |
195 enum { CORSFail, CORSSuccess, CORSEnumMax }; | |
196 int corsValue = m_corsFailed ? CORSFail : CORSSuccess; | |
197 blink::Platform::current()->histogramEnumeration("WebFont.CORSSucces
s", corsValue, CORSEnumMax); | |
198 } | |
199 } | 169 } |
200 } | 170 } |
201 | 171 |
202 const char* RemoteFontFaceSource::FontLoadHistograms::histogramName(const FontRe
source* font) | 172 const char* RemoteFontFaceSource::FontLoadHistograms::histogramName(const FontRe
source* font) |
203 { | 173 { |
204 if (font->errorOccurred()) | 174 if (font->errorOccurred()) |
205 return "WebFont.DownloadTime.LoadError"; | 175 return "WebFont.DownloadTime.LoadError"; |
206 | 176 |
207 unsigned size = font->encodedSize(); | 177 unsigned size = font->encodedSize(); |
208 if (size < 10 * 1024) | 178 if (size < 10 * 1024) |
209 return "WebFont.DownloadTime.0.Under10KB"; | 179 return "WebFont.DownloadTime.0.Under10KB"; |
210 if (size < 50 * 1024) | 180 if (size < 50 * 1024) |
211 return "WebFont.DownloadTime.1.10KBTo50KB"; | 181 return "WebFont.DownloadTime.1.10KBTo50KB"; |
212 if (size < 100 * 1024) | 182 if (size < 100 * 1024) |
213 return "WebFont.DownloadTime.2.50KBTo100KB"; | 183 return "WebFont.DownloadTime.2.50KBTo100KB"; |
214 if (size < 1024 * 1024) | 184 if (size < 1024 * 1024) |
215 return "WebFont.DownloadTime.3.100KBTo1MB"; | 185 return "WebFont.DownloadTime.3.100KBTo1MB"; |
216 return "WebFont.DownloadTime.4.Over1MB"; | 186 return "WebFont.DownloadTime.4.Over1MB"; |
217 } | 187 } |
218 | 188 |
219 } // namespace WebCore | 189 } // namespace WebCore |
OLD | NEW |