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

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

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 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ 6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 11 matching lines...) Expand all
22 } // namespace storage 22 } // namespace storage
23 23
24 namespace content { 24 namespace content {
25 class ChromeAppCacheService; 25 class ChromeAppCacheService;
26 class ChromeBlobStorageContext; 26 class ChromeBlobStorageContext;
27 class ResourceContext; 27 class ResourceContext;
28 class ResourceMessageFilter; 28 class ResourceMessageFilter;
29 class ServiceWorkerContextWrapper; 29 class ServiceWorkerContextWrapper;
30 30
31 // This class represents the type of resource requester. 31 // This class represents the type of resource requester.
32 // Currently there are three types: 32 // Currently there are four types:
33 // - Requesters that request resources from renderer processes. 33 // - Requesters that request resources from renderer processes.
34 // - Requesters that request resources within the browser process for browser 34 // - Requesters that request resources within the browser process for browser
35 // side navigation (aka PlzNavigate). 35 // side navigation (aka PlzNavigate).
36 // - Requesters that request resources for download or page save. 36 // - Requesters that request resources for download or page save.
37 // - Requesters that request service worker navigation preload requests.
37 class CONTENT_EXPORT ResourceRequesterInfo 38 class CONTENT_EXPORT ResourceRequesterInfo
38 : public base::RefCountedThreadSafe<ResourceRequesterInfo> { 39 : public base::RefCountedThreadSafe<ResourceRequesterInfo> {
39 public: 40 public:
40 typedef base::Callback<void(ResourceType resource_type, 41 typedef base::Callback<void(ResourceType resource_type,
41 ResourceContext**, 42 ResourceContext**,
42 net::URLRequestContext**)> 43 net::URLRequestContext**)>
43 GetContextsCallback; 44 GetContextsCallback;
44 45
45 // Creates a ResourceRequesterInfo for a requester that requests resources 46 // Creates a ResourceRequesterInfo for a requester that requests resources
46 // from the renderer process. 47 // from the renderer process.
(...skipping 13 matching lines...) Expand all
60 // Creates a ResourceRequesterInfo for a requester that requests resources 61 // Creates a ResourceRequesterInfo for a requester that requests resources
61 // within the browser process for browser side navigation (aka PlzNavigate). 62 // within the browser process for browser side navigation (aka PlzNavigate).
62 static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation( 63 static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation(
63 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); 64 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
64 65
65 // Creates a ResourceRequesterInfo for a requester that requests resources for 66 // Creates a ResourceRequesterInfo for a requester that requests resources for
66 // download or page save. 67 // download or page save.
67 static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave( 68 static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave(
68 int child_id); 69 int child_id);
69 70
71 // Creates a ResourceRequesterInfo for a service worker navigation preload
72 // request. When PlzNavigate is enabled, |original_request_info| must be
73 // browser side navigation type. Otherwise it must be renderer type.
74 static scoped_refptr<ResourceRequesterInfo> CreateForNavigationPreload(
75 ResourceRequesterInfo* original_request_info);
76
70 bool IsRenderer() const { return type_ == RequesterType::RENDERER; } 77 bool IsRenderer() const { return type_ == RequesterType::RENDERER; }
71 bool IsBrowserSideNavigation() const { 78 bool IsBrowserSideNavigation() const {
72 return type_ == RequesterType::BROWSER_SIDE_NAVIGATION; 79 return type_ == RequesterType::BROWSER_SIDE_NAVIGATION;
73 } 80 }
81 bool IsNavigationPreload() const {
82 return type_ == RequesterType::NAVIGATION_PRELOAD;
83 }
74 84
75 // Returns the renderer process ID associated with the requester. Returns -1 85 // Returns the renderer process ID associated with the requester. Returns -1
76 // for browser side navigation requester. Even if the ResourceMessageFilter 86 // for browser side navigation requester. Even if the ResourceMessageFilter
77 // has been destroyed, this method of renderer type requester info returns the 87 // 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. 88 // valid process ID which was assigned to the renderer process of the filter.
79 int child_id() const { return child_id_; } 89 int child_id() const { return child_id_; }
80 90
81 // Sets the ResourceMessageFilter of the renderer type requester info. 91 // Sets the ResourceMessageFilter of the renderer type requester info.
82 void set_filter(base::WeakPtr<ResourceMessageFilter> filter); 92 void set_filter(base::WeakPtr<ResourceMessageFilter> filter);
83 93
84 // Returns the filter for sending IPC messages to the renderer process. This 94 // 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 95 // may return null if the process exited. This method is available only for
86 // renderer type requester. 96 // renderer type requester.
87 ResourceMessageFilter* filter() { return filter_.get(); } 97 ResourceMessageFilter* filter() { return filter_.get(); }
88 98
89 // Returns the ResourceContext and URLRequestContext associated to the 99 // Returns the ResourceContext and URLRequestContext associated to the
90 // requester. Currently this method is available only for renderer type 100 // requester. Currently this method is available only for renderer type
91 // requester. 101 // requester and service worker navigation preload type.
92 void GetContexts(ResourceType resource_type, 102 void GetContexts(ResourceType resource_type,
93 ResourceContext** resource_context, 103 ResourceContext** resource_context,
94 net::URLRequestContext** request_context) const; 104 net::URLRequestContext** request_context) const;
95 105
96 // Returns the ChromeAppCacheService associated with the requester. Currently 106 // Returns the ChromeAppCacheService associated with the requester. Currently
97 // this method is available only for renderer type requester. 107 // this method is available only for renderer type requester.
98 ChromeAppCacheService* appcache_service() { return appcache_service_.get(); } 108 ChromeAppCacheService* appcache_service() { return appcache_service_.get(); }
99 109
100 // Returns the ChromeBlobStorageContext associated with the requester. 110 // Returns the ChromeBlobStorageContext associated with the requester.
101 // Currently this method is available only for renderer type requester. 111 // Currently this method is available only for renderer type requester.
102 ChromeBlobStorageContext* blob_storage_context() { 112 ChromeBlobStorageContext* blob_storage_context() {
103 return blob_storage_context_.get(); 113 return blob_storage_context_.get();
104 } 114 }
105 115
106 // Returns the FileSystemContext associated with the requester. Currently this 116 // Returns the FileSystemContext associated with the requester. Currently this
107 // method is available only for renderer type requester. 117 // method is available only for renderer type requester.
108 storage::FileSystemContext* file_system_context() { 118 storage::FileSystemContext* file_system_context() {
109 return file_system_context_.get(); 119 return file_system_context_.get();
110 } 120 }
111 121
112 // Returns the ServiceWorkerContext associated with the requester. Currently 122 // Returns the ServiceWorkerContext associated with the requester. Currently
113 // this method is available for renderer type requester and browser side 123 // this method is available for renderer type requester, browser side
114 // navigation type requester. 124 // navigation type requester and service worker navigation preload type
125 // requester.
115 ServiceWorkerContextWrapper* service_worker_context() { 126 ServiceWorkerContextWrapper* service_worker_context() {
116 return service_worker_context_.get(); 127 return service_worker_context_.get();
117 } 128 }
118 129
119 private: 130 private:
120 friend class base::RefCountedThreadSafe<ResourceRequesterInfo>; 131 friend class base::RefCountedThreadSafe<ResourceRequesterInfo>;
121 132
122 enum class RequesterType { 133 enum class RequesterType {
123 RENDERER, 134 RENDERER,
124 BROWSER_SIDE_NAVIGATION, 135 BROWSER_SIDE_NAVIGATION,
125 DOWNLOAD_OR_PAGE_SAVE 136 DOWNLOAD_OR_PAGE_SAVE,
137 NAVIGATION_PRELOAD
126 }; 138 };
127 139
128 ResourceRequesterInfo(RequesterType type, 140 ResourceRequesterInfo(RequesterType type,
129 int child_id, 141 int child_id,
130 ChromeAppCacheService* appcache_service, 142 ChromeAppCacheService* appcache_service,
131 ChromeBlobStorageContext* blob_storage_context, 143 ChromeBlobStorageContext* blob_storage_context,
132 storage::FileSystemContext* file_system_context, 144 storage::FileSystemContext* file_system_context,
133 ServiceWorkerContextWrapper* service_worker_context, 145 ServiceWorkerContextWrapper* service_worker_context,
134 const GetContextsCallback& get_contexts_callback); 146 const GetContextsCallback& get_contexts_callback);
135 ~ResourceRequesterInfo(); 147 ~ResourceRequesterInfo();
136 148
137 const RequesterType type_; 149 const RequesterType type_;
138 // The filter might be deleted if the process exited. 150 // The filter might be deleted if the process exited.
139 base::WeakPtr<ResourceMessageFilter> filter_; 151 base::WeakPtr<ResourceMessageFilter> filter_;
140 const int child_id_; 152 const int child_id_;
141 const scoped_refptr<ChromeAppCacheService> appcache_service_; 153 const scoped_refptr<ChromeAppCacheService> appcache_service_;
142 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; 154 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
143 const scoped_refptr<storage::FileSystemContext> file_system_context_; 155 const scoped_refptr<storage::FileSystemContext> file_system_context_;
144 const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 156 const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
145 const GetContextsCallback get_contexts_callback_; 157 const GetContextsCallback get_contexts_callback_;
146 158
147 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo); 159 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo);
148 }; 160 };
149 161
150 } // namespace content 162 } // namespace content
151 163
152 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ 164 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698