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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests Created 4 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/resource_requester_info.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "content/browser/appcache/chrome_appcache_service.h"
9 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
10 #include "content/browser/loader/resource_message_filter.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/public/browser/resource_context.h"
13 #include "storage/browser/fileapi/file_system_context.h"
14
15 namespace content {
16
17 ResourceRequesterInfo::ResourceRequesterInfo(
18 RequesterType type,
19 int child_id,
20 ChromeAppCacheService* appcache_service,
21 ChromeBlobStorageContext* blob_storage_context,
22 storage::FileSystemContext* file_system_context,
23 ServiceWorkerContextWrapper* service_worker_context,
24 const GetContextsCallback& get_contexts_callback)
25 : type_(type),
26 child_id_(child_id),
27 appcache_service_(appcache_service),
28 blob_storage_context_(blob_storage_context),
29 file_system_context_(file_system_context),
30 service_worker_context_(service_worker_context),
31 get_contexts_callback_(get_contexts_callback) {}
32
33 ResourceRequesterInfo::~ResourceRequesterInfo() {}
34
35 std::unique_ptr<ResourceRequesterInfo> ResourceRequesterInfo::clone() const {
36 std::unique_ptr<ResourceRequesterInfo> info =
37 base::WrapUnique(new ResourceRequesterInfo(
38 type_, child_id_, appcache_service_.get(),
39 blob_storage_context_.get(), file_system_context_.get(),
40 service_worker_context_.get(), get_contexts_callback_));
41 if (type_ == RequesterType::RENDERER)
42 info->set_filter(filter_);
43 return info;
44 }
45
46 void ResourceRequesterInfo::set_filter(
47 base::WeakPtr<ResourceMessageFilter> filter) {
48 DCHECK_CURRENTLY_ON(BrowserThread::IO);
49 DCHECK(type_ == RequesterType::RENDERER);
mmenke 2016/11/17 16:27:20 include base/logging.h
mmenke 2016/11/17 16:27:20 DCHECK_EQ
horo 2016/11/17 17:50:27 Done.
horo 2016/11/17 17:50:27 Done.
50 filter_ = filter;
51 }
52
53 void ResourceRequesterInfo::GetContexts(
54 ResourceType resource_type,
55 ResourceContext** resource_context,
56 net::URLRequestContext** request_context) const {
57 get_contexts_callback_.Run(resource_type, resource_context, request_context);
58 }
59
60 std::unique_ptr<ResourceRequesterInfo> ResourceRequesterInfo::CreateForRenderer(
61 int child_id,
62 ChromeAppCacheService* appcache_service,
63 ChromeBlobStorageContext* blob_storage_context,
64 storage::FileSystemContext* file_system_context,
65 ServiceWorkerContextWrapper* service_worker_context,
66 const GetContextsCallback& get_contexts_callback) {
67 return base::WrapUnique(new ResourceRequesterInfo(
68 RequesterType::RENDERER, child_id, appcache_service, blob_storage_context,
69 file_system_context, service_worker_context, get_contexts_callback));
70 }
71
72 std::unique_ptr<ResourceRequesterInfo>
73 ResourceRequesterInfo::CreateForRendererTesting(int child_id) {
74 return base::WrapUnique(new ResourceRequesterInfo(
75 RequesterType::RENDERER, child_id, nullptr /* appcache_service */,
76 nullptr /* blob_storage_context */, nullptr /* file_system_context */,
77 nullptr /*service_worker_context */, GetContextsCallback()));
78 }
79
80 std::unique_ptr<ResourceRequesterInfo>
81 ResourceRequesterInfo::CreateForBrowserSideNavigation(
82 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
83 return base::WrapUnique(new ResourceRequesterInfo(
84 RequesterType::BROWSER_SIDE_NAVIGATION, -1,
85 nullptr /* appcache_service */, nullptr /* blob_storage_context */,
86 nullptr /* file_system_context */, service_worker_context.get(),
87 GetContextsCallback()));
88 }
89
90 std::unique_ptr<ResourceRequesterInfo>
91 ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) {
92 return base::WrapUnique(new ResourceRequesterInfo(
93 RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id,
94 nullptr /* appcache_service */, nullptr /* blob_storage_context */,
95 nullptr /* file_system_context */, nullptr /*service_worker_context */,
96 GetContextsCallback()));
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698