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

Side by Side Diff: third_party/WebKit/Source/core/fetch/FontResource.cpp

Issue 2453813004: WebFonts cache-aware timeout adaptation (Closed)
Patch Set: simplify by not calling cache miss callback in didAddClient() Created 4 years, 1 month 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 /* 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
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
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
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(options().cacheAwareLoadingEnabled == IsCacheAwareLoadingEnabled);
156 DCHECK(isLoading());
157
158 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
159
160 ResourceClientWalker<FontResourceClient> walker(clients());
161 while (FontResourceClient* client = walker.next())
162 client->willReloadAfterDiskCacheMiss(this);
163
164 if (m_loadLimitState == ShortLimitExceeded ||
165 m_loadLimitState == LongLimitExceeded)
166 notifyClientsShortLimitExceeded();
167 if (m_loadLimitState == LongLimitExceeded)
168 notifyClientsLongLimitExceeded();
169 }
170
146 void FontResource::fontLoadShortLimitCallback(TimerBase*) { 171 void FontResource::fontLoadShortLimitCallback(TimerBase*) {
147 if (!isLoading()) 172 DCHECK(isLoading());
148 return;
149 DCHECK_EQ(m_loadLimitState, UnderLimit); 173 DCHECK_EQ(m_loadLimitState, UnderLimit);
150 m_loadLimitState = ShortLimitExceeded; 174 m_loadLimitState = ShortLimitExceeded;
175
176 // Block client callbacks if currently loading from cache.
177 if (loader()->isCacheAwareLoadingActivated())
178 return;
179 notifyClientsShortLimitExceeded();
180 }
181
182 void FontResource::fontLoadLongLimitCallback(TimerBase*) {
183 DCHECK(isLoading());
184 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
185 m_loadLimitState = LongLimitExceeded;
186
187 // Block client callbacks if currently loading from cache.
188 if (loader()->isCacheAwareLoadingActivated())
189 return;
190 notifyClientsLongLimitExceeded();
191 }
192
193 void FontResource::notifyClientsShortLimitExceeded() {
151 ResourceClientWalker<FontResourceClient> walker(clients()); 194 ResourceClientWalker<FontResourceClient> walker(clients());
152 while (FontResourceClient* client = walker.next()) 195 while (FontResourceClient* client = walker.next())
153 client->fontLoadShortLimitExceeded(this); 196 client->fontLoadShortLimitExceeded(this);
154 } 197 }
155 198
156 void FontResource::fontLoadLongLimitCallback(TimerBase*) { 199 void FontResource::notifyClientsLongLimitExceeded() {
157 if (!isLoading())
158 return;
159 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
160 m_loadLimitState = LongLimitExceeded;
161 ResourceClientWalker<FontResourceClient> walker(clients()); 200 ResourceClientWalker<FontResourceClient> walker(clients());
162 while (FontResourceClient* client = walker.next()) 201 while (FontResourceClient* client = walker.next())
163 client->fontLoadLongLimitExceeded(this); 202 client->fontLoadLongLimitExceeded(this);
164 } 203 }
165 204
166 void FontResource::allClientsAndObserversRemoved() { 205 void FontResource::allClientsAndObserversRemoved() {
167 m_fontData.reset(); 206 m_fontData.reset();
168 Resource::allClientsAndObserversRemoved(); 207 Resource::allClientsAndObserversRemoved();
169 } 208 }
170 209
171 void FontResource::checkNotify() { 210 void FontResource::checkNotify() {
172 m_fontLoadShortLimitTimer.stop(); 211 m_fontLoadShortLimitTimer.stop();
173 m_fontLoadLongLimitTimer.stop(); 212 m_fontLoadLongLimitTimer.stop();
174 213
175 Resource::checkNotify(); 214 Resource::checkNotify();
176 } 215 }
177 216
178 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698