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
);
79 // Create an instance for an original profile for media. This is expected to
80 // get called on UI thread. This method takes a profile and reuses the
81 // 'original' net::URLRequestContext for common files.
82 static ChromeURLRequestContextGetter
* CreateForMedia(
83 Profile
* profile
, const ProfileIOData
* profile_io_data
);
85 // Create an instance for an original profile for extensions. This is expected
86 // to get called on UI thread.
87 static ChromeURLRequestContextGetter
* CreateForExtensions(
88 Profile
* profile
, const ProfileIOData
* profile_io_data
);
90 // Create an instance for an original profile for an app with isolated
91 // storage. This is expected to get called on UI thread.
92 static ChromeURLRequestContextGetter
* CreateForIsolatedApp(
94 const ProfileIOData
* profile_io_data
,
95 const StoragePartitionDescriptor
& partition_descriptor
,
96 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
97 protocol_handler_interceptor
,
98 content::ProtocolHandlerMap
* protocol_handlers
);
100 // Create an instance for an original profile for media with isolated
101 // storage. This is expected to get called on UI thread.
102 static ChromeURLRequestContextGetter
* CreateForIsolatedMedia(
104 ChromeURLRequestContextGetter
* app_context
,
105 const ProfileIOData
* profile_io_data
,
106 const StoragePartitionDescriptor
& partition_descriptor
);
109 virtual ~ChromeURLRequestContextGetter();
111 // Deferred logic for creating a ChromeURLRequestContext.
112 // Access only from the IO thread.
113 scoped_ptr
<ChromeURLRequestContextFactory
> factory_
;
115 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext
116 // instance that was lazily created by GetURLRequestContext().
117 // Access only from the IO thread.
118 base::WeakPtr
<ChromeURLRequestContext
> url_request_context_
;
120 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter
);
123 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_