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. |
| 33 | mojom::URLLoaderFactoryPtr* GetNetworkFactory(); |
| 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. |
| 37 | CONTENT_EXPORT mojom::URLLoaderFactoryPtr* GetBlobFactory(); |
| 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. |
| 41 | // This is called on the UI thread. |
| 42 | CONTENT_EXPORT void SetNetworkFactoryForTesting( |
| 43 | mojom::URLLoaderFactoryPtr test_factory); |
| 44 | |
| 45 | private: |
| 46 | friend class base::DeleteHelper<URLLoaderFactoryGetter>; |
| 47 | friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 48 | |
| 49 | CONTENT_EXPORT ~URLLoaderFactoryGetter(); |
ananta | a2c8ec6 | 2017-06-09 23:44:05 | [diff] [blame] | 50 | void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory, |
| 51 | mojom::URLLoaderFactoryPtrInfo blob_factory); |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 52 | void SetTestNetworkFactoryOnIOThread( |
| 53 | mojom::URLLoaderFactoryPtrInfo test_factory); |
| 54 | |
| 55 | // Only accessed on IO thread. |
| 56 | mojom::URLLoaderFactoryPtr network_factory_; |
jam | 9354af8 | 2017-06-03 21:59:41 | [diff] [blame] | 57 | mojom::URLLoaderFactoryPtr blob_factory_; |
| 58 | mojom::URLLoaderFactoryPtr test_factory_; |
jam | c190586 | 2017-05-16 14:45:30 | [diff] [blame] | 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter); |
| 61 | }; |
| 62 | |
| 63 | } // namespace content |
| 64 | |
| 65 | #endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |