OLD | NEW |
---|---|
(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 BrowserMessageFilter; | |
26 class ChromeAppCacheService; | |
27 class ChromeBlobStorageContext; | |
28 class ResourceContext; | |
29 class ResourceMessageFilter; | |
30 class ServiceWorkerContextWrapper; | |
31 | |
32 // This class represents the type of resource request. | |
kinuko
2016/11/21 13:36:26
resource request -> resource requester?
Would be
horo
2016/11/21 14:57:59
Done.
| |
33 // Currently there are three types: | |
34 // - Resource request from renderer processes. | |
35 // - Resource request for browser side navigation. (PlzNavigate). | |
36 // - Download request or page save request. | |
kinuko
2016/11/21 13:36:26
- Requesters that request resource from renderer p
horo
2016/11/21 14:57:59
Done.
| |
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 renderer process initiated request. | |
kinuko
2016/11/21 13:36:26
ditto for per-request vs per-requester (here and b
horo
2016/11/21 14:57:59
Done.
| |
46 static scoped_refptr<ResourceRequesterInfo> CreateForRenderer( | |
47 int child_id, | |
48 ChromeAppCacheService* appcache_service, | |
49 ChromeBlobStorageContext* blob_storage_context, | |
50 storage::FileSystemContext* file_system_context, | |
51 ServiceWorkerContextWrapper* service_worker_context, | |
52 const GetContextsCallback& get_contexts_callback); | |
53 | |
54 // Creates a ResourceRequesterInfo for a renderer process initiated request | |
55 // for testing. | |
56 static scoped_refptr<ResourceRequesterInfo> CreateForRendererTesting( | |
57 int child_id); | |
58 | |
59 // Creates a ResourceRequesterInfo for a browser side navigation request which | |
60 // is initiated by the browser process. | |
61 static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation( | |
62 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | |
63 | |
64 // Creates a ResourceRequesterInfo for a download or page save request. | |
65 static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave( | |
66 int child_id); | |
67 | |
68 bool IsRenderer() const { return type_ == RequesterType::RENDERER; } | |
69 bool IsBrowserSideNavigation() const { | |
70 return type_ == RequesterType::BROWSER_SIDE_NAVIGATION; | |
71 } | |
72 | |
73 // Returns the renderer process ID associated with the request. Returns -1 for | |
74 // browser side navigation requests. Even if the ResourceMessageFilter has | |
75 // been destroyed, this method of renderer type request info returns the | |
76 // valid process ID which was assigned to the renderer process of the filter. | |
77 int child_id() const { return child_id_; } | |
78 | |
79 // Sets the ResourceMessageFilter of the renderer type requester info. | |
80 void set_filter(base::WeakPtr<ResourceMessageFilter> filter); | |
81 | |
82 // Returns the filter for sending IPC messages to the renderer process. This | |
83 // may return null if the process exited. This method is available only for | |
84 // renderer requests. | |
85 ResourceMessageFilter* filter() const { return filter_.get(); } | |
kinuko
2016/11/21 13:36:26
basically we shouldn't return non-const pointers f
horo
2016/11/21 14:57:59
Done.
| |
86 | |
87 // Returns the ResourceContext and URLRequestContext associated to the | |
88 // request. Currently this method is available only for renderer requests. | |
89 void GetContexts(ResourceType resource_type, | |
90 ResourceContext** resource_context, | |
91 net::URLRequestContext** request_context) const; | |
92 | |
93 // Returns the ChromeAppCacheService associated with the request. Currently | |
94 // this method is available only for renderer requests. | |
95 ChromeAppCacheService* appcache_service() const { | |
96 return appcache_service_.get(); | |
97 } | |
98 | |
99 // Returns the ChromeBlobStorageContext associated with the request. Currently | |
100 // this method is available only for renderer requests. | |
101 ChromeBlobStorageContext* blob_storage_context() const { | |
102 return blob_storage_context_.get(); | |
103 } | |
104 | |
105 // Returns the FileSystemContext associated with the request. Currently this | |
106 // method is available only for renderer requests. | |
107 storage::FileSystemContext* file_system_context() const { | |
108 return file_system_context_.get(); | |
109 } | |
110 | |
111 // Returns the ServiceWorkerContext associated with the request. Currently | |
112 // this method is available for renderer requests and browser side navigation | |
113 // requests. | |
114 ServiceWorkerContextWrapper* service_worker_context() const { | |
115 return service_worker_context_.get(); | |
116 } | |
117 | |
118 private: | |
119 friend class base::RefCountedThreadSafe<ResourceRequesterInfo>; | |
120 | |
121 enum class RequesterType { | |
122 RENDERER, | |
123 BROWSER_SIDE_NAVIGATION, | |
124 DOWNLOAD_OR_PAGE_SAVE | |
125 }; | |
126 | |
127 ResourceRequesterInfo(RequesterType type, | |
128 int child_id, | |
129 ChromeAppCacheService* appcache_service, | |
130 ChromeBlobStorageContext* blob_storage_context, | |
131 storage::FileSystemContext* file_system_context, | |
132 ServiceWorkerContextWrapper* service_worker_context, | |
133 const GetContextsCallback& get_contexts_callback); | |
134 ~ResourceRequesterInfo(); | |
135 | |
136 const RequesterType type_; | |
137 // The filter might be deleted if the process exited. | |
138 base::WeakPtr<ResourceMessageFilter> filter_; | |
139 const int child_id_; | |
140 const scoped_refptr<ChromeAppCacheService> appcache_service_; | |
141 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | |
142 const scoped_refptr<storage::FileSystemContext> file_system_context_; | |
143 const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
144 const GetContextsCallback get_contexts_callback_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo); | |
147 }; | |
148 | |
149 } // namespace content | |
150 | |
151 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ | |
OLD | NEW |