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

Unified Diff: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp

Issue 2290983003: CSSStyleSheetResource should cache decoded text instead of raw bytes (Closed)
Patch Set: hiroshige review2 Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
diff --git a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
index f44d16a3fcff570c6df1692629a9cc5dde000860..481a51c37b4992b4ef2366e58d295976c13af20b 100644
--- a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
@@ -92,13 +92,20 @@ void CSSStyleSheetResource::didAddClient(ResourceClient* c)
const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const
{
- if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck))
+ if (!canUseSheet(mimeTypeCheck))
return String();
- if (!m_decodedSheetText.isNull())
+ // Use cached decoded sheet text when available
+ if (!m_decodedSheetText.isNull()) {
+ // We should have the decoded sheet text cached when the resource is fully loaded.
+ DCHECK(getStatus() != Resource::Cached);
Charlie Harrison 2016/08/31 13:01:18 nit: DCHECK_NE
kouhei (in TOK) 2016/09/02 03:43:42 Done.
+
return m_decodedSheetText;
+ }
+
+ if (!data() || data()->isEmpty())
+ return String();
- // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
return decodedText();
}
@@ -115,15 +122,15 @@ void CSSStyleSheetResource::appendData(const char* data, size_t length)
void CSSStyleSheetResource::checkNotify()
{
- // Decode the data to find out the encoding and keep the sheet text around during checkNotify()
- if (data())
+ // Decode the data to find out the encoding and cache the decoded sheet text.
Charlie Harrison 2016/08/31 13:01:18 Also comment that clearData() only clears the raw
kouhei (in TOK) 2016/09/02 03:43:42 Done.
+ if (data()) {
m_decodedSheetText = decodedText();
+ clearData();
+ }
ResourceClientWalker<StyleSheetResourceClient> w(clients());
while (StyleSheetResourceClient* c = w.next())
c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), this);
- // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.
- m_decodedSheetText = String();
}
void CSSStyleSheetResource::destroyDecodedDataIfPossible()
@@ -133,6 +140,13 @@ void CSSStyleSheetResource::destroyDecodedDataIfPossible()
setParsedStyleSheetCache(nullptr);
setDecodedSize(0);
+
+}
+
+void CSSStyleSheetResource::destroyDecodedDataIfPossible()
Charlie Harrison 2016/08/31 13:01:18 duplicate method?
kouhei (in TOK) 2016/09/02 03:43:42 Done.
kouhei (in TOK) 2016/09/02 03:43:42 Done.
+{
+ m_decodedSheetText = String();
+ destroyDecodedDataIfPossible();
}
bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698