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

Side by Side Diff: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp

Issue 2290983003: CSSStyleSheetResource should cache decoded text instead of raw bytes (Closed)
Patch Set: hiroshige review Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); 85 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this);
86 86
87 // |c| might be removed in didAppendFirstData, so ensure it is still a 87 // |c| might be removed in didAppendFirstData, so ensure it is still a
88 // client. 88 // client.
89 if (hasClient(c) && !isLoading()) 89 if (hasClient(c) && !isLoading())
90 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ est().url(), response().url(), encoding(), this); 90 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(resourceRequ est().url(), response().url(), encoding(), this);
91 } 91 }
92 92
93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const 93 const String CSSStyleSheetResource::sheetText(MIMETypeCheck mimeTypeCheck) const
94 { 94 {
95 if (!data() || data()->isEmpty() || !canUseSheet(mimeTypeCheck)) 95 if (!canUseSheet(mimeTypeCheck))
96 return String(); 96 return String();
97 97
98 if (!m_decodedSheetText.isNull()) 98 // Use cached decoded sheet text when available
99 if (!m_decodedSheetText.isNull()) {
100 // We should have the decoded sheet text cached when the resource is ful ly loaded.
101 DCHECK(getStatus() != Resource::Cached);
102
99 return m_decodedSheetText; 103 return m_decodedSheetText;
104 }
100 105
101 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory 106 if (!data() || data()->isEmpty())
107 return String();
108
102 return decodedText(); 109 return decodedText();
103 } 110 }
104 111
105 void CSSStyleSheetResource::appendData(const char* data, size_t length) 112 void CSSStyleSheetResource::appendData(const char* data, size_t length)
106 { 113 {
107 Resource::appendData(data, length); 114 Resource::appendData(data, length);
108 if (m_didNotifyFirstData) 115 if (m_didNotifyFirstData)
109 return; 116 return;
110 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 117 ResourceClientWalker<StyleSheetResourceClient> w(clients());
111 while (StyleSheetResourceClient* c = w.next()) 118 while (StyleSheetResourceClient* c = w.next())
112 c->didAppendFirstData(this); 119 c->didAppendFirstData(this);
113 m_didNotifyFirstData = true; 120 m_didNotifyFirstData = true;
114 } 121 }
115 122
116 void CSSStyleSheetResource::checkNotify() 123 void CSSStyleSheetResource::checkNotify()
117 { 124 {
118 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify() 125 // Decode the data to find out the encoding and cache the decoded sheet text .
119 if (data()) 126 if (data()) {
120 m_decodedSheetText = decodedText(); 127 m_decodedSheetText = decodedText();
128 clearData();
129 }
121 130
122 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 131 ResourceClientWalker<StyleSheetResourceClient> w(clients());
123 while (StyleSheetResourceClient* c = w.next()) 132 while (StyleSheetResourceClient* c = w.next())
124 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this); 133 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding( ), this);
125 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate.
126 m_decodedSheetText = String();
127 } 134 }
128 135
129 void CSSStyleSheetResource::destroyDecodedDataIfPossible() 136 void CSSStyleSheetResource::destroyDecodedDataIfPossible()
130 { 137 {
138 m_decodedSheetText = String();
hiroshige 2016/08/31 10:34:53 Probably clearing |m_decodedSheetText| in destroyD
131 if (!m_parsedStyleSheetCache) 139 if (!m_parsedStyleSheetCache)
132 return; 140 return;
133 141
134 setParsedStyleSheetCache(nullptr); 142 setParsedStyleSheetCache(nullptr);
135 setDecodedSize(0); 143 setDecodedSize(0);
136 } 144 }
137 145
138 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const 146 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const
139 { 147 {
140 if (errorOccurred()) 148 if (errorOccurred())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // This stylesheet resource did conflict with another resource and was 190 // This stylesheet resource did conflict with another resource and was
183 // not added to the cache. 191 // not added to the cache.
184 setParsedStyleSheetCache(nullptr); 192 setParsedStyleSheetCache(nullptr);
185 return; 193 return;
186 } 194 }
187 setParsedStyleSheetCache(sheet); 195 setParsedStyleSheetCache(sheet);
188 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 196 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
189 } 197 }
190 198
191 } // namespace blink 199 } // namespace blink
OLDNEW
« 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