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

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

Issue 2453813004: WebFonts cache-aware timeout adaptation (Closed)
Patch Set: rebase 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
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 28 matching lines...) Expand all
136 145
137 FontPlatformData FontResource::platformDataFromCustomData( 146 FontPlatformData FontResource::platformDataFromCustomData(
138 float size, 147 float size,
139 bool bold, 148 bool bold,
140 bool italic, 149 bool italic,
141 FontOrientation orientation) { 150 FontOrientation orientation) {
142 DCHECK(m_fontData); 151 DCHECK(m_fontData);
143 return m_fontData->fontPlatformData(size, bold, italic, orientation); 152 return m_fontData->fontPlatformData(size, bold, italic, orientation);
144 } 153 }
145 154
155 void FontResource::willReloadAfterDiskCacheMiss() {
156 DCHECK(isLoading());
157 DCHECK(loader()->isCacheAwareLoadingActivated());
158
159 if (m_loadLimitState == ShortLimitExceeded ||
160 m_loadLimitState == LongLimitExceeded)
161 notifyClientsShortLimitExceeded();
162 if (m_loadLimitState == LongLimitExceeded)
163 notifyClientsLongLimitExceeded();
164
165 DEFINE_STATIC_LOCAL(
166 EnumerationHistogram, loadLimitHistogram,
167 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax));
168 loadLimitHistogram.count(m_loadLimitState);
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() {
194 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
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()) 201 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
158 return;
159 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
160 m_loadLimitState = LongLimitExceeded;
161 ResourceClientWalker<FontResourceClient> walker(clients()); 202 ResourceClientWalker<FontResourceClient> walker(clients());
162 while (FontResourceClient* client = walker.next()) 203 while (FontResourceClient* client = walker.next())
163 client->fontLoadLongLimitExceeded(this); 204 client->fontLoadLongLimitExceeded(this);
164 } 205 }
165 206
166 void FontResource::allClientsAndObserversRemoved() { 207 void FontResource::allClientsAndObserversRemoved() {
167 m_fontData.reset(); 208 m_fontData.reset();
168 Resource::allClientsAndObserversRemoved(); 209 Resource::allClientsAndObserversRemoved();
169 } 210 }
170 211
(...skipping 10 matching lines...) Expand all
181 ResourceClientWalker<FontResourceClient> walker(clients()); 222 ResourceClientWalker<FontResourceClient> walker(clients());
182 while (FontResourceClient* client = walker.next()) { 223 while (FontResourceClient* client = walker.next()) {
183 if (!client->isLowPriorityLoadingAllowedForRemoteFont()) { 224 if (!client->isLowPriorityLoadingAllowedForRemoteFont()) {
184 return false; 225 return false;
185 } 226 }
186 } 227 }
187 return true; 228 return true;
188 } 229 }
189 230
190 } // namespace blink 231 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FontResource.h ('k') | third_party/WebKit/Source/core/fetch/MockResourceClients.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698