Chromium Code Reviews| Index: third_party/WebKit/Source/core/loader/resource/FontResource.cpp |
| diff --git a/third_party/WebKit/Source/core/loader/resource/FontResource.cpp b/third_party/WebKit/Source/core/loader/resource/FontResource.cpp |
| index 3018c7641efdce176613b75674222240201b7b13..c7e4bdedd55dd6b3c022185b200b61b3e7c7a342 100644 |
| --- a/third_party/WebKit/Source/core/loader/resource/FontResource.cpp |
| +++ b/third_party/WebKit/Source/core/loader/resource/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(toyoshim): 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,12 @@ 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; |
| + |
| + ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
| if (m_loadLimitState == ShortLimitExceeded || |
| m_loadLimitState == LongLimitExceeded) |
| static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
| @@ -150,6 +159,22 @@ FontPlatformData FontResource::platformDataFromCustomData( |
| return m_fontData->fontPlatformData(size, bold, italic, orientation); |
| } |
| +void FontResource::willReloadAfterDiskCacheMiss() { |
| + DCHECK(isLoading()); |
| + DCHECK(loader()->isCacheAwareLoadingActivated()); |
| + 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); |
| +} |
| + |
| void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
| // TODO(toyoshim): Change CHECK() to DCHECK() and remove if(!isLoading()) if |
| // this can survive on Canary for some days. http://crbug.com/670638 |
| @@ -158,19 +183,33 @@ void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
| return; |
| 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*) { |
| - // TODO(toyoshim): Change CHECK() to DCHECK() and remove if(!isLoading()) if |
| - // this can survive on Canary for some days. http://crbug.com/670638 |
| - CHECK(isLoading()); |
| - if (!isLoading()) |
| - return; |
| + DCHECK(isLoading()); |
|
Shao-Chuan Lee
2016/12/09 06:33:52
Should we make this consistent with fontLoadShortL
Takashi Toyoshima
2016/12/09 10:28:20
Sorry for mixing new and old code in this CL.
Yea
|
| DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); |
| m_loadLimitState = LongLimitExceeded; |
| + |
| + // Block client callbacks if currently loading from cache. |
| + if (loader()->isCacheAwareLoadingActivated()) |
| + return; |
| + notifyClientsLongLimitExceeded(); |
| +} |
| + |
| +void FontResource::notifyClientsShortLimitExceeded() { |
| + ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
| + ResourceClientWalker<FontResourceClient> walker(clients()); |
| + while (FontResourceClient* client = walker.next()) |
| + client->fontLoadShortLimitExceeded(this); |
| +} |
| + |
| +void FontResource::notifyClientsLongLimitExceeded() { |
| + ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
| ResourceClientWalker<FontResourceClient> walker(clients()); |
| while (FontResourceClient* client = walker.next()) |
| client->fontLoadLongLimitExceeded(this); |