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..f544c7014e4d7b88094ac143a1dbb50d6457ff26 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,52 @@ FontPlatformData FontResource::platformDataFromCustomData( |
return m_fontData->fontPlatformData(size, bold, italic, orientation); |
} |
+void FontResource::willReloadAfterDiskCacheMiss() { |
+ DCHECK(options().cacheAwareLoadingEnabled == IsCacheAwareLoadingEnabled); |
+ DCHECK(isLoading()); |
+ |
+ ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
+ |
+ ResourceClientWalker<FontResourceClient> walker(clients()); |
+ while (FontResourceClient* client = walker.next()) |
+ client->willReloadAfterDiskCacheMiss(this); |
+ |
+ if (m_loadLimitState == ShortLimitExceeded || |
+ m_loadLimitState == LongLimitExceeded) |
+ notifyClientsShortLimitExceeded(); |
+ if (m_loadLimitState == LongLimitExceeded) |
+ notifyClientsLongLimitExceeded(); |
+} |
+ |
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); |