blob: 35a1ed0322c6487c315966c546e8d9f2e64bdd50 [file] [log] [blame]
jamc1905862017-05-16 14:45:301// 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"
jamc1905862017-05-16 14:45:3011#include "content/public/browser/browser_thread.h"
mmenke680c2142017-07-05 19:08:5612#include "content/public/common/url_loader_factory.mojom.h"
jamc1905862017-05-16 14:45:3013
14namespace content {
15
ananta2e65213d2017-05-19 04:08:2416class StoragePartitionImpl;
17
jamc1905862017-05-16 14:45:3018// 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.
21class URLLoaderFactoryGetter
22 : public base::RefCountedThreadSafe<URLLoaderFactoryGetter,
23 BrowserThread::DeleteOnIOThread> {
24 public:
Anantanarayanan Iyengaraa70bb42017-08-23 01:38:3225 CONTENT_EXPORT URLLoaderFactoryGetter();
jamc1905862017-05-16 14:45:3026
ananta2e65213d2017-05-19 04:08:2427 // 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);
jamc1905862017-05-16 14:45:3030
31 // Called on the IO thread to get the URLLoaderFactory to the network service.
32 // The pointer shouldn't be cached.
John Abd-El-Maleka4bb87f2017-11-27 21:32:1933 mojom::URLLoaderFactory* GetNetworkFactory();
jamc1905862017-05-16 14:45:3034
jam9354af82017-06-03 21:59:4135 // Called on the IO thread to get the URLLoaderFactory to the blob service.
36 // The pointer shouldn't be cached.
John Abd-El-Maleka4bb87f2017-11-27 21:32:1937 CONTENT_EXPORT mojom::URLLoaderFactory* GetBlobFactory();
jam9354af82017-06-03 21:59:4138
jamc1905862017-05-16 14:45:3039 // Overrides the network URLLoaderFactory for subsequent requests. Passing a
40 // null pointer will restore the default behavior.
jamc1905862017-05-16 14:45:3041 CONTENT_EXPORT void SetNetworkFactoryForTesting(
John Abd-El-Maleka4bb87f2017-11-27 21:32:1942 mojom::URLLoaderFactory* test_factory);
43
44 CONTENT_EXPORT mojom::URLLoaderFactoryPtr*
45 original_network_factory_for_testing() {
46 return &network_factory_;
47 }
jamc1905862017-05-16 14:45:3048
49 private:
50 friend class base::DeleteHelper<URLLoaderFactoryGetter>;
51 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
52
53 CONTENT_EXPORT ~URLLoaderFactoryGetter();
anantaa2c8ec62017-06-09 23:44:0554 void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory,
55 mojom::URLLoaderFactoryPtrInfo blob_factory);
jamc1905862017-05-16 14:45:3056
57 // Only accessed on IO thread.
58 mojom::URLLoaderFactoryPtr network_factory_;
jam9354af82017-06-03 21:59:4159 mojom::URLLoaderFactoryPtr blob_factory_;
John Abd-El-Maleka4bb87f2017-11-27 21:32:1960 mojom::URLLoaderFactory* test_factory_ = nullptr;
jamc1905862017-05-16 14:45:3061
62 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter);
63};
64
65} // namespace content
66
67#endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_