Index: third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp |
diff --git a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp |
index e6f9a8c7845dd7d7ec5e0fb09577a04afb6d853a..1b05405e3f390a21168366a79137fc7c7bd58201 100644 |
--- a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp |
+++ b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp |
@@ -9,6 +9,7 @@ |
#include "core/css/CSSFontSelector.h" |
#include "core/dom/Document.h" |
#include "core/fetch/ResourceFetcher.h" |
+#include "core/fetch/ResourceLoader.h" |
#include "core/inspector/ConsoleMessage.h" |
#include "core/loader/FrameLoaderClient.h" |
#include "core/page/NetworkStateNotifier.h" |
@@ -56,7 +57,7 @@ RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
: m_font(font), |
m_fontSelector(fontSelector), |
m_display(display), |
- m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod), |
+ m_period(BlockPeriod), |
m_histograms(font->url().protocolIsData() |
? FontLoadHistograms::FromDataURL |
: font->isLoaded() ? FontLoadHistograms::FromMemoryCache |
@@ -64,7 +65,6 @@ RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
m_display), |
m_isInterventionTriggered(false) { |
ThreadState::current()->registerPreFinalizer(this); |
- m_font->addClient(this); |
if (shouldTriggerWebFontsIntervention()) { |
m_isInterventionTriggered = true; |
@@ -74,6 +74,13 @@ RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, |
"Slow network is detected. Fallback font will be used while loading: " + |
m_font->url().elidedString())); |
} |
+ |
+ if (m_display == FontDisplaySwap && !shouldTriggerCacheAwareAdaptation()) |
+ m_period = SwapPeriod; |
+ |
+ // Font loading callbacks may be called in addClient(), make sure |m_period| |
+ // is properly set before calling. |
+ m_font->addClient(this); |
} |
RemoteFontFaceSource::~RemoteFontFaceSource() {} |
@@ -161,8 +168,14 @@ void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) { |
m_histograms.longLimitExceeded(m_isInterventionTriggered); |
} |
+void RemoteFontFaceSource::willReloadAfterDiskCacheMiss(const FontResource*) { |
+ DCHECK(m_font->isLoading()); |
+ if (m_display == FontDisplaySwap) |
+ switchToSwapPeriod(); |
+} |
+ |
void RemoteFontFaceSource::switchToSwapPeriod() { |
- ASSERT(m_period == BlockPeriod); |
+ DCHECK_EQ(m_period, BlockPeriod); |
m_period = SwapPeriod; |
pruneTable(); |
@@ -177,7 +190,7 @@ void RemoteFontFaceSource::switchToSwapPeriod() { |
void RemoteFontFaceSource::switchToFailurePeriod() { |
if (m_period == BlockPeriod) |
switchToSwapPeriod(); |
- ASSERT(m_period == SwapPeriod); |
+ DCHECK_EQ(m_period, SwapPeriod); |
m_period = FailurePeriod; |
} |
@@ -200,6 +213,16 @@ bool RemoteFontFaceSource::shouldTriggerWebFontsIntervention() { |
return networkIsSlow && m_display == FontDisplayAuto; |
} |
+bool RemoteFontFaceSource::shouldTriggerCacheAwareAdaptation() { |
+ if (m_font->stillNeedsLoad() && |
+ m_font->options().cacheAwareLoadingEnabled == IsCacheAwareLoadingEnabled) |
+ return true; |
+ if (m_font->isLoading() && m_font->loader()->isCacheAwareLoadingActivated()) |
+ return true; |
+ // willReloadAfterDiskCacheMiss() will not be called. |
+ return false; |
+} |
+ |
PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData( |
const FontDescription& fontDescription) { |
if (!isLoaded()) |