Chromium Code Reviews| Index: content/browser/loader/resource_requester_info.h |
| diff --git a/content/browser/loader/resource_requester_info.h b/content/browser/loader/resource_requester_info.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb2159c2501765fc22b618a1243907d556bf0d88 |
| --- /dev/null |
| +++ b/content/browser/loader/resource_requester_info.h |
| @@ -0,0 +1,151 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ |
| +#define CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "content/common/content_export.h" |
| +#include "content/public/common/resource_type.h" |
| + |
| +namespace net { |
| +class URLRequestContext; |
| +} // namespace net |
| + |
| +namespace storage { |
| +class FileSystemContext; |
| +} // namespace storage |
| + |
| +namespace content { |
| +class BrowserMessageFilter; |
| +class ChromeAppCacheService; |
| +class ChromeBlobStorageContext; |
| +class ResourceContext; |
| +class ResourceMessageFilter; |
| +class ServiceWorkerContextWrapper; |
| + |
| +// 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.
|
| +// Currently there are three types: |
| +// - Resource request from renderer processes. |
| +// - Resource request for browser side navigation. (PlzNavigate). |
| +// - 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.
|
| +class CONTENT_EXPORT ResourceRequesterInfo |
| + : public base::RefCountedThreadSafe<ResourceRequesterInfo> { |
| + public: |
| + typedef base::Callback<void(ResourceType resource_type, |
| + ResourceContext**, |
| + net::URLRequestContext**)> |
| + GetContextsCallback; |
| + |
| + // 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.
|
| + static scoped_refptr<ResourceRequesterInfo> CreateForRenderer( |
| + int child_id, |
| + ChromeAppCacheService* appcache_service, |
| + ChromeBlobStorageContext* blob_storage_context, |
| + storage::FileSystemContext* file_system_context, |
| + ServiceWorkerContextWrapper* service_worker_context, |
| + const GetContextsCallback& get_contexts_callback); |
| + |
| + // Creates a ResourceRequesterInfo for a renderer process initiated request |
| + // for testing. |
| + static scoped_refptr<ResourceRequesterInfo> CreateForRendererTesting( |
| + int child_id); |
| + |
| + // Creates a ResourceRequesterInfo for a browser side navigation request which |
| + // is initiated by the browser process. |
| + static scoped_refptr<ResourceRequesterInfo> CreateForBrowserSideNavigation( |
| + scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
| + |
| + // Creates a ResourceRequesterInfo for a download or page save request. |
| + static scoped_refptr<ResourceRequesterInfo> CreateForDownloadOrPageSave( |
| + int child_id); |
| + |
| + bool IsRenderer() const { return type_ == RequesterType::RENDERER; } |
| + bool IsBrowserSideNavigation() const { |
| + return type_ == RequesterType::BROWSER_SIDE_NAVIGATION; |
| + } |
| + |
| + // Returns the renderer process ID associated with the request. Returns -1 for |
| + // browser side navigation requests. Even if the ResourceMessageFilter has |
| + // been destroyed, this method of renderer type request info returns the |
| + // valid process ID which was assigned to the renderer process of the filter. |
| + int child_id() const { return child_id_; } |
| + |
| + // Sets the ResourceMessageFilter of the renderer type requester info. |
| + void set_filter(base::WeakPtr<ResourceMessageFilter> filter); |
| + |
| + // Returns the filter for sending IPC messages to the renderer process. This |
| + // may return null if the process exited. This method is available only for |
| + // renderer requests. |
| + 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.
|
| + |
| + // Returns the ResourceContext and URLRequestContext associated to the |
| + // request. Currently this method is available only for renderer requests. |
| + void GetContexts(ResourceType resource_type, |
| + ResourceContext** resource_context, |
| + net::URLRequestContext** request_context) const; |
| + |
| + // Returns the ChromeAppCacheService associated with the request. Currently |
| + // this method is available only for renderer requests. |
| + ChromeAppCacheService* appcache_service() const { |
| + return appcache_service_.get(); |
| + } |
| + |
| + // Returns the ChromeBlobStorageContext associated with the request. Currently |
| + // this method is available only for renderer requests. |
| + ChromeBlobStorageContext* blob_storage_context() const { |
| + return blob_storage_context_.get(); |
| + } |
| + |
| + // Returns the FileSystemContext associated with the request. Currently this |
| + // method is available only for renderer requests. |
| + storage::FileSystemContext* file_system_context() const { |
| + return file_system_context_.get(); |
| + } |
| + |
| + // Returns the ServiceWorkerContext associated with the request. Currently |
| + // this method is available for renderer requests and browser side navigation |
| + // requests. |
| + ServiceWorkerContextWrapper* service_worker_context() const { |
| + return service_worker_context_.get(); |
| + } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<ResourceRequesterInfo>; |
| + |
| + enum class RequesterType { |
| + RENDERER, |
| + BROWSER_SIDE_NAVIGATION, |
| + DOWNLOAD_OR_PAGE_SAVE |
| + }; |
| + |
| + ResourceRequesterInfo(RequesterType type, |
| + int child_id, |
| + ChromeAppCacheService* appcache_service, |
| + ChromeBlobStorageContext* blob_storage_context, |
| + storage::FileSystemContext* file_system_context, |
| + ServiceWorkerContextWrapper* service_worker_context, |
| + const GetContextsCallback& get_contexts_callback); |
| + ~ResourceRequesterInfo(); |
| + |
| + const RequesterType type_; |
| + // The filter might be deleted if the process exited. |
| + base::WeakPtr<ResourceMessageFilter> filter_; |
| + const int child_id_; |
| + const scoped_refptr<ChromeAppCacheService> appcache_service_; |
| + const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| + const scoped_refptr<storage::FileSystemContext> file_system_context_; |
| + const scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| + const GetContextsCallback get_contexts_callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ResourceRequesterInfo); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUESTER_INFO_H_ |