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

Side by Side Diff: content/browser/loader/resource_requester_info.cc

Issue 2497223002: Introduce a new ResourceRequesterInfo type for NavigationPreload. (Closed)
Patch Set: incorporated mmenke's comment Created 4 years 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/loader/resource_requester_info.h" 5 #include "content/browser/loader/resource_requester_info.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "content/browser/appcache/chrome_appcache_service.h" 9 #include "content/browser/appcache/chrome_appcache_service.h"
10 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 10 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_context.h"
14 #include "content/public/common/browser_side_navigation_policy.h"
13 #include "storage/browser/fileapi/file_system_context.h" 15 #include "storage/browser/fileapi/file_system_context.h"
14 16
15 namespace content { 17 namespace content {
16 18
19 namespace {
20
21 void GetContextsCallbackForNavigationPreload(
22 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
23 ResourceType resource_type,
24 ResourceContext** resource_context_out,
25 net::URLRequestContext** request_context_out) {
26 *resource_context_out = service_worker_context->resource_context();
27 *request_context_out = (*resource_context_out)->GetRequestContext();
28 }
29
30 } // namespace
31
17 ResourceRequesterInfo::ResourceRequesterInfo( 32 ResourceRequesterInfo::ResourceRequesterInfo(
18 RequesterType type, 33 RequesterType type,
19 int child_id, 34 int child_id,
20 ChromeAppCacheService* appcache_service, 35 ChromeAppCacheService* appcache_service,
21 ChromeBlobStorageContext* blob_storage_context, 36 ChromeBlobStorageContext* blob_storage_context,
22 storage::FileSystemContext* file_system_context, 37 storage::FileSystemContext* file_system_context,
23 ServiceWorkerContextWrapper* service_worker_context, 38 ServiceWorkerContextWrapper* service_worker_context,
24 const GetContextsCallback& get_contexts_callback) 39 const GetContextsCallback& get_contexts_callback)
25 : type_(type), 40 : type_(type),
26 child_id_(child_id), 41 child_id_(child_id),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 93
79 scoped_refptr<ResourceRequesterInfo> 94 scoped_refptr<ResourceRequesterInfo>
80 ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) { 95 ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) {
81 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo( 96 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo(
82 RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id, 97 RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id,
83 nullptr /* appcache_service */, nullptr /* blob_storage_context */, 98 nullptr /* appcache_service */, nullptr /* blob_storage_context */,
84 nullptr /* file_system_context */, nullptr /*service_worker_context */, 99 nullptr /* file_system_context */, nullptr /*service_worker_context */,
85 GetContextsCallback())); 100 GetContextsCallback()));
86 } 101 }
87 102
103 scoped_refptr<ResourceRequesterInfo>
104 ResourceRequesterInfo::CreateForNavigationPreload(
105 ResourceRequesterInfo* original_request_info) {
106 GetContextsCallback get_contexts_callback =
107 original_request_info->get_contexts_callback_;
108 if (IsBrowserSideNavigationEnabled()) {
109 DCHECK(original_request_info->IsBrowserSideNavigation());
110 DCHECK(!get_contexts_callback);
111 DCHECK(original_request_info->service_worker_context());
112 // The requester info for browser side navigation doesn't have the
113 // get_contexts_callback. So create the callback here which gets the
114 // ResourceContext and the URLRequestContext form ServiceWorkerContext.
115 get_contexts_callback =
116 base::Bind(&GetContextsCallbackForNavigationPreload,
117 scoped_refptr<ServiceWorkerContextWrapper>(
118 original_request_info->service_worker_context()));
119 } else {
120 DCHECK(original_request_info->IsRenderer());
121 DCHECK(get_contexts_callback);
122 }
123
124 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo(
125 RequesterType::NAVIGATION_PRELOAD, -1, nullptr /* appcache_service */,
126 nullptr /* blob_storage_context */, nullptr /* file_system_context */,
127 original_request_info->service_worker_context(), get_contexts_callback));
128 }
129
88 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698