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

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

Issue 2438033003: [NOT FOR COMMIT] Layout test for WebFonts cache-aware timeout adaption (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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 WebURLRequest::RequestContextFont); 81 WebURLRequest::RequestContextFont);
82 return toFontResource( 82 return toFontResource(
83 fetcher->requestResource(request, FontResourceFactory())); 83 fetcher->requestResource(request, FontResourceFactory()));
84 } 84 }
85 85
86 FontResource::FontResource(const ResourceRequest& resourceRequest, 86 FontResource::FontResource(const ResourceRequest& resourceRequest,
87 const ResourceLoaderOptions& options) 87 const ResourceLoaderOptions& options)
88 : Resource(resourceRequest, Font, options), 88 : Resource(resourceRequest, Font, options),
89 m_loadLimitState(LoadNotStarted), 89 m_loadLimitState(LoadNotStarted),
90 m_corsFailed(false), 90 m_corsFailed(false),
91 m_isCallbackDisabledForTesting(false),
91 m_fontLoadShortLimitTimer(this, 92 m_fontLoadShortLimitTimer(this,
92 &FontResource::fontLoadShortLimitCallback), 93 &FontResource::fontLoadShortLimitCallback),
93 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) { 94 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) {
94 } 95 }
95 96
96 FontResource::~FontResource() {} 97 FontResource::~FontResource() {}
97 98
98 void FontResource::didAddClient(ResourceClient* c) { 99 void FontResource::didAddClient(ResourceClient* c) {
99 DCHECK(FontResourceClient::isExpectedType(c)); 100 DCHECK(FontResourceClient::isExpectedType(c));
100 Resource::didAddClient(c); 101 Resource::didAddClient(c);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 FontPlatformData FontResource::platformDataFromCustomData( 147 FontPlatformData FontResource::platformDataFromCustomData(
147 float size, 148 float size,
148 bool bold, 149 bool bold,
149 bool italic, 150 bool italic,
150 FontOrientation orientation) { 151 FontOrientation orientation) {
151 DCHECK(m_fontData); 152 DCHECK(m_fontData);
152 return m_fontData->fontPlatformData(size, bold, italic, orientation); 153 return m_fontData->fontPlatformData(size, bold, italic, orientation);
153 } 154 }
154 155
155 void FontResource::willReloadAfterDiskCacheMiss() { 156 void FontResource::willReloadAfterDiskCacheMiss() {
157 if (m_isCallbackDisabledForTesting)
158 return;
159
156 DCHECK(isLoading()); 160 DCHECK(isLoading());
157 DCHECK(loader()->isCacheAwareLoadingActivated());
158 161
159 if (m_loadLimitState == ShortLimitExceeded || 162 if (m_loadLimitState == ShortLimitExceeded ||
160 m_loadLimitState == LongLimitExceeded) 163 m_loadLimitState == LongLimitExceeded)
161 notifyClientsShortLimitExceeded(); 164 notifyClientsShortLimitExceeded();
162 if (m_loadLimitState == LongLimitExceeded) 165 if (m_loadLimitState == LongLimitExceeded)
163 notifyClientsLongLimitExceeded(); 166 notifyClientsLongLimitExceeded();
164 167
165 DEFINE_STATIC_LOCAL( 168 DEFINE_STATIC_LOCAL(
166 EnumerationHistogram, loadLimitHistogram, 169 EnumerationHistogram, loadLimitHistogram,
167 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax)); 170 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax));
168 loadLimitHistogram.count(m_loadLimitState); 171 loadLimitHistogram.count(m_loadLimitState);
169 } 172 }
170 173
171 void FontResource::fontLoadShortLimitCallback(TimerBase*) { 174 void FontResource::fontLoadShortLimitCallback(TimerBase*) {
172 DCHECK(isLoading()); 175 DCHECK(isLoading());
173 DCHECK_EQ(m_loadLimitState, UnderLimit); 176 DCHECK_EQ(m_loadLimitState, UnderLimit);
174 m_loadLimitState = ShortLimitExceeded; 177 m_loadLimitState = ShortLimitExceeded;
175 178
179 if (m_isCallbackDisabledForTesting)
180 return;
181
176 // Block client callbacks if currently loading from cache. 182 // Block client callbacks if currently loading from cache.
177 if (loader()->isCacheAwareLoadingActivated()) 183 if (loader()->isCacheAwareLoadingActivated())
178 return; 184 return;
179 notifyClientsShortLimitExceeded(); 185 notifyClientsShortLimitExceeded();
180 } 186 }
181 187
182 void FontResource::fontLoadLongLimitCallback(TimerBase*) { 188 void FontResource::fontLoadLongLimitCallback(TimerBase*) {
183 DCHECK(isLoading()); 189 DCHECK(isLoading());
184 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); 190 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
185 m_loadLimitState = LongLimitExceeded; 191 m_loadLimitState = LongLimitExceeded;
186 192
193 if (m_isCallbackDisabledForTesting)
194 return;
195
187 // Block client callbacks if currently loading from cache. 196 // Block client callbacks if currently loading from cache.
188 if (loader()->isCacheAwareLoadingActivated()) 197 if (loader()->isCacheAwareLoadingActivated())
189 return; 198 return;
190 notifyClientsLongLimitExceeded(); 199 notifyClientsLongLimitExceeded();
191 } 200 }
192 201
193 void FontResource::notifyClientsShortLimitExceeded() { 202 void FontResource::notifyClientsShortLimitExceeded() {
194 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); 203 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
195 ResourceClientWalker<FontResourceClient> walker(clients()); 204 ResourceClientWalker<FontResourceClient> walker(clients());
196 while (FontResourceClient* client = walker.next()) 205 while (FontResourceClient* client = walker.next())
(...skipping 25 matching lines...) Expand all
222 ResourceClientWalker<FontResourceClient> walker(clients()); 231 ResourceClientWalker<FontResourceClient> walker(clients());
223 while (FontResourceClient* client = walker.next()) { 232 while (FontResourceClient* client = walker.next()) {
224 if (!client->isLowPriorityLoadingAllowedForRemoteFont()) { 233 if (!client->isLowPriorityLoadingAllowedForRemoteFont()) {
225 return false; 234 return false;
226 } 235 }
227 } 236 }
228 return true; 237 return true;
229 } 238 }
230 239
231 } // namespace blink 240 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698