blob: cee9f47b0608872afd582f3cf0afaeda4d2e965c [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.
33 mojom::URLLoaderFactoryPtr* GetNetworkFactory();
34
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.
37 CONTENT_EXPORT mojom::URLLoaderFactoryPtr* GetBlobFactory();
38
jamc1905862017-05-16 14:45:3039 // 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();
anantaa2c8ec62017-06-09 23:44:0550 void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory,
51 mojom::URLLoaderFactoryPtrInfo blob_factory);
jamc1905862017-05-16 14:45:3052 void SetTestNetworkFactoryOnIOThread(
53 mojom::URLLoaderFactoryPtrInfo test_factory);
54
55 // Only accessed on IO thread.
56 mojom::URLLoaderFactoryPtr network_factory_;
jam9354af82017-06-03 21:59:4157 mojom::URLLoaderFactoryPtr blob_factory_;
58 mojom::URLLoaderFactoryPtr test_factory_;
jamc1905862017-05-16 14:45:3059
60 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter);
61};
62
63} // namespace content
64
65#endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_