jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 1 | // Copyright 2017 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_URL_LOADER_FACTORY_GETTER_H_ |
| 6 | #define CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |
| 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "content/common/content_export.h" |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 11 | #include "content/public/browser/browser_thread.h" |
mmenke | 680c214 | 2017-07-05 19:08:56 | [diff] [blame] | 12 | #include "content/public/common/url_loader_factory.mojom.h" |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 13 | |
| 14 | namespace content { |
| 15 | |
ananta | 2e65213d | 2017-05-19 04:08:24 | [diff] [blame] | 16 | class StoragePartitionImpl; |
| 17 | |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 18 | // Holds on to URLLoaderFactory for a given StoragePartition and allows code |
| 19 | // running on the IO thread to access them. Note these are the factories used by |
| 20 | // the browser process for frame requests. |
| 21 | class URLLoaderFactoryGetter |
| 22 | : public base::RefCountedThreadSafe<URLLoaderFactoryGetter, |
| 23 | BrowserThread::DeleteOnIOThread> { |
| 24 | public: |
Anantanarayanan Iyengar | aa70bb4 | 2017-08-23 01:38:32 | [diff] [blame] | 25 | CONTENT_EXPORT URLLoaderFactoryGetter(); |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 26 | |
ananta | 2e65213d | 2017-05-19 04:08:24 | [diff] [blame] | 27 | // Initializes this object on the UI thread. The |partition| is used to |
| 28 | // initialize the URLLoaderFactories for the network service and AppCache. |
| 29 | void Initialize(StoragePartitionImpl* partition); |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 30 | |
| 31 | // Called on the IO thread to get the URLLoaderFactory to the network service. |
| 32 | // The pointer shouldn't be cached. |
John Abd-El-Malek | a4bb87f | 2017-11-27 21:32:19 | [diff] [blame] | 33 | mojom::URLLoaderFactory* GetNetworkFactory(); |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 34 | |
jam | 9354af8 | 2017-06-03 21:59:41 | [diff] [blame] | 35 | // Called on the IO thread to get the URLLoaderFactory to the blob service. |
| 36 | // The pointer shouldn't be cached. |
John Abd-El-Malek | a4bb87f | 2017-11-27 21:32:19 | [diff] [blame] | 37 | CONTENT_EXPORT mojom::URLLoaderFactory* GetBlobFactory(); |
jam | 9354af8 | 2017-06-03 21:59:41 | [diff] [blame] | 38 | |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 39 | // Overrides the network URLLoaderFactory for subsequent requests. Passing a |
| 40 | // null pointer will restore the default behavior. |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 41 | CONTENT_EXPORT void SetNetworkFactoryForTesting( |
John Abd-El-Malek | a4bb87f | 2017-11-27 21:32:19 | [diff] [blame] | 42 | mojom::URLLoaderFactory* test_factory); |
| 43 | |
| 44 | CONTENT_EXPORT mojom::URLLoaderFactoryPtr* |
| 45 | original_network_factory_for_testing() { |
| 46 | return &network_factory_; |
| 47 | } |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | friend class base::DeleteHelper<URLLoaderFactoryGetter>; |
| 51 | friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 52 | |
| 53 | CONTENT_EXPORT ~URLLoaderFactoryGetter(); |
ananta | a2c8ec6 | 2017-06-09 23:44:05 | [diff] [blame] | 54 | void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory, |
| 55 | mojom::URLLoaderFactoryPtrInfo blob_factory); |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 56 | |
| 57 | // Only accessed on IO thread. |
| 58 | mojom::URLLoaderFactoryPtr network_factory_; |
jam | 9354af8 | 2017-06-03 21:59:41 | [diff] [blame] | 59 | mojom::URLLoaderFactoryPtr blob_factory_; |
John Abd-El-Malek | a4bb87f | 2017-11-27 21:32:19 | [diff] [blame] | 60 | mojom::URLLoaderFactory* test_factory_ = nullptr; |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter); |
| 63 | }; |
| 64 | |
| 65 | } // namespace content |
| 66 | |
| 67 | #endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |