1 // Copyright (c) 2012 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_H_
6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_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 // Subclass of net::URLRequestContext which can be used to store extra
23 // information for requests.
25 // All methods of this class must be called from the IO thread,
26 // including the constructor and destructor.
27 class ChromeURLRequestContext
: public net::URLRequestContext
{
29 ChromeURLRequestContext();
30 virtual ~ChromeURLRequestContext();
32 base::WeakPtr
<ChromeURLRequestContext
> GetWeakPtr() {
33 return weak_factory_
.GetWeakPtr();
36 // Copies the state from |other| into this context.
37 void CopyFrom(ChromeURLRequestContext
* other
);
40 base::WeakPtrFactory
<ChromeURLRequestContext
> weak_factory_
;
42 // ---------------------------------------------------------------------------
43 // Important: When adding any new members below, consider whether they need to
44 // be added to CopyFrom.
45 // ---------------------------------------------------------------------------
47 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext
);
50 // A net::URLRequestContextGetter subclass used by the browser. This returns a
51 // subclass of net::URLRequestContext which can be used to store extra
52 // information about requests.
54 // Most methods are expected to be called on the UI thread, except for
55 // the destructor and GetURLRequestContext().
56 class ChromeURLRequestContextGetter
: public net::URLRequestContextGetter
{
58 // Constructs a ChromeURLRequestContextGetter that will use |factory| to
59 // create the ChromeURLRequestContext.
60 explicit ChromeURLRequestContextGetter(
61 ChromeURLRequestContextFactory
* factory
);
63 // Note that GetURLRequestContext() can only be called from the IO
64 // thread (it will assert otherwise).
65 // GetIOMessageLoopProxy however can be called from any thread.
67 // net::URLRequestContextGetter implementation.
68 virtual ChromeURLRequestContext
* GetURLRequestContext() OVERRIDE
;
69 virtual scoped_refptr
<base::SingleThreadTaskRunner
>
70 GetNetworkTaskRunner() const OVERRIDE
;
72 // Create an instance for use with an 'original' (non-OTR) profile. This is
73 // expected to get called on the UI thread.
74 static ChromeURLRequestContextGetter
* Create(
76 const ProfileIOData
* profile_io_data
,
77 content::ProtocolHandlerMap
* protocol_handlers
,
78 content::ProtocolHandlerScopedVector protocol_interceptors
);
80 // Create an instance for an original profile for media. This is expected to
81 // get called on UI thread. This method takes a profile and reuses the
82 // 'original' net::URLRequestContext for common files.
83 static ChromeURLRequestContextGetter
* CreateForMedia(
84 Profile
* profile
, const ProfileIOData
* profile_io_data
);
86 // Create an instance for an original profile for extensions. This is expected
87 // to get called on UI thread.
88 static ChromeURLRequestContextGetter
* CreateForExtensions(
89 Profile
* profile
, const ProfileIOData
* profile_io_data
);
91 // Create an instance for an original profile for an app with isolated
92 // storage. This is expected to get called on UI thread.
93 static ChromeURLRequestContextGetter
* CreateForIsolatedApp(
95 const ProfileIOData
* profile_io_data
,
96 const StoragePartitionDescriptor
& partition_descriptor
,
97 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
98 protocol_handler_interceptor
,
99 content::ProtocolHandlerMap
* protocol_handlers
,
100 content::ProtocolHandlerScopedVector protocol_interceptors
);
102 // Create an instance for an original profile for media with isolated
103 // storage. This is expected to get called on UI thread.
104 static ChromeURLRequestContextGetter
* CreateForIsolatedMedia(
106 ChromeURLRequestContextGetter
* app_context
,
107 const ProfileIOData
* profile_io_data
,
108 const StoragePartitionDescriptor
& partition_descriptor
);
111 virtual ~ChromeURLRequestContextGetter();
113 // Deferred logic for creating a ChromeURLRequestContext.
114 // Access only from the IO thread.
115 scoped_ptr
<ChromeURLRequestContextFactory
> factory_
;
117 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext
118 // instance that was lazily created by GetURLRequestContext().
119 // Access only from the IO thread.
120 base::WeakPtr
<ChromeURLRequestContext
> url_request_context_
;
122 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter
);
125 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_