Chromium Code Reviews| 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. | |
| 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. | |
| 37 class CONTENT_EXPORT ResourceRequesterInfo { | |
| 38 public: | |
| 39 typedef base::Callback<void(ResourceType resource_type, | |
| 40 ResourceContext**, | |
| 41 net::URLRequestContext**)> | |
| 42 GetContextsCallback; | |
| 43 | |
| 44 // Creates a ResourceRequesterInfo for renderer process initiated request. | |
| 45 static std::unique_ptr<ResourceRequesterInfo> CreateForRenderer( | |
| 46 int child_id, | |
| 47 ChromeAppCacheService* appcache_service, | |
| 48 ChromeBlobStorageContext* blob_storage_context, | |
| 49 storage::FileSystemContext* file_system_context, | |
| 50 ServiceWorkerContextWrapper* service_worker_context, | |
| 51 const GetContextsCallback& get_contexts_callback); | |
| 52 | |
| 53 // Creates a ResourceRequesterInfo for a renderer process initiated request | |
| 54 // for testing. | |
| 55 static std::unique_ptr<ResourceRequesterInfo> CreateForRendererTesting( | |
| 56 int child_id); | |
| 57 | |
| 58 // Creates a ResourceRequesterInfo for a browser side navigation request which | |
| 59 // is initiated by the browser process. | |
| 60 static std::unique_ptr<ResourceRequesterInfo> CreateForBrowserSideNavigation( | |
| 61 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | |
| 62 | |
| 63 // Creates a ResourceRequesterInfo for a download or page save request. | |
| 64 static std::unique_ptr<ResourceRequesterInfo> CreateForDownloadOrPageSave( | |
| 65 int child_id); | |
| 66 | |
| 67 ~ResourceRequesterInfo(); | |
| 68 | |
| 69 std::unique_ptr<ResourceRequesterInfo> clone() const; | |
| 70 | |
| 71 bool IsRenderer() const { return type_ == RequesterType::RENDERER; } | |
| 72 bool IsBrowserSideNavigation() const { | |
| 73 return type_ == RequesterType::BROWSER_SIDE_NAVIGATION; | |
| 74 } | |
| 75 | |
| 76 // Returns the renderer process ID associated with the request. Returns -1 for | |
| 77 // browser side navigation requests. Even if the ResourceMessageFilter has | |
| 78 // been destroyed, this method of renderer type request info returns the | |
| 79 // valid process ID which was assigned to the renderer process of the filter. | |
| 80 int child_id() const { return child_id_; } | |
| 81 | |
| 82 // Sets the ResourceMessageFilter of the renderer type requester info. | |
| 83 void set_filter(base::WeakPtr<ResourceMessageFilter> filter); | |
| 84 | |
| 85 // Returns the filter for sending IPC messages to the renderer process. This | |
| 86 // may return null if the process eixted. This method is available only for | |
|
mmenke
2016/11/17 16:27:20
exited
horo
2016/11/17 17:50:27
Done.
| |
| 87 // renderer requests. | |
| 88 ResourceMessageFilter* filter() const { return filter_.get(); } | |
| 89 | |
| 90 // Returns the ResourceContext and URLRequestContext associated to the | |
| 91 // request. Currently this method is available only for renderer requests. | |
| 92 void GetContexts(ResourceType resource_type, | |
| 93 ResourceContext** resource_context, | |
| 94 net::URLRequestContext** request_context) const; | |
| 95 | |
| 96 // Returns the ChromeAppCacheService associated with the request. Currently | |
| 97 // this method is available only for renderer requests. | |
| 98 ChromeAppCacheService* appcache_service() const { | |
| 99 return appcache_service_.get(); | |
| 100 } | |
| 101 | |
| 102 // Returns the ChromeBlobStorageContext associated with the request. Currently | |
| 103 // this method is available only for renderer requests. | |
| 104 ChromeBlobStorageContext* blob_storage_context() const { | |
| 105 return blob_storage_context_.get(); | |
| 106 } | |
| 107 | |
| 108 // Returns the FileSystemContext associated with the request. Currently this | |
| 109 // method is available only for renderer requests. | |
| 110 storage::FileSystemContext* file_system_context() const { | |
| 111 return file_system_context_.get(); | |
| 112 } | |
| 113 | |
| 114 // Returns the ServiceWorkerContext associated with the request. Currently | |
| 115 // this method is available for renderer requests and browser side navigation | |
| 116 // requests. | |
| 117 ServiceWorkerContextWrapper* service_worker_context() const { | |
| 118 return service_worker_context_.get(); | |
| 119 } | |
| 120 | |
| 121 private: | |
| 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 | |
| 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 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
| 141 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | |
| 142 scoped_refptr<storage::FileSystemContext> file_system_context_; | |
| 143 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
| 144 GetContextsCallback get_contexts_callback_; | |
|
mmenke
2016/11/17 16:27:20
I think all of these be const, except filter? (Th
horo
2016/11/17 17:50:27
Done.
| |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo); | |
| 147 }; | |
| 148 | |
| 149 } // namespace content | |
| 150 | |
| 151 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ | |
| OLD | NEW |