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

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

Issue 1807323002: [WeakMemoryCache 1a] Make Reference from Inspector to Resource weak, remove removedFromMemoryCache() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove some comments Created 4 years, 7 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ est, const ResourceLoaderOptions& options, const String& charset) 52 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ est, const ResourceLoaderOptions& options, const String& charset)
53 : StyleSheetResource(resourceRequest, CSSStyleSheet, options, "text/css", ch arset) 53 : StyleSheetResource(resourceRequest, CSSStyleSheet, options, "text/css", ch arset)
54 { 54 {
55 } 55 }
56 56
57 CSSStyleSheetResource::~CSSStyleSheetResource() 57 CSSStyleSheetResource::~CSSStyleSheetResource()
58 { 58 {
59 } 59 }
60 60
61 void CSSStyleSheetResource::removedFromMemoryCache() 61 void CSSStyleSheetResource::willDestroyResourceInternal()
62 {
63 setParsedStyleSheetCache(nullptr);
64 }
65
66 void CSSStyleSheetResource::setParsedStyleSheetCache(StyleSheetContents* newShee t)
62 { 67 {
63 if (m_parsedStyleSheetCache) 68 if (m_parsedStyleSheetCache)
64 m_parsedStyleSheetCache->removedFromMemoryCache(); 69 m_parsedStyleSheetCache->setReferencedFromResource(false);
65 m_parsedStyleSheetCache.clear(); 70 m_parsedStyleSheetCache = newSheet;
66 Resource::removedFromMemoryCache(); 71 if (m_parsedStyleSheetCache)
72 m_parsedStyleSheetCache->setReferencedFromResource(true);
67 } 73 }
68 74
69 DEFINE_TRACE(CSSStyleSheetResource) 75 DEFINE_TRACE(CSSStyleSheetResource)
70 { 76 {
71 visitor->trace(m_parsedStyleSheetCache); 77 visitor->trace(m_parsedStyleSheetCache);
72 StyleSheetResource::trace(visitor); 78 StyleSheetResource::trace(visitor);
73 } 79 }
74 80
75 void CSSStyleSheetResource::didAddClient(ResourceClient* c) 81 void CSSStyleSheetResource::didAddClient(ResourceClient* c)
76 { 82 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 bool CSSStyleSheetResource::isSafeToUnlock() const 120 bool CSSStyleSheetResource::isSafeToUnlock() const
115 { 121 {
116 return m_data->hasOneRef(); 122 return m_data->hasOneRef();
117 } 123 }
118 124
119 void CSSStyleSheetResource::destroyDecodedDataIfPossible() 125 void CSSStyleSheetResource::destroyDecodedDataIfPossible()
120 { 126 {
121 if (!m_parsedStyleSheetCache) 127 if (!m_parsedStyleSheetCache)
122 return; 128 return;
123 129
124 m_parsedStyleSheetCache->removedFromMemoryCache(); 130 setParsedStyleSheetCache(nullptr);
125 m_parsedStyleSheetCache.clear();
126
127 setDecodedSize(0); 131 setDecodedSize(0);
128 } 132 }
129 133
130 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const 134 bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const
131 { 135 {
132 if (errorOccurred()) 136 if (errorOccurred())
133 return false; 137 return false;
134 138
135 // This check exactly matches Firefox. Note that we grab the Content-Type 139 // This check exactly matches Firefox. Note that we grab the Content-Type
136 // header directly because we want to see what the value is BEFORE content 140 // header directly because we want to see what the value is BEFORE content
137 // sniffing. Firefox does this by setting a "type hint" on the channel. 141 // sniffing. Firefox does this by setting a "type hint" on the channel.
138 // This implementation should be observationally equivalent. 142 // This implementation should be observationally equivalent.
139 // 143 //
140 // This code defaults to allowing the stylesheet for non-HTTP protocols so 144 // This code defaults to allowing the stylesheet for non-HTTP protocols so
141 // folks can use standards mode for local HTML documents. 145 // folks can use standards mode for local HTML documents.
142 if (mimeTypeCheck == MIMETypeCheck::Lax) 146 if (mimeTypeCheck == MIMETypeCheck::Lax)
143 return true; 147 return true;
144 AtomicString contentType = httpContentType(); 148 AtomicString contentType = httpContentType();
145 return contentType.isEmpty() || equalIgnoringCase(contentType, "text/css") | | equalIgnoringCase(contentType, "application/x-unknown-content-type"); 149 return contentType.isEmpty() || equalIgnoringCase(contentType, "text/css") | | equalIgnoringCase(contentType, "application/x-unknown-content-type");
146 } 150 }
147 151
148 StyleSheetContents* CSSStyleSheetResource::restoreParsedStyleSheet(const CSSPars erContext& context) 152 StyleSheetContents* CSSStyleSheetResource::restoreParsedStyleSheet(const CSSPars erContext& context)
149 { 153 {
150 if (!m_parsedStyleSheetCache) 154 if (!m_parsedStyleSheetCache)
151 return nullptr; 155 return nullptr;
152 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { 156 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
153 m_parsedStyleSheetCache->removedFromMemoryCache(); 157 setParsedStyleSheetCache(nullptr);
154 m_parsedStyleSheetCache.clear();
155 return nullptr; 158 return nullptr;
156 } 159 }
157 160
158 ASSERT(m_parsedStyleSheetCache->isCacheable()); 161 ASSERT(m_parsedStyleSheetCache->isCacheable());
159 ASSERT(m_parsedStyleSheetCache->isInMemoryCache()); 162 ASSERT(m_parsedStyleSheetCache->isReferencedFromResource());
160 163
161 // Contexts must be identical so we know we would get the same exact result if we parsed again. 164 // Contexts must be identical so we know we would get the same exact result if we parsed again.
162 if (m_parsedStyleSheetCache->parserContext() != context) 165 if (m_parsedStyleSheetCache->parserContext() != context)
163 return nullptr; 166 return nullptr;
164 167
165 didAccessDecodedData(); 168 didAccessDecodedData();
166 169
167 return m_parsedStyleSheetCache; 170 return m_parsedStyleSheetCache;
168 } 171 }
169 172
170 void CSSStyleSheetResource::saveParsedStyleSheet(StyleSheetContents* sheet) 173 void CSSStyleSheetResource::saveParsedStyleSheet(StyleSheetContents* sheet)
171 { 174 {
172 ASSERT(sheet && sheet->isCacheable()); 175 ASSERT(sheet && sheet->isCacheable());
173 176
174 if (m_parsedStyleSheetCache)
175 m_parsedStyleSheetCache->removedFromMemoryCache();
176
177 if (!memoryCache()->contains(this)) { 177 if (!memoryCache()->contains(this)) {
178 // This stylesheet resource did conflict with another resource and was 178 // This stylesheet resource did conflict with another resource and was
179 // not added to the cache. 179 // not added to the cache.
180 m_parsedStyleSheetCache = nullptr; 180 setParsedStyleSheetCache(nullptr);
181 return; 181 return;
182 } 182 }
183 m_parsedStyleSheetCache = sheet; 183 setParsedStyleSheetCache(sheet);
184 m_parsedStyleSheetCache->addedToMemoryCache();
185
186 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 184 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
187 } 185 }
188 186
189 } // namespace blink 187 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | third_party/WebKit/Source/core/fetch/MemoryCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698