Index: third_party/WebKit/Source/core/fetch/FontResource.cpp |
diff --git a/third_party/WebKit/Source/core/fetch/FontResource.cpp b/third_party/WebKit/Source/core/fetch/FontResource.cpp |
index 2de0a247cda364998c55aca696d0456f8f37c313..f8daa718b4f277e59afbbe23de5909a137276841 100644 |
--- a/third_party/WebKit/Source/core/fetch/FontResource.cpp |
+++ b/third_party/WebKit/Source/core/fetch/FontResource.cpp |
@@ -29,6 +29,7 @@ |
#include "core/fetch/FetchRequest.h" |
#include "core/fetch/ResourceClientWalker.h" |
#include "core/fetch/ResourceFetcher.h" |
+#include "core/fetch/ResourceLoader.h" |
#include "platform/Histogram.h" |
#include "platform/SharedBuffer.h" |
#include "platform/fonts/FontCustomPlatformData.h" |
@@ -39,6 +40,8 @@ namespace blink { |
// Durations of font-display periods. |
// https://tabatkins.github.io/specs/css-font-display/#font-display-desc |
+// TODO(shaochuan): Revisit short limit value once cache-aware font display is |
+// launched. crbug.com/570205 |
static const double fontLoadWaitShortLimitSec = 0.1; |
static const double fontLoadWaitLongLimitSec = 3.0; |
@@ -95,6 +98,11 @@ FontResource::~FontResource() {} |
void FontResource::didAddClient(ResourceClient* c) { |
DCHECK(FontResourceClient::isExpectedType(c)); |
Resource::didAddClient(c); |
+ |
+ // Block client callbacks if currently loading from cache. |
+ if (isLoading() && loader()->isCacheAwareLoadingActivated()) |
+ return; |
+ |
if (m_loadLimitState == ShortLimitExceeded || |
m_loadLimitState == LongLimitExceeded) |
static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
@@ -143,21 +151,53 @@ FontPlatformData FontResource::platformDataFromCustomData( |
return m_fontData->fontPlatformData(size, bold, italic, orientation); |
} |
+void FontResource::willReloadAfterDiskCacheMiss() { |
+ DCHECK(isLoading()); |
+ DCHECK(loader()->isCacheAwareLoadingActivated()); |
+ |
+ ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
Shao-Chuan Lee
2016/11/07 06:52:47
I feel like having this whenever client callbacks
|
+ |
+ if (m_loadLimitState == ShortLimitExceeded || |
+ m_loadLimitState == LongLimitExceeded) |
+ notifyClientsShortLimitExceeded(); |
+ if (m_loadLimitState == LongLimitExceeded) |
+ notifyClientsLongLimitExceeded(); |
+ |
+ DEFINE_STATIC_LOCAL( |
+ EnumerationHistogram, loadLimitHistogram, |
+ ("WebFont.LoadLimitOnDiskCacheMiss", LoadLimitStateEnumMax)); |
+ loadLimitHistogram.count(m_loadLimitState); |
Shao-Chuan Lee
2016/11/07 06:52:47
ksakamoto@: PTAL
Kunihiko Sakamoto
2016/11/07 07:56:24
Looks good. Please add a histogram.xml entry.
Shao-Chuan Lee
2016/11/07 08:43:44
Done.
|
+} |
+ |
void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
- if (!isLoading()) |
- return; |
+ DCHECK(isLoading()); |
DCHECK_EQ(m_loadLimitState, UnderLimit); |
m_loadLimitState = ShortLimitExceeded; |
- ResourceClientWalker<FontResourceClient> walker(clients()); |
- while (FontResourceClient* client = walker.next()) |
- client->fontLoadShortLimitExceeded(this); |
+ |
+ // Block client callbacks if currently loading from cache. |
+ if (loader()->isCacheAwareLoadingActivated()) |
+ return; |
+ notifyClientsShortLimitExceeded(); |
} |
void FontResource::fontLoadLongLimitCallback(TimerBase*) { |
- if (!isLoading()) |
- return; |
+ DCHECK(isLoading()); |
DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); |
m_loadLimitState = LongLimitExceeded; |
+ |
+ // Block client callbacks if currently loading from cache. |
+ if (loader()->isCacheAwareLoadingActivated()) |
+ return; |
+ notifyClientsLongLimitExceeded(); |
+} |
+ |
+void FontResource::notifyClientsShortLimitExceeded() { |
+ ResourceClientWalker<FontResourceClient> walker(clients()); |
+ while (FontResourceClient* client = walker.next()) |
+ client->fontLoadShortLimitExceeded(this); |
+} |
+ |
+void FontResource::notifyClientsLongLimitExceeded() { |
ResourceClientWalker<FontResourceClient> walker(clients()); |
while (FontResourceClient* client = walker.next()) |
client->fontLoadLongLimitExceeded(this); |