Chromium Code Reviews| 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..614bc48e55ed0e82bb4938648155bd6d25177184 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); |
| + |
| 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,19 +122,20 @@ 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. |
| + 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() |
| { |
| + m_decodedSheetText = String(); |
|
hiroshige
2016/08/31 10:34:53
Probably clearing |m_decodedSheetText| in destroyD
|
| if (!m_parsedStyleSheetCache) |
| return; |