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/fetch/FontResource.h" | 27 #include "core/fetch/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(shaochuan): 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 | |
98 if (m_loadLimitState == ShortLimitExceeded || | 106 if (m_loadLimitState == ShortLimitExceeded || |
99 m_loadLimitState == LongLimitExceeded) | 107 m_loadLimitState == LongLimitExceeded) |
100 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 108 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
101 if (m_loadLimitState == LongLimitExceeded) | 109 if (m_loadLimitState == LongLimitExceeded) |
102 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 110 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
103 } | 111 } |
104 | 112 |
105 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { | 113 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { |
106 // Reload will use the same object, and needs to reset |m_loadLimitState| | 114 // Reload will use the same object, and needs to reset |m_loadLimitState| |
107 // before any didAddClient() is called again. | 115 // before any didAddClient() is called again. |
(...skipping 28 matching lines...) Expand all Loading... | |
136 | 144 |
137 FontPlatformData FontResource::platformDataFromCustomData( | 145 FontPlatformData FontResource::platformDataFromCustomData( |
138 float size, | 146 float size, |
139 bool bold, | 147 bool bold, |
140 bool italic, | 148 bool italic, |
141 FontOrientation orientation) { | 149 FontOrientation orientation) { |
142 DCHECK(m_fontData); | 150 DCHECK(m_fontData); |
143 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 151 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
144 } | 152 } |
145 | 153 |
154 void FontResource::willReloadAfterDiskCacheMiss() { | |
155 DCHECK(isLoading()); | |
156 DCHECK(loader()->isCacheAwareLoadingActivated()); | |
157 | |
158 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); | |
Shao-Chuan Lee
2016/11/07 06:52:47
I feel like having this whenever client callbacks
| |
159 | |
160 if (m_loadLimitState == ShortLimitExceeded || | |
161 m_loadLimitState == LongLimitExceeded) | |
162 notifyClientsShortLimitExceeded(); | |
163 if (m_loadLimitState == LongLimitExceeded) | |
164 notifyClientsLongLimitExceeded(); | |
165 | |
166 DEFINE_STATIC_LOCAL( | |
167 EnumerationHistogram, loadLimitHistogram, | |
168 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax)); | |
169 loadLimitHistogram.count(m_loadLimitState); | |
Shao-Chuan Lee
2016/11/07 06:52:47
ksakamoto@: PTAL
Kunihiko Sakamoto
2016/11/07 07:56:24
Looks good. Please add a histogram.xml entry.
Shao-Chuan Lee
2016/11/07 08:43:44
Done.
| |
170 } | |
171 | |
146 void FontResource::fontLoadShortLimitCallback(TimerBase*) { | 172 void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
147 if (!isLoading()) | 173 DCHECK(isLoading()); |
148 return; | |
149 DCHECK_EQ(m_loadLimitState, UnderLimit); | 174 DCHECK_EQ(m_loadLimitState, UnderLimit); |
150 m_loadLimitState = ShortLimitExceeded; | 175 m_loadLimitState = ShortLimitExceeded; |
176 | |
177 // Block client callbacks if currently loading from cache. | |
178 if (loader()->isCacheAwareLoadingActivated()) | |
179 return; | |
180 notifyClientsShortLimitExceeded(); | |
181 } | |
182 | |
183 void FontResource::fontLoadLongLimitCallback(TimerBase*) { | |
184 DCHECK(isLoading()); | |
185 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); | |
186 m_loadLimitState = LongLimitExceeded; | |
187 | |
188 // Block client callbacks if currently loading from cache. | |
189 if (loader()->isCacheAwareLoadingActivated()) | |
190 return; | |
191 notifyClientsLongLimitExceeded(); | |
192 } | |
193 | |
194 void FontResource::notifyClientsShortLimitExceeded() { | |
151 ResourceClientWalker<FontResourceClient> walker(clients()); | 195 ResourceClientWalker<FontResourceClient> walker(clients()); |
152 while (FontResourceClient* client = walker.next()) | 196 while (FontResourceClient* client = walker.next()) |
153 client->fontLoadShortLimitExceeded(this); | 197 client->fontLoadShortLimitExceeded(this); |
154 } | 198 } |
155 | 199 |
156 void FontResource::fontLoadLongLimitCallback(TimerBase*) { | 200 void FontResource::notifyClientsLongLimitExceeded() { |
157 if (!isLoading()) | |
158 return; | |
159 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); | |
160 m_loadLimitState = LongLimitExceeded; | |
161 ResourceClientWalker<FontResourceClient> walker(clients()); | 201 ResourceClientWalker<FontResourceClient> walker(clients()); |
162 while (FontResourceClient* client = walker.next()) | 202 while (FontResourceClient* client = walker.next()) |
163 client->fontLoadLongLimitExceeded(this); | 203 client->fontLoadLongLimitExceeded(this); |
164 } | 204 } |
165 | 205 |
166 void FontResource::allClientsAndObserversRemoved() { | 206 void FontResource::allClientsAndObserversRemoved() { |
167 m_fontData.reset(); | 207 m_fontData.reset(); |
168 Resource::allClientsAndObserversRemoved(); | 208 Resource::allClientsAndObserversRemoved(); |
169 } | 209 } |
170 | 210 |
171 void FontResource::checkNotify() { | 211 void FontResource::checkNotify() { |
172 m_fontLoadShortLimitTimer.stop(); | 212 m_fontLoadShortLimitTimer.stop(); |
173 m_fontLoadLongLimitTimer.stop(); | 213 m_fontLoadLongLimitTimer.stop(); |
174 | 214 |
175 Resource::checkNotify(); | 215 Resource::checkNotify(); |
176 } | 216 } |
177 | 217 |
178 } // namespace blink | 218 } // namespace blink |
OLD | NEW |