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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix URLLoaderFactoryImplTest/URLLoaderFactoryImplTest.GetFailedResponse2 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
(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 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/common/content_export.h"
14 #include "content/public/common/resource_type.h"
15
16 namespace net {
17 class URLRequestContext;
18 } // namespace net
19
20 namespace storage {
21 class FileSystemContext;
22 } // namespace storage
23
24 namespace content {
25 class ChromeAppCacheService;
26 class ChromeBlobStorageContext;
27 class ResourceContext;
28 class ResourceMessageFilter;
29 class ServiceWorkerContextWrapper;
30
31 // This class represents the type of resource requester.
32 // Currently there are three types:
33 // - Requesters that request resources from renderer processes.
34 // - Requesters that request resources within the browser process for browser
35 // side navigation (aka PlzNavigate).
36 // - Requesters that request resources for download or page save.
37 class CONTENT_EXPORT ResourceRequesterInfo
38 : public base::RefCountedThreadSafe<ResourceRequesterInfo> {
39 public:
40 typedef base::Callback<void(ResourceType resource_type,
41 ResourceContext**,
42 net::URLRequestContext**)>
43 GetContextsCallback;
44
45 // Creates a ResourceRequesterInfo for a requester that requests resources
46 // from the renderer process.
47 static scoped_refptr<ResourceRequesterInfo> CreateForRenderer(
48 int child_id,
49 ChromeAppCacheService* appcache_service,
50 ChromeBlobStorageContext* blob_storage_context,
51 storage::FileSystemContext* file_system_context,
52 ServiceWorkerContextWrapper* service_worker_context,
53 const GetContextsCallback& get_contexts_callback);
54
55 // Creates a ResourceRequesterInfo for a requester that requests resources
56 // from the renderer process for testing.
57 static scoped_refptr<ResourceRequesterInfo> CreateForRendererTesting(
58 int child_id);
59
60 // Creates a ResourceRequesterInfo for a requester that requests resources
61 // within the browser process for browser side navigation (aka PlzNavigate).
62 static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation(
63 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
64
65 // Creates a ResourceRequesterInfo for a requester that requests resources for
66 // download or page save.
67 static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave(
68 int child_id);
69
70 bool IsRenderer() const { return type_ == RequesterType::RENDERER; }
71 bool IsBrowserSideNavigation() const {
72 return type_ == RequesterType::BROWSER_SIDE_NAVIGATION;
73 }
74
75 // Returns the renderer process ID associated with the requester. Returns -1
76 // for browser side navigation requester. Even if the ResourceMessageFilter
77 // has been destroyed, this method of renderer type requester info returns the
78 // valid process ID which was assigned to the renderer process of the filter.
79 int child_id() const { return child_id_; }
80
81 // Sets the ResourceMessageFilter of the renderer type requester info.
82 void set_filter(base::WeakPtr<ResourceMessageFilter> filter);
83
84 // Returns the filter for sending IPC messages to the renderer process. This
85 // may return null if the process exited. This method is available only for
86 // renderer type requester.
87 ResourceMessageFilter* filter() { return filter_.get(); }
88
89 // Returns the ResourceContext and URLRequestContext associated to the
90 // requester. Currently this method is available only for renderer type
91 // requester.
92 void GetContexts(ResourceType resource_type,
93 ResourceContext** resource_context,
94 net::URLRequestContext** request_context) const;
95
96 // Returns the ChromeAppCacheService associated with the requester. Currently
97 // this method is available only for renderer type requester.
98 ChromeAppCacheService* appcache_service() { return appcache_service_.get(); }
99
100 // Returns the ChromeBlobStorageContext associated with the requester.
101 // Currently this method is available only for renderer type requester.
102 ChromeBlobStorageContext* blob_storage_context() {
103 return blob_storage_context_.get();
104 }
105
106 // Returns the FileSystemContext associated with the requester. Currently this
107 // method is available only for renderer type requester.
108 storage::FileSystemContext* file_system_context() {
109 return file_system_context_.get();
110 }
111
112 // Returns the ServiceWorkerContext associated with the requester. Currently
113 // this method is available for renderer type requester and browser side
114 // navigation type requester.
115 ServiceWorkerContextWrapper* service_worker_context() {
116 return service_worker_context_.get();
117 }
118
119 private:
120 friend class base::RefCountedThreadSafe<ResourceRequesterInfo>;
121
122 enum class RequesterType {
123 RENDERER,
124 BROWSER_SIDE_NAVIGATION,
125 DOWNLOAD_OR_PAGE_SAVE
126 };
127
128 ResourceRequesterInfo(RequesterType type,
129 int child_id,
130 ChromeAppCacheService* appcache_service,
131 ChromeBlobStorageContext* blob_storage_context,
132 storage::FileSystemContext* file_system_context,
133 ServiceWorkerContextWrapper* service_worker_context,
134 const GetContextsCallback& get_contexts_callback);
135 ~ResourceRequesterInfo();
136
137 const RequesterType type_;
138 // The filter might be deleted if the process exited.
139 base::WeakPtr<ResourceMessageFilter> filter_;
140 const int child_id_;
141 const scoped_refptr<ChromeAppCacheService> appcache_service_;
142 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
143 const scoped_refptr<storage::FileSystemContext> file_system_context_;
144 const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
145 const GetContextsCallback get_contexts_callback_;
146
147 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo);
148 };
149
150 } // namespace content
151
152 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
OLDNEW
« no previous file with comments | « content/browser/loader/resource_request_info_impl.cc ('k') | content/browser/loader/resource_requester_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698