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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp

Issue 2452413002: Make CSSPreloaderResourceClient hold weak references to its resource (Closed)
Patch Set: 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/html/parser/CSSPreloadScanner.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) 2008, 2010 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. 4 * Copyright (C) 2010 Google Inc. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 m_rule.clear(); 248 m_rule.clear();
249 m_ruleValue.clear(); 249 m_ruleValue.clear();
250 } 250 }
251 251
252 CSSPreloaderResourceClient::CSSPreloaderResourceClient( 252 CSSPreloaderResourceClient::CSSPreloaderResourceClient(
253 Resource* resource, 253 Resource* resource,
254 HTMLResourcePreloader* preloader) 254 HTMLResourcePreloader* preloader)
255 : m_policy(preloader->document()->settings()->cssExternalScannerPreload() 255 : m_policy(preloader->document()->settings()->cssExternalScannerPreload()
256 ? ScanAndPreload 256 ? ScanAndPreload
257 : ScanOnly), 257 : ScanOnly),
258 m_preloader(preloader) { 258 m_preloader(preloader),
259 DCHECK(resource->getType() == Resource::Type::CSSStyleSheet); 259 m_resource(toCSSStyleSheetResource(resource)) {
Yoav Weiss 2016/10/27 21:59:49 Can you bring back the DCHECK?
Charlie Harrison 2016/10/27 22:34:01 AFAICT the to<Resource> type casts do this already
260 setResource(toCSSStyleSheetResource(resource), 260 m_resource->addClient(this);
261 Resource::DontMarkAsReferenced);
262 } 261 }
263 262
264 CSSPreloaderResourceClient::~CSSPreloaderResourceClient() {} 263 CSSPreloaderResourceClient::~CSSPreloaderResourceClient() {}
265 264
266 void CSSPreloaderResourceClient::setCSSStyleSheet( 265 void CSSPreloaderResourceClient::setCSSStyleSheet(
267 const String& href, 266 const String& href,
268 const KURL& baseURL, 267 const KURL& baseURL,
269 const String& charset, 268 const String& charset,
270 const CSSStyleSheetResource*) { 269 const CSSStyleSheetResource*) {
271 clearResource(); 270 clearResource();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 int currentPreloadCount = m_preloader->countPreloads(); 312 int currentPreloadCount = m_preloader->countPreloads();
314 m_preloader->takeAndPreload(preloads); 313 m_preloader->takeAndPreload(preloads);
315 DEFINE_STATIC_LOCAL( 314 DEFINE_STATIC_LOCAL(
316 CustomCountHistogram, cssImportHistogram, 315 CustomCountHistogram, cssImportHistogram,
317 ("PreloadScanner.ExternalCSS.PreloadCount", 1, 100, 50)); 316 ("PreloadScanner.ExternalCSS.PreloadCount", 1, 100, 50));
318 cssImportHistogram.count(m_preloader->countPreloads() - 317 cssImportHistogram.count(m_preloader->countPreloads() -
319 currentPreloadCount); 318 currentPreloadCount);
320 } 319 }
321 } 320 }
322 321
322 void CSSPreloaderResourceClient::clearResource() {
323 if (m_resource)
324 m_resource->removeClient(this);
325 m_resource.clear();
326 }
327
323 DEFINE_TRACE(CSSPreloaderResourceClient) { 328 DEFINE_TRACE(CSSPreloaderResourceClient) {
324 visitor->trace(m_preloader); 329 visitor->trace(m_preloader);
325 ResourceOwner<CSSStyleSheetResource>::trace(visitor); 330 visitor->trace(m_resource);
331 StyleSheetResourceClient::trace(visitor);
326 } 332 }
327 333
328 } // namespace blink 334 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698