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

Side by Side Diff: Source/core/html/parser/HTMLResourcePreloader.cpp

Issue 1170503003: Remove resource type-specific fetching logic from ResourceFetcher (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All Rights Reserved. 2 * Copyright (C) 2013 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/html/parser/HTMLResourcePreloader.h" 27 #include "core/html/parser/HTMLResourcePreloader.h"
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/fetch/CSSStyleSheetResource.h"
30 #include "core/fetch/FetchInitiatorInfo.h" 31 #include "core/fetch/FetchInitiatorInfo.h"
32 #include "core/fetch/ImageResource.h"
31 #include "core/fetch/ResourceFetcher.h" 33 #include "core/fetch/ResourceFetcher.h"
34 #include "core/fetch/ScriptResource.h"
32 #include "platform/network/NetworkHints.h" 35 #include "platform/network/NetworkHints.h"
33 #include "public/platform/Platform.h" 36 #include "public/platform/Platform.h"
34 37
35 namespace blink { 38 namespace blink {
36 39
37 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document) 40 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document)
38 : m_document(document) 41 : m_document(document)
39 { 42 {
40 } 43 }
41 44
(...skipping 23 matching lines...) Expand all
65 } 68 }
66 preconnect(host, crossOrigin); 69 preconnect(host, crossOrigin);
67 } 70 }
68 71
69 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) 72 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload)
70 { 73 {
71 if (preload->isPreconnect()) { 74 if (preload->isPreconnect()) {
72 preconnectHost(preload.get()); 75 preconnectHost(preload.get());
73 return; 76 return;
74 } 77 }
78
Yoav Weiss 2015/06/08 06:44:18 Can't say that I like adding all that resource typ
Nate Chapin 2015/06/08 19:01:22 For this patch by itself, yes. However, for the pr
79 // Ensure main resources aren't preloaded, since the cache can't actually re use the preload.
80 if (preload->resourceType() == Resource::MainResource)
Yoav Weiss 2015/06/08 06:44:17 Is there a scenario where we preload a main resour
Nate Chapin 2015/06/08 19:01:22 I think there was hope a year or two ago that we w
81 return;
82 ASSERT(preload->resourceType() == Resource::Script || preload->resourceType( ) == Resource::CSSStyleSheet || preload->resourceType() == Resource::Image);
83
75 FetchRequest request = preload->resourceRequest(m_document); 84 FetchRequest request = preload->resourceRequest(m_document);
85 if (preload->resourceType() == Resource::Script || preload->resourceType() = = Resource::CSSStyleSheet)
86 request.setCharset(preload->charset().isEmpty() ? m_document->charset(). string() : preload->charset());
87 request.setForPreload(true);
76 Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_ cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime())), 0, 2000, 20); 88 Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_ cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime())), 0, 2000, 20);
77 m_document->fetcher()->preload(preload->resourceType(), request, preload->ch arset()); 89
90 ResourcePtr<Resource> resource;
91 if (preload->resourceType() == Resource::Image)
92 resource = ImageResource::fetch(request, m_document->fetcher());
93 else if (preload->resourceType() == Resource::Script)
94 resource = ScriptResource::fetch(request, m_document->fetcher());
95 else
96 resource = CSSStyleSheetResource::fetch(request, m_document->fetcher());
97
98 if (resource)
99 m_document->fetcher()->preloadStarted(resource.get());
78 } 100 }
79 101
80 } // namespace blink 102 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/imports/HTMLImportsController.cpp ('k') | Source/core/inspector/InspectorResourceContentLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698