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

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

Issue 2497223002: Introduce a new ResourceRequesterInfo type for NavigationPreload. (Closed)
Patch Set: incorporated yhirano'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 =
28 service_worker_context->resource_context()->GetRequestContext();
29 }
30
31 } // namespace
32
17 ResourceRequesterInfo::ResourceRequesterInfo( 33 ResourceRequesterInfo::ResourceRequesterInfo(
18 RequesterType type, 34 RequesterType type,
19 int child_id, 35 int child_id,
20 ChromeAppCacheService* appcache_service, 36 ChromeAppCacheService* appcache_service,
21 ChromeBlobStorageContext* blob_storage_context, 37 ChromeBlobStorageContext* blob_storage_context,
22 storage::FileSystemContext* file_system_context, 38 storage::FileSystemContext* file_system_context,
23 ServiceWorkerContextWrapper* service_worker_context, 39 ServiceWorkerContextWrapper* service_worker_context,
24 const GetContextsCallback& get_contexts_callback) 40 const GetContextsCallback& get_contexts_callback)
25 : type_(type), 41 : type_(type),
26 child_id_(child_id), 42 child_id_(child_id),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 94
79 scoped_refptr<ResourceRequesterInfo> 95 scoped_refptr<ResourceRequesterInfo>
80 ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) { 96 ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) {
81 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo( 97 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo(
82 RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id, 98 RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id,
83 nullptr /* appcache_service */, nullptr /* blob_storage_context */, 99 nullptr /* appcache_service */, nullptr /* blob_storage_context */,
84 nullptr /* file_system_context */, nullptr /*service_worker_context */, 100 nullptr /* file_system_context */, nullptr /*service_worker_context */,
85 GetContextsCallback())); 101 GetContextsCallback()));
86 } 102 }
87 103
104 scoped_refptr<ResourceRequesterInfo>
105 ResourceRequesterInfo::CreateForNavigationPreload(
106 ResourceRequesterInfo* original_request_info) {
107 GetContextsCallback get_contexts_callback =
108 original_request_info->get_contexts_callback_;
109 if (IsBrowserSideNavigationEnabled()) {
110 DCHECK(original_request_info->IsBrowserSideNavigation());
111 DCHECK(!get_contexts_callback);
112 DCHECK(original_request_info->service_worker_context());
113 // The requester info for browser side navigation doesn't have the
114 // get_contexts_callback. So create the callback here which gets the
115 // ResourceContext and the URLRequestContext form ServiceWorkerContext.
116 get_contexts_callback =
117 base::Bind(&GetContextsCallbackForNavigationPreload,
118 scoped_refptr<ServiceWorkerContextWrapper>(
119 original_request_info->service_worker_context()));
120 } else {
121 DCHECK(original_request_info->IsRenderer());
122 DCHECK(get_contexts_callback);
123 }
124
125 return scoped_refptr<ResourceRequesterInfo>(new ResourceRequesterInfo(
126 RequesterType::NAVIGATION_PRELOAD, -1, nullptr /* appcache_service */,
127 nullptr /* blob_storage_context */, nullptr /* file_system_context */,
128 original_request_info->service_worker_context(), get_contexts_callback));
129 }
130
88 } // namespace content 131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698