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

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

Issue 2390583002: [WIP] WebFonts cache-aware timeout adaption (Closed)
Patch Set: handle font-display: swap Created 4 years, 2 months 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 21 matching lines...) Expand all
32 #include "platform/Histogram.h" 32 #include "platform/Histogram.h"
33 #include "platform/SharedBuffer.h" 33 #include "platform/SharedBuffer.h"
34 #include "platform/fonts/FontCustomPlatformData.h" 34 #include "platform/fonts/FontCustomPlatformData.h"
35 #include "platform/fonts/FontPlatformData.h" 35 #include "platform/fonts/FontPlatformData.h"
36 #include "wtf/CurrentTime.h" 36 #include "wtf/CurrentTime.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 // Durations of font-display periods. 40 // Durations of font-display periods.
41 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc 41 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc
42 static const double fontLoadWaitShortLimitSec = 0.1; 42 static const double fontLoadWaitShortLimitSec = 0.1;
Kunihiko Sakamoto 2016/10/12 08:56:30 With cache-aware loading, disk cache RTT longer th
Shao-Chuan Lee 2016/10/17 03:45:59 Done.
43 static const double fontLoadWaitLongLimitSec = 3.0; 43 static const double fontLoadWaitLongLimitSec = 3.0;
44 44
45 enum FontPackageFormat { 45 enum FontPackageFormat {
46 PackageFormatUnknown, 46 PackageFormatUnknown,
47 PackageFormatSFNT, 47 PackageFormatSFNT,
48 PackageFormatWOFF, 48 PackageFormatWOFF,
49 PackageFormatWOFF2, 49 PackageFormatWOFF2,
50 PackageFormatSVG, 50 PackageFormatSVG,
51 PackageFormatEnumMax 51 PackageFormatEnumMax
52 }; 52 };
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 FontPlatformData FontResource::platformDataFromCustomData( 138 FontPlatformData FontResource::platformDataFromCustomData(
139 float size, 139 float size,
140 bool bold, 140 bool bold,
141 bool italic, 141 bool italic,
142 FontOrientation orientation) { 142 FontOrientation orientation) {
143 DCHECK(m_fontData); 143 DCHECK(m_fontData);
144 return m_fontData->fontPlatformData(size, bold, italic, orientation); 144 return m_fontData->fontPlatformData(size, bold, italic, orientation);
145 } 145 }
146 146
147 void FontResource::willReloadAfterDiskCacheMiss() {
148 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
149
150 ResourceClientWalker<FontResourceClient> walker(clients());
151 while (FontResourceClient* client = walker.next())
152 client->willReloadAfterDiskCacheMiss(this);
153
154 DCHECK(!resourceRequest().isCacheAwareLoadingActivated());
155 if (!m_fontLoadShortLimitTimer.isActive())
156 fontLoadShortLimitCallback(nullptr);
yhirano 2016/10/12 06:30:38 This code assumes that startLoadLimitTimersIfNeede
Shao-Chuan Lee 2016/10/13 05:20:45 Load limit timers are always started after FontRes
Shao-Chuan Lee 2016/10/17 03:45:59 Added comments.
157 if (!m_fontLoadLongLimitTimer.isActive())
158 fontLoadLongLimitCallback(nullptr);
159 }
160
147 void FontResource::fontLoadShortLimitCallback(TimerBase*) { 161 void FontResource::fontLoadShortLimitCallback(TimerBase*) {
148 if (!isLoading()) 162 if (!isLoading())
149 return; 163 return;
164 if (resourceRequest().isCacheAwareLoadingActivated())
165 return;
150 DCHECK_EQ(m_loadLimitState, UnderLimit); 166 DCHECK_EQ(m_loadLimitState, UnderLimit);
151 m_loadLimitState = ShortLimitExceeded; 167 m_loadLimitState = ShortLimitExceeded;
152 ResourceClientWalker<FontResourceClient> walker(clients()); 168 ResourceClientWalker<FontResourceClient> walker(clients());
153 while (FontResourceClient* client = walker.next()) 169 while (FontResourceClient* client = walker.next())
154 client->fontLoadShortLimitExceeded(this); 170 client->fontLoadShortLimitExceeded(this);
155 } 171 }
156 172
157 void FontResource::fontLoadLongLimitCallback(TimerBase*) { 173 void FontResource::fontLoadLongLimitCallback(TimerBase*) {
158 if (!isLoading()) 174 if (!isLoading())
159 return; 175 return;
176 if (resourceRequest().isCacheAwareLoadingActivated())
177 return;
160 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); 178 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded);
161 m_loadLimitState = LongLimitExceeded; 179 m_loadLimitState = LongLimitExceeded;
162 ResourceClientWalker<FontResourceClient> walker(clients()); 180 ResourceClientWalker<FontResourceClient> walker(clients());
163 while (FontResourceClient* client = walker.next()) 181 while (FontResourceClient* client = walker.next())
164 client->fontLoadLongLimitExceeded(this); 182 client->fontLoadLongLimitExceeded(this);
165 } 183 }
166 184
167 void FontResource::allClientsAndObserversRemoved() { 185 void FontResource::allClientsAndObserversRemoved() {
168 m_fontData.reset(); 186 m_fontData.reset();
169 Resource::allClientsAndObserversRemoved(); 187 Resource::allClientsAndObserversRemoved();
170 } 188 }
171 189
172 void FontResource::checkNotify() { 190 void FontResource::checkNotify() {
173 m_fontLoadShortLimitTimer.stop(); 191 m_fontLoadShortLimitTimer.stop();
174 m_fontLoadLongLimitTimer.stop(); 192 m_fontLoadLongLimitTimer.stop();
175 193
176 Resource::checkNotify(); 194 Resource::checkNotify();
177 } 195 }
178 196
179 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698