Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 m_rule.clear(); | 235 m_rule.clear(); |
| 236 m_ruleValue.clear(); | 236 m_ruleValue.clear(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLR esourcePreloader* preloader) | 239 CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLR esourcePreloader* preloader) |
| 240 : m_resource(resource) | 240 : m_resource(resource) |
| 241 , m_preloader(preloader) | 241 , m_preloader(preloader) |
| 242 { | 242 { |
| 243 } | 243 } |
| 244 | 244 |
| 245 void CSSPreloaderResourceClient::stopObserving() | |
| 246 { | |
| 247 if (m_resource) { | |
| 248 m_resource->removeClient(this); | |
| 249 m_resource.clear(); | |
| 250 } | |
| 251 } | |
| 252 | |
| 253 CSSPreloaderResourceClient::~CSSPreloaderResourceClient() | |
| 254 { | |
| 255 stopObserving(); | |
|
Nate Chapin
2016/05/03 18:25:30
Alternately, you can have CSSPreloaderResourceClie
Charlie Harrison
2016/05/03 20:32:11
Very good point. Thanks for the suggestion.
| |
| 256 } | |
| 257 | |
| 245 void CSSPreloaderResourceClient::notifyFinished(Resource* resource) | 258 void CSSPreloaderResourceClient::notifyFinished(Resource* resource) |
| 246 { | 259 { |
| 247 resource->removeClient(this); | 260 stopObserving(); |
| 248 m_resource.clear(); | |
| 249 } | 261 } |
| 250 | 262 |
| 251 // Only attach for one appendData call, as that's where most imports will likely | 263 // Only attach for one appendData call, as that's where most imports will likely |
| 252 // be (according to spec). | 264 // be (according to spec). |
| 253 void CSSPreloaderResourceClient::didAppendFirstData(const CSSStyleSheetResource* resource) | 265 void CSSPreloaderResourceClient::didAppendFirstData(const CSSStyleSheetResource* resource) |
| 254 { | 266 { |
| 255 const String& chunk = resource->decodedText(); | 267 const String& chunk = resource->decodedText(); |
| 256 if (!chunk.isNull() && m_preloader) { | 268 if (!chunk.isNull() && m_preloader) { |
| 257 CSSPreloadScanner cssPreloadScanner; | 269 CSSPreloadScanner cssPreloadScanner; |
| 258 PreloadRequestStream preloads; | 270 PreloadRequestStream preloads; |
| 259 // Passing an empty SegmentedString here results in PreloadRequests | 271 // Passing an empty SegmentedString here results in PreloadRequests |
| 260 // with no file/line information. | 272 // with no file/line information. |
| 261 // TODO(csharrison): If this becomes an issue the CSSPreloadScanner | 273 // TODO(csharrison): If this becomes an issue the CSSPreloadScanner |
| 262 // may be augmented to take care of this case without performing an | 274 // may be augmented to take care of this case without performing an |
| 263 // additional copy. | 275 // additional copy. |
| 264 cssPreloadScanner.scan(chunk, SegmentedString(), preloads, resource->res ponse().url()); | 276 cssPreloadScanner.scan(chunk, SegmentedString(), preloads, resource->res ponse().url()); |
| 265 int currentPreloadCount = m_preloader->countPreloads(); | 277 int currentPreloadCount = m_preloader->countPreloads(); |
| 266 m_preloader->takeAndPreload(preloads); | 278 m_preloader->takeAndPreload(preloads); |
| 267 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssImportHistogram, ("PreloadS canner.ExternalCSS.PreloadCount", 1, 100, 50)); | 279 DEFINE_STATIC_LOCAL(CustomCountHistogram, cssImportHistogram, ("PreloadS canner.ExternalCSS.PreloadCount", 1, 100, 50)); |
| 268 cssImportHistogram.count(m_preloader->countPreloads() - currentPreloadCo unt); | 280 cssImportHistogram.count(m_preloader->countPreloads() - currentPreloadCo unt); |
| 269 } | 281 } |
| 270 m_resource->removeClient(this); | 282 stopObserving(); |
| 271 m_resource.clear(); | |
| 272 } | 283 } |
| 273 | 284 |
| 274 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |