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

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

Issue 2556683003: Reland: WebFonts cache-aware timeout adaptation (Closed)
Patch Set: rebase Created 4 years 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/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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 148
140 FontPlatformData FontResource::platformDataFromCustomData( 149 FontPlatformData FontResource::platformDataFromCustomData(
141 float size, 150 float size,
142 bool bold, 151 bool bold,
143 bool italic, 152 bool italic,
144 FontOrientation orientation) { 153 FontOrientation orientation) {
145 DCHECK(m_fontData); 154 DCHECK(m_fontData);
146 return m_fontData->fontPlatformData(size, bold, italic, orientation); 155 return m_fontData->fontPlatformData(size, bold, italic, orientation);
147 } 156 }
148 157
158 void FontResource::willReloadAfterDiskCacheMiss() {
159 DCHECK(isLoading());
160 DCHECK(loader()->isCacheAwareLoadingActivated());
161 if (m_loadLimitState == ShortLimitExceeded ||
162 m_loadLimitState == LongLimitExceeded) {
163 notifyClientsShortLimitExceeded();
164 }
165 if (m_loadLimitState == LongLimitExceeded)
166 notifyClientsLongLimitExceeded();
167
168 DEFINE_STATIC_LOCAL(
169 EnumerationHistogram, loadLimitHistogram,
170 ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax));
171 loadLimitHistogram.count(m_loadLimitState);
172 }
173
149 void FontResource::fontLoadShortLimitCallback(TimerBase*) { 174 void FontResource::fontLoadShortLimitCallback(TimerBase*) {
150 DCHECK(isLoading()); 175 DCHECK(isLoading());
151 DCHECK_EQ(m_loadLimitState, UnderLimit); 176 DCHECK_EQ(m_loadLimitState, UnderLimit);
152 m_loadLimitState = ShortLimitExceeded; 177 m_loadLimitState = ShortLimitExceeded;
153 ResourceClientWalker<FontResourceClient> walker(clients()); 178
154 while (FontResourceClient* client = walker.next()) 179 // Block client callbacks if currently loading from cache.
155 client->fontLoadShortLimitExceeded(this); 180 if (loader()->isCacheAwareLoadingActivated())
181 return;
182 notifyClientsShortLimitExceeded();
156 } 183 }
157 184
158 void FontResource::fontLoadLongLimitCallback(TimerBase*) { 185 void FontResource::fontLoadLongLimitCallback(TimerBase*) {
159 DCHECK(isLoading()); 186 DCHECK(isLoading());
160 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); 187 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
161 m_loadLimitState = LongLimitExceeded; 188 m_loadLimitState = LongLimitExceeded;
189
190 // Block client callbacks if currently loading from cache.
191 if (loader()->isCacheAwareLoadingActivated())
192 return;
193 notifyClientsLongLimitExceeded();
194 }
195
196 void FontResource::notifyClientsShortLimitExceeded() {
197 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
198 ResourceClientWalker<FontResourceClient> walker(clients());
199 while (FontResourceClient* client = walker.next())
200 client->fontLoadShortLimitExceeded(this);
201 }
202
203 void FontResource::notifyClientsLongLimitExceeded() {
204 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
162 ResourceClientWalker<FontResourceClient> walker(clients()); 205 ResourceClientWalker<FontResourceClient> walker(clients());
163 while (FontResourceClient* client = walker.next()) 206 while (FontResourceClient* client = walker.next())
164 client->fontLoadLongLimitExceeded(this); 207 client->fontLoadLongLimitExceeded(this);
165 } 208 }
166 209
167 void FontResource::allClientsAndObserversRemoved() { 210 void FontResource::allClientsAndObserversRemoved() {
168 m_fontData.reset(); 211 m_fontData.reset();
169 Resource::allClientsAndObserversRemoved(); 212 Resource::allClientsAndObserversRemoved();
170 } 213 }
171 214
(...skipping 21 matching lines...) Expand all
193 Resource::onMemoryDump(level, memoryDump); 236 Resource::onMemoryDump(level, memoryDump);
194 if (!m_fontData) 237 if (!m_fontData)
195 return; 238 return;
196 const String name = getMemoryDumpName() + "/decoded_webfont"; 239 const String name = getMemoryDumpName() + "/decoded_webfont";
197 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(name); 240 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(name);
198 dump->addScalar("size", "bytes", m_fontData->dataSize()); 241 dump->addScalar("size", "bytes", m_fontData->dataSize());
199 memoryDump->addSuballocation(dump->guid(), "malloc"); 242 memoryDump->addSuballocation(dump->guid(), "malloc");
200 } 243 }
201 244
202 } // namespace blink 245 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698