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 esource requester. |
| 33 // Currently there are three types: |
| 34 // - Requesters that request resources from renderer processes. |
| 35 // - Requesters that request resources within the browser process for browser |
| 36 // side navigation (aka PlzNavigate). |
| 37 // - Requesters that request resources for download or page save. |
| 38 class CONTENT_EXPORT ResourceRequesterInfo |
| 39 : public base::RefCountedThreadSafe<ResourceRequesterInfo> { |
| 40 public: |
| 41 typedef base::Callback<void(ResourceType resource_type, |
| 42 ResourceContext**, |
| 43 net::URLRequestContext**)> |
| 44 GetContextsCallback; |
| 45 |
| 46 // Creates a ResourceRequesterInfo for a requester that requests resources |
| 47 // from the renderer process. |
| 48 static scoped_refptr<ResourceRequesterInfo> CreateForRenderer( |
| 49 int child_id, |
| 50 ChromeAppCacheService* appcache_service, |
| 51 ChromeBlobStorageContext* blob_storage_context, |
| 52 storage::FileSystemContext* file_system_context, |
| 53 ServiceWorkerContextWrapper* service_worker_context, |
| 54 const GetContextsCallback& get_contexts_callback); |
| 55 |
| 56 // Creates a ResourceRequesterInfo for a requester that requests resources |
| 57 // from the renderer process for testing. |
| 58 static scoped_refptr<ResourceRequesterInfo> CreateForRendererTesting( |
| 59 int child_id); |
| 60 |
| 61 // Creates a ResourceRequesterInfo for a requester that requests resources |
| 62 // within the browser process for browser side navigation (aka PlzNavigate). |
| 63 static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation( |
| 64 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
| 65 |
| 66 // Creates a ResourceRequesterInfo for a requester that requests resources for |
| 67 // download or page save. |
| 68 static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave( |
| 69 int child_id); |
| 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 requester. Returns -1 |
| 77 // for browser side navigation requester. Even if the ResourceMessageFilter |
| 78 // has been destroyed, this method of renderer type requester 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 exited. This method is available only for |
| 87 // renderer type requester. |
| 88 ResourceMessageFilter* filter() { return filter_.get(); } |
| 89 |
| 90 // Returns the ResourceContext and URLRequestContext associated to the |
| 91 // requester. Currently this method is available only for renderer type |
| 92 // requester. |
| 93 void GetContexts(ResourceType resource_type, |
| 94 ResourceContext** resource_context, |
| 95 net::URLRequestContext** request_context) const; |
| 96 |
| 97 // Returns the ChromeAppCacheService associated with the requester. Currently |
| 98 // this method is available only for renderer type requester. |
| 99 ChromeAppCacheService* appcache_service() { return appcache_service_.get(); } |
| 100 |
| 101 // Returns the ChromeBlobStorageContext associated with the requester. |
| 102 // Currently this method is available only for renderer type requester. |
| 103 ChromeBlobStorageContext* blob_storage_context() { |
| 104 return blob_storage_context_.get(); |
| 105 } |
| 106 |
| 107 // Returns the FileSystemContext associated with the requester. Currently this |
| 108 // method is available only for renderer type requester. |
| 109 storage::FileSystemContext* file_system_context() { |
| 110 return file_system_context_.get(); |
| 111 } |
| 112 |
| 113 // Returns the ServiceWorkerContext associated with the requester. Currently |
| 114 // this method is available for renderer type requester and browser side |
| 115 // navigation type requester. |
| 116 ServiceWorkerContextWrapper* service_worker_context() { |
| 117 return service_worker_context_.get(); |
| 118 } |
| 119 |
| 120 private: |
| 121 friend class base::RefCountedThreadSafe<ResourceRequesterInfo>; |
| 122 |
| 123 enum class RequesterType { |
| 124 RENDERER, |
| 125 BROWSER_SIDE_NAVIGATION, |
| 126 DOWNLOAD_OR_PAGE_SAVE |
| 127 }; |
| 128 |
| 129 ResourceRequesterInfo(RequesterType type, |
| 130 int child_id, |
| 131 ChromeAppCacheService* appcache_service, |
| 132 ChromeBlobStorageContext* blob_storage_context, |
| 133 storage::FileSystemContext* file_system_context, |
| 134 ServiceWorkerContextWrapper* service_worker_context, |
| 135 const GetContextsCallback& get_contexts_callback); |
| 136 ~ResourceRequesterInfo(); |
| 137 |
| 138 const RequesterType type_; |
| 139 // The filter might be deleted if the process exited. |
| 140 base::WeakPtr<ResourceMessageFilter> filter_; |
| 141 const int child_id_; |
| 142 const scoped_refptr<ChromeAppCacheService> appcache_service_; |
| 143 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 144 const scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 145 const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 146 const GetContextsCallback get_contexts_callback_; |
| 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo); |
| 149 }; |
| 150 |
| 151 } // namespace content |
| 152 |
| 153 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ |
OLD | NEW |