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

Unified Diff: third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp

Issue 2453813004: WebFonts cache-aware timeout adaptation (Closed)
Patch Set: simplify by not calling cache miss callback in didAddClient() 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 side-by-side diff with in-line comments
Download patch
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())

Powered by Google App Engine
This is Rietveld 408576698