1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_GETTER_H_
6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_GETTER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
12 #include "net/url_request/url_request_context.h"
13 #include "net/url_request/url_request_context_getter.h"
14 #include "net/url_request/url_request_job_factory.h"
16 class ChromeURLRequestContextFactory
;
20 struct StoragePartitionDescriptor
;
22 // A net::URLRequestContextGetter subclass used by the browser. This returns a
23 // subclass of net::URLRequestContext which can be used to store extra
24 // information about requests.
26 // Most methods are expected to be called on the UI thread, except for
27 // the destructor and GetURLRequestContext().
28 class ChromeURLRequestContextGetter
: public net::URLRequestContextGetter
{
30 // Constructs a ChromeURLRequestContextGetter that will use |factory| to
31 // create the URLRequestContext.
32 explicit ChromeURLRequestContextGetter(
33 ChromeURLRequestContextFactory
* factory
);
35 // Note that GetURLRequestContext() can only be called from the IO
36 // thread (it will assert otherwise).
37 // GetIOMessageLoopProxy however can be called from any thread.
39 // net::URLRequestContextGetter implementation.
40 net::URLRequestContext
* GetURLRequestContext() override
;
41 scoped_refptr
<base::SingleThreadTaskRunner
> GetNetworkTaskRunner()
44 // Create an instance for use with an 'original' (non-OTR) profile. This is
45 // expected to get called on the UI thread.
46 static ChromeURLRequestContextGetter
* Create(
48 const ProfileIOData
* profile_io_data
,
49 content::ProtocolHandlerMap
* protocol_handlers
,
50 content::URLRequestInterceptorScopedVector request_interceptors
);
52 // Create an instance for an original profile for media. This is expected to
53 // get called on UI thread. This method takes a profile and reuses the
54 // 'original' net::URLRequestContext for common files.
55 static ChromeURLRequestContextGetter
* CreateForMedia(
56 Profile
* profile
, const ProfileIOData
* profile_io_data
);
58 // Create an instance for an original profile for extensions. This is expected
59 // to get called on UI thread.
60 static ChromeURLRequestContextGetter
* CreateForExtensions(
61 Profile
* profile
, const ProfileIOData
* profile_io_data
);
63 // Create an instance for an original profile for an app with isolated
64 // storage. This is expected to get called on UI thread.
65 static ChromeURLRequestContextGetter
* CreateForIsolatedApp(
67 const ProfileIOData
* profile_io_data
,
68 const StoragePartitionDescriptor
& partition_descriptor
,
69 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
70 protocol_handler_interceptor
,
71 content::ProtocolHandlerMap
* protocol_handlers
,
72 content::URLRequestInterceptorScopedVector request_interceptors
);
74 // Create an instance for an original profile for media with isolated
75 // storage. This is expected to get called on UI thread.
76 static ChromeURLRequestContextGetter
* CreateForIsolatedMedia(
78 ChromeURLRequestContextGetter
* app_context
,
79 const ProfileIOData
* profile_io_data
,
80 const StoragePartitionDescriptor
& partition_descriptor
);
82 // Discard reference to URLRequestContext and inform observers of shutdown.
83 // Must be called before destruction. May only be called on IO thread.
84 void NotifyContextShuttingDown();
87 ~ChromeURLRequestContextGetter() override
;
89 // Deferred logic for creating a URLRequestContext.
90 // Access only from the IO thread.
91 scoped_ptr
<ChromeURLRequestContextFactory
> factory_
;
93 // NULL before initialization and after invalidation.
94 // Otherwise, it is the URLRequestContext instance that
95 // was lazily created by GetURLRequestContext().
96 // Access only from the IO thread.
97 net::URLRequestContext
* url_request_context_
;
99 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter
);
102 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_GETTER_H_