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

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

Issue 2477293002: Report the size of |CSSStyleSheetResource::m_decodedSheetText| as decoded size (Closed)
Patch Set: setDecodedSheetText() Created 4 years, 1 month 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 CSSStyleSheetResource::~CSSStyleSheetResource() {} 71 CSSStyleSheetResource::~CSSStyleSheetResource() {}
72 72
73 void CSSStyleSheetResource::setParsedStyleSheetCache( 73 void CSSStyleSheetResource::setParsedStyleSheetCache(
74 StyleSheetContents* newSheet) { 74 StyleSheetContents* newSheet) {
75 if (m_parsedStyleSheetCache) 75 if (m_parsedStyleSheetCache)
76 m_parsedStyleSheetCache->clearReferencedFromResource(); 76 m_parsedStyleSheetCache->clearReferencedFromResource();
77 m_parsedStyleSheetCache = newSheet; 77 m_parsedStyleSheetCache = newSheet;
78 if (m_parsedStyleSheetCache) 78 if (m_parsedStyleSheetCache)
79 m_parsedStyleSheetCache->setReferencedFromResource(this); 79 m_parsedStyleSheetCache->setReferencedFromResource(this);
80
81 // Updates the decoded size to take parsed stylesheet cache into account.
82 updateDecodedSize();
80 } 83 }
81 84
82 DEFINE_TRACE(CSSStyleSheetResource) { 85 DEFINE_TRACE(CSSStyleSheetResource) {
83 visitor->trace(m_parsedStyleSheetCache); 86 visitor->trace(m_parsedStyleSheetCache);
84 StyleSheetResource::trace(visitor); 87 StyleSheetResource::trace(visitor);
85 } 88 }
86 89
87 void CSSStyleSheetResource::didAddClient(ResourceClient* c) { 90 void CSSStyleSheetResource::didAddClient(ResourceClient* c) {
88 DCHECK(StyleSheetResourceClient::isExpectedType(c)); 91 DCHECK(StyleSheetResourceClient::isExpectedType(c));
89 // Resource::didAddClient() must be before setCSSStyleSheet(), because 92 // Resource::didAddClient() must be before setCSSStyleSheet(), because
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (m_didNotifyFirstData) 130 if (m_didNotifyFirstData)
128 return; 131 return;
129 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 132 ResourceClientWalker<StyleSheetResourceClient> w(clients());
130 while (StyleSheetResourceClient* c = w.next()) 133 while (StyleSheetResourceClient* c = w.next())
131 c->didAppendFirstData(this); 134 c->didAppendFirstData(this);
132 m_didNotifyFirstData = true; 135 m_didNotifyFirstData = true;
133 } 136 }
134 137
135 void CSSStyleSheetResource::checkNotify() { 138 void CSSStyleSheetResource::checkNotify() {
136 // Decode the data to find out the encoding and cache the decoded sheet text. 139 // Decode the data to find out the encoding and cache the decoded sheet text.
137 if (data()) { 140 if (data())
138 m_decodedSheetText = decodedText(); 141 setDecodedSheetText(decodedText());
139 }
140 142
141 ResourceClientWalker<StyleSheetResourceClient> w(clients()); 143 ResourceClientWalker<StyleSheetResourceClient> w(clients());
142 while (StyleSheetResourceClient* c = w.next()) { 144 while (StyleSheetResourceClient* c = w.next()) {
143 markClientFinished(c); 145 markClientFinished(c);
144 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), 146 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(),
145 this); 147 this);
146 } 148 }
147 149
148 // Clear raw bytes as now we have the full decoded sheet text. 150 // Clear raw bytes as now we have the full decoded sheet text.
149 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) 151 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once)
150 // as SubresourceIntegrity checks require raw bytes. 152 // as SubresourceIntegrity checks require raw bytes.
151 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, 153 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too,
152 // but is safe as we should have a cached ResourceIntegrityDisposition. 154 // but is safe as we should have a cached ResourceIntegrityDisposition.
153 clearData(); 155 clearData();
156 setEncodedSizeMemoryUsage(0);
154 } 157 }
155 158
156 void CSSStyleSheetResource::destroyDecodedDataIfPossible() { 159 void CSSStyleSheetResource::destroyDecodedDataIfPossible() {
157 if (!m_parsedStyleSheetCache) 160 if (!m_parsedStyleSheetCache)
158 return; 161 return;
159 162
160 setParsedStyleSheetCache(nullptr); 163 setParsedStyleSheetCache(nullptr);
161 setDecodedSize(0);
162 } 164 }
163 165
164 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() { 166 void CSSStyleSheetResource::destroyDecodedDataForFailedRevalidation() {
165 m_decodedSheetText = String(); 167 setDecodedSheetText(String());
166 destroyDecodedDataIfPossible(); 168 destroyDecodedDataIfPossible();
167 } 169 }
168 170
169 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const { 171 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const {
170 if (errorOccurred()) 172 if (errorOccurred())
171 return false; 173 return false;
172 174
173 // This check exactly matches Firefox. Note that we grab the Content-Type 175 // This check exactly matches Firefox. Note that we grab the Content-Type
174 // header directly because we want to see what the value is BEFORE content 176 // header directly because we want to see what the value is BEFORE content
175 // sniffing. Firefox does this by setting a "type hint" on the channel. This 177 // sniffing. Firefox does this by setting a "type hint" on the channel. This
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 DCHECK(sheet); 212 DCHECK(sheet);
211 DCHECK(sheet->isCacheableForResource()); 213 DCHECK(sheet->isCacheableForResource());
212 214
213 if (!memoryCache()->contains(this)) { 215 if (!memoryCache()->contains(this)) {
214 // This stylesheet resource did conflict with another resource and was not 216 // This stylesheet resource did conflict with another resource and was not
215 // added to the cache. 217 // added to the cache.
216 setParsedStyleSheetCache(nullptr); 218 setParsedStyleSheetCache(nullptr);
217 return; 219 return;
218 } 220 }
219 setParsedStyleSheetCache(sheet); 221 setParsedStyleSheetCache(sheet);
220 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 222 }
223
224 void CSSStyleSheetResource::setDecodedSheetText(
225 const String& decodedSheetText) {
226 m_decodedSheetText = decodedSheetText;
227 updateDecodedSize();
228 }
229
230 void CSSStyleSheetResource::updateDecodedSize() {
231 size_t decodedSize = m_decodedSheetText.charactersSizeInBytes();
232 if (m_parsedStyleSheetCache)
233 decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes();
234 setDecodedSize(decodedSize);
221 } 235 }
222 236
223 } // namespace blink 237 } // 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