Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| diff --git a/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp b/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| index 15a5aaf1d36714052c7ccaf8db2548737a75454c..c233d7289518da4bc34ae10d4bf44f4fbcab7f66 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| +++ b/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| @@ -27,8 +27,11 @@ |
| #include "core/html/parser/CSSPreloadScanner.h" |
| +#include "core/fetch/CSSStyleSheetResource.h" |
| #include "core/fetch/FetchInitiatorTypeNames.h" |
| #include "core/html/parser/HTMLParserIdioms.h" |
| +#include "core/html/parser/HTMLResourcePreloader.h" |
| +#include "platform/Histogram.h" |
| #include "platform/text/SegmentedString.h" |
| namespace blink { |
| @@ -233,4 +236,33 @@ void CSSPreloadScanner::emitRule(const SegmentedString& source) |
| m_ruleValue.clear(); |
| } |
| +CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLResourcePreloader* preloader) |
| + : m_resource(resource) |
| + , m_preloader(preloader) |
| +{ |
| +} |
| + |
| +void CSSPreloaderResourceClient::notifyFinished(Resource* resource) |
| +{ |
| + resource->removeClient(this); |
| +} |
| + |
| +// Only attach for one appendData call, as that's where most imports will likely |
| +// be (according to spec). |
| +void CSSPreloaderResourceClient::didAppendFirstData(const CSSStyleSheetResource* resource) |
| +{ |
| + const String& chunk = resource->decodedText(); |
| + if (!chunk.isNull() && m_preloader) { |
| + CSSPreloadScanner cssPreloadScanner; |
| + PreloadRequestStream preloads; |
| + // TODO(csharrison): Should SegmentedString be populated? |
|
kinuko
2016/04/29 03:30:08
nit: make this a TODO-like comment with a bit more
Charlie Harrison
2016/04/29 13:21:38
Done.
|
| + cssPreloadScanner.scan(chunk, SegmentedString(), preloads, resource->response().url()); |
| + int currentPreloadCount = m_preloader->countPreloads(); |
| + m_preloader->takeAndPreload(preloads); |
| + DEFINE_STATIC_LOCAL(CustomCountHistogram, cssImportHistogram, ("PreloadScanner.ExternalCSS.PreloadCount", 1, 100, 50)); |
| + cssImportHistogram.count(m_preloader->countPreloads() - currentPreloadCount); |
| + } |
| + m_resource->removeClient(this); |
|
kinuko
2016/04/29 03:30:08
nit: should we also clear m_resource here (and in
Charlie Harrison
2016/04/29 13:21:38
Done.
|
| +} |
| + |
| } // namespace blink |