OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "core/loader/resource/FontResource.h" | 27 #include "core/loader/resource/FontResource.h" |
28 | 28 |
29 #include "core/fetch/FetchRequest.h" | 29 #include "core/fetch/FetchRequest.h" |
30 #include "core/fetch/ResourceClientWalker.h" | 30 #include "core/fetch/ResourceClientWalker.h" |
31 #include "core/fetch/ResourceFetcher.h" | 31 #include "core/fetch/ResourceFetcher.h" |
32 #include "core/fetch/ResourceLoader.h" | |
32 #include "platform/Histogram.h" | 33 #include "platform/Histogram.h" |
33 #include "platform/SharedBuffer.h" | 34 #include "platform/SharedBuffer.h" |
34 #include "platform/fonts/FontCustomPlatformData.h" | 35 #include "platform/fonts/FontCustomPlatformData.h" |
35 #include "platform/fonts/FontPlatformData.h" | 36 #include "platform/fonts/FontPlatformData.h" |
36 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
37 | 38 |
38 namespace blink { | 39 namespace blink { |
39 | 40 |
40 // Durations of font-display periods. | 41 // Durations of font-display periods. |
41 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc | 42 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc |
43 // TODO(toyoshim): Revisit short limit value once cache-aware font display is | |
44 // launched. crbug.com/570205 | |
42 static const double fontLoadWaitShortLimitSec = 0.1; | 45 static const double fontLoadWaitShortLimitSec = 0.1; |
43 static const double fontLoadWaitLongLimitSec = 3.0; | 46 static const double fontLoadWaitLongLimitSec = 3.0; |
44 | 47 |
45 enum FontPackageFormat { | 48 enum FontPackageFormat { |
46 PackageFormatUnknown, | 49 PackageFormatUnknown, |
47 PackageFormatSFNT, | 50 PackageFormatSFNT, |
48 PackageFormatWOFF, | 51 PackageFormatWOFF, |
49 PackageFormatWOFF2, | 52 PackageFormatWOFF2, |
50 PackageFormatSVG, | 53 PackageFormatSVG, |
51 PackageFormatEnumMax | 54 PackageFormatEnumMax |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 m_fontLoadShortLimitTimer(this, | 91 m_fontLoadShortLimitTimer(this, |
89 &FontResource::fontLoadShortLimitCallback), | 92 &FontResource::fontLoadShortLimitCallback), |
90 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) { | 93 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) { |
91 } | 94 } |
92 | 95 |
93 FontResource::~FontResource() {} | 96 FontResource::~FontResource() {} |
94 | 97 |
95 void FontResource::didAddClient(ResourceClient* c) { | 98 void FontResource::didAddClient(ResourceClient* c) { |
96 DCHECK(FontResourceClient::isExpectedType(c)); | 99 DCHECK(FontResourceClient::isExpectedType(c)); |
97 Resource::didAddClient(c); | 100 Resource::didAddClient(c); |
101 | |
102 // Block client callbacks if currently loading from cache. | |
103 if (isLoading() && loader()->isCacheAwareLoadingActivated()) | |
104 return; | |
105 | |
106 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); | |
98 if (m_loadLimitState == ShortLimitExceeded || | 107 if (m_loadLimitState == ShortLimitExceeded || |
99 m_loadLimitState == LongLimitExceeded) | 108 m_loadLimitState == LongLimitExceeded) |
100 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 109 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
101 if (m_loadLimitState == LongLimitExceeded) | 110 if (m_loadLimitState == LongLimitExceeded) |
102 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 111 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
103 } | 112 } |
104 | 113 |
105 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { | 114 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { |
106 // Reload will use the same object, and needs to reset |m_loadLimitState| | 115 // Reload will use the same object, and needs to reset |m_loadLimitState| |
107 // before any didAddClient() is called again. | 116 // before any didAddClient() is called again. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 152 |
144 FontPlatformData FontResource::platformDataFromCustomData( | 153 FontPlatformData FontResource::platformDataFromCustomData( |
145 float size, | 154 float size, |
146 bool bold, | 155 bool bold, |
147 bool italic, | 156 bool italic, |
148 FontOrientation orientation) { | 157 FontOrientation orientation) { |
149 DCHECK(m_fontData); | 158 DCHECK(m_fontData); |
150 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 159 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
151 } | 160 } |
152 | 161 |
162 void FontResource::willReloadAfterDiskCacheMiss() { | |
163 DCHECK(isLoading()); | |
164 DCHECK(loader()->isCacheAwareLoadingActivated()); | |
165 if (m_loadLimitState == ShortLimitExceeded || | |
166 m_loadLimitState == LongLimitExceeded) { | |
167 notifyClientsShortLimitExceeded(); | |
168 } | |
169 if (m_loadLimitState == LongLimitExceeded) | |
170 notifyClientsLongLimitExceeded(); | |
171 | |
172 DEFINE_STATIC_LOCAL( | |
173 EnumerationHistogram, loadLimitHistogram, | |
174 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax)); | |
175 loadLimitHistogram.count(m_loadLimitState); | |
176 } | |
177 | |
153 void FontResource::fontLoadShortLimitCallback(TimerBase*) { | 178 void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
154 // TODO(toyoshim): Change CHECK() to DCHECK() and remove if(!isLoading()) if | 179 // TODO(toyoshim): Change CHECK() to DCHECK() and remove if(!isLoading()) if |
155 // this can survive on Canary for some days. http://crbug.com/670638 | 180 // this can survive on Canary for some days. http://crbug.com/670638 |
156 CHECK(isLoading()); | 181 CHECK(isLoading()); |
157 if (!isLoading()) | 182 if (!isLoading()) |
158 return; | 183 return; |
159 DCHECK_EQ(m_loadLimitState, UnderLimit); | 184 DCHECK_EQ(m_loadLimitState, UnderLimit); |
160 m_loadLimitState = ShortLimitExceeded; | 185 m_loadLimitState = ShortLimitExceeded; |
186 | |
187 // Block client callbacks if currently loading from cache. | |
188 if (loader()->isCacheAwareLoadingActivated()) | |
189 return; | |
190 notifyClientsShortLimitExceeded(); | |
191 } | |
192 | |
193 void FontResource::fontLoadLongLimitCallback(TimerBase*) { | |
194 DCHECK(isLoading()); | |
Shao-Chuan Lee
2016/12/09 06:33:52
Should we make this consistent with fontLoadShortL
Takashi Toyoshima
2016/12/09 10:28:20
Sorry for mixing new and old code in this CL.
Yea
| |
195 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); | |
196 m_loadLimitState = LongLimitExceeded; | |
197 | |
198 // Block client callbacks if currently loading from cache. | |
199 if (loader()->isCacheAwareLoadingActivated()) | |
200 return; | |
201 notifyClientsLongLimitExceeded(); | |
202 } | |
203 | |
204 void FontResource::notifyClientsShortLimitExceeded() { | |
205 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); | |
161 ResourceClientWalker<FontResourceClient> walker(clients()); | 206 ResourceClientWalker<FontResourceClient> walker(clients()); |
162 while (FontResourceClient* client = walker.next()) | 207 while (FontResourceClient* client = walker.next()) |
163 client->fontLoadShortLimitExceeded(this); | 208 client->fontLoadShortLimitExceeded(this); |
164 } | 209 } |
165 | 210 |
166 void FontResource::fontLoadLongLimitCallback(TimerBase*) { | 211 void FontResource::notifyClientsLongLimitExceeded() { |
167 // TODO(toyoshim): Change CHECK() to DCHECK() and remove if(!isLoading()) if | 212 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
168 // this can survive on Canary for some days. http://crbug.com/670638 | |
169 CHECK(isLoading()); | |
170 if (!isLoading()) | |
171 return; | |
172 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); | |
173 m_loadLimitState = LongLimitExceeded; | |
174 ResourceClientWalker<FontResourceClient> walker(clients()); | 213 ResourceClientWalker<FontResourceClient> walker(clients()); |
175 while (FontResourceClient* client = walker.next()) | 214 while (FontResourceClient* client = walker.next()) |
176 client->fontLoadLongLimitExceeded(this); | 215 client->fontLoadLongLimitExceeded(this); |
177 } | 216 } |
178 | 217 |
179 void FontResource::allClientsAndObserversRemoved() { | 218 void FontResource::allClientsAndObserversRemoved() { |
180 m_fontData.reset(); | 219 m_fontData.reset(); |
181 Resource::allClientsAndObserversRemoved(); | 220 Resource::allClientsAndObserversRemoved(); |
182 } | 221 } |
183 | 222 |
(...skipping 21 matching lines...) Expand all Loading... | |
205 Resource::onMemoryDump(level, memoryDump); | 244 Resource::onMemoryDump(level, memoryDump); |
206 if (!m_fontData) | 245 if (!m_fontData) |
207 return; | 246 return; |
208 const String name = getMemoryDumpName() + "/decoded_webfont"; | 247 const String name = getMemoryDumpName() + "/decoded_webfont"; |
209 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(name); | 248 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(name); |
210 dump->addScalar("size", "bytes", m_fontData->dataSize()); | 249 dump->addScalar("size", "bytes", m_fontData->dataSize()); |
211 memoryDump->addSuballocation(dump->guid(), "malloc"); | 250 memoryDump->addSuballocation(dump->guid(), "malloc"); |
212 } | 251 } |
213 | 252 |
214 } // namespace blink | 253 } // namespace blink |
OLD | NEW |