OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // ---------------------------------------------------------------------------- | 35 // ---------------------------------------------------------------------------- |
36 // Helper factories | 36 // Helper factories |
37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
38 | 38 |
39 // Factory that creates the main ChromeURLRequestContext. | 39 // Factory that creates the main ChromeURLRequestContext. |
40 class FactoryForMain : public ChromeURLRequestContextFactory { | 40 class FactoryForMain : public ChromeURLRequestContextFactory { |
41 public: | 41 public: |
42 FactoryForMain( | 42 FactoryForMain( |
43 const ProfileIOData* profile_io_data, | 43 const ProfileIOData* profile_io_data, |
44 content::ProtocolHandlerMap* protocol_handlers) | 44 content::ProtocolHandlerMap* protocol_handlers, |
45 : profile_io_data_(profile_io_data) { | 45 content::ProtocolHandlerScopedVector protocol_interceptors) |
| 46 : profile_io_data_(profile_io_data), |
| 47 protocol_interceptors_(protocol_interceptors.Pass()) { |
46 std::swap(protocol_handlers_, *protocol_handlers); | 48 std::swap(protocol_handlers_, *protocol_handlers); |
47 } | 49 } |
48 | 50 |
49 virtual ChromeURLRequestContext* Create() OVERRIDE { | 51 virtual ChromeURLRequestContext* Create() OVERRIDE { |
50 profile_io_data_->Init(&protocol_handlers_); | 52 profile_io_data_->Init(&protocol_handlers_, protocol_interceptors_.Pass()); |
51 return profile_io_data_->GetMainRequestContext(); | 53 return profile_io_data_->GetMainRequestContext(); |
52 } | 54 } |
53 | 55 |
54 private: | 56 private: |
55 const ProfileIOData* const profile_io_data_; | 57 const ProfileIOData* const profile_io_data_; |
56 content::ProtocolHandlerMap protocol_handlers_; | 58 content::ProtocolHandlerMap protocol_handlers_; |
| 59 content::ProtocolHandlerScopedVector protocol_interceptors_; |
57 }; | 60 }; |
58 | 61 |
59 // Factory that creates the ChromeURLRequestContext for extensions. | 62 // Factory that creates the ChromeURLRequestContext for extensions. |
60 class FactoryForExtensions : public ChromeURLRequestContextFactory { | 63 class FactoryForExtensions : public ChromeURLRequestContextFactory { |
61 public: | 64 public: |
62 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) | 65 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) |
63 : profile_io_data_(profile_io_data) {} | 66 : profile_io_data_(profile_io_data) {} |
64 | 67 |
65 virtual ChromeURLRequestContext* Create() OVERRIDE { | 68 virtual ChromeURLRequestContext* Create() OVERRIDE { |
66 return profile_io_data_->GetExtensionsRequestContext(); | 69 return profile_io_data_->GetExtensionsRequestContext(); |
67 } | 70 } |
68 | 71 |
69 private: | 72 private: |
70 const ProfileIOData* const profile_io_data_; | 73 const ProfileIOData* const profile_io_data_; |
71 }; | 74 }; |
72 | 75 |
73 // Factory that creates the ChromeURLRequestContext for a given isolated app. | 76 // Factory that creates the ChromeURLRequestContext for a given isolated app. |
74 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | 77 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
75 public: | 78 public: |
76 FactoryForIsolatedApp( | 79 FactoryForIsolatedApp( |
77 const ProfileIOData* profile_io_data, | 80 const ProfileIOData* profile_io_data, |
78 const StoragePartitionDescriptor& partition_descriptor, | 81 const StoragePartitionDescriptor& partition_descriptor, |
79 ChromeURLRequestContextGetter* main_context, | 82 ChromeURLRequestContextGetter* main_context, |
80 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 83 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
81 protocol_handler_interceptor, | 84 protocol_handler_interceptor, |
82 content::ProtocolHandlerMap* protocol_handlers) | 85 content::ProtocolHandlerMap* protocol_handlers, |
| 86 content::ProtocolHandlerScopedVector protocol_interceptors) |
83 : profile_io_data_(profile_io_data), | 87 : profile_io_data_(profile_io_data), |
84 partition_descriptor_(partition_descriptor), | 88 partition_descriptor_(partition_descriptor), |
85 main_request_context_getter_(main_context), | 89 main_request_context_getter_(main_context), |
86 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) { | 90 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), |
| 91 protocol_interceptors_(protocol_interceptors.Pass()) { |
87 std::swap(protocol_handlers_, *protocol_handlers); | 92 std::swap(protocol_handlers_, *protocol_handlers); |
88 } | 93 } |
89 | 94 |
90 virtual ChromeURLRequestContext* Create() OVERRIDE { | 95 virtual ChromeURLRequestContext* Create() OVERRIDE { |
91 // We will copy most of the state from the main request context. | 96 // We will copy most of the state from the main request context. |
92 // | 97 // |
93 // Note that this factory is one-shot. After Create() is called once, the | 98 // Note that this factory is one-shot. After Create() is called once, the |
94 // factory is actually destroyed. Thus it is safe to destructively pass | 99 // factory is actually destroyed. Thus it is safe to destructively pass |
95 // state onwards. | 100 // state onwards. |
96 return profile_io_data_->GetIsolatedAppRequestContext( | 101 return profile_io_data_->GetIsolatedAppRequestContext( |
97 main_request_context_getter_->GetURLRequestContext(), | 102 main_request_context_getter_->GetURLRequestContext(), |
98 partition_descriptor_, | 103 partition_descriptor_, |
99 protocol_handler_interceptor_.Pass(), | 104 protocol_handler_interceptor_.Pass(), |
100 &protocol_handlers_); | 105 &protocol_handlers_, |
| 106 protocol_interceptors_.Pass()); |
101 } | 107 } |
102 | 108 |
103 private: | 109 private: |
104 const ProfileIOData* const profile_io_data_; | 110 const ProfileIOData* const profile_io_data_; |
105 const StoragePartitionDescriptor partition_descriptor_; | 111 const StoragePartitionDescriptor partition_descriptor_; |
106 scoped_refptr<ChromeURLRequestContextGetter> | 112 scoped_refptr<ChromeURLRequestContextGetter> |
107 main_request_context_getter_; | 113 main_request_context_getter_; |
108 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 114 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
109 protocol_handler_interceptor_; | 115 protocol_handler_interceptor_; |
110 content::ProtocolHandlerMap protocol_handlers_; | 116 content::ProtocolHandlerMap protocol_handlers_; |
| 117 content::ProtocolHandlerScopedVector protocol_interceptors_; |
111 }; | 118 }; |
112 | 119 |
113 // Factory that creates the media ChromeURLRequestContext for a given isolated | 120 // Factory that creates the media ChromeURLRequestContext for a given isolated |
114 // app. The media context is based on the corresponding isolated app's context. | 121 // app. The media context is based on the corresponding isolated app's context. |
115 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { | 122 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { |
116 public: | 123 public: |
117 FactoryForIsolatedMedia( | 124 FactoryForIsolatedMedia( |
118 const ProfileIOData* profile_io_data, | 125 const ProfileIOData* profile_io_data, |
119 const StoragePartitionDescriptor& partition_descriptor, | 126 const StoragePartitionDescriptor& partition_descriptor, |
120 ChromeURLRequestContextGetter* app_context) | 127 ChromeURLRequestContextGetter* app_context) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 195 |
189 scoped_refptr<base::SingleThreadTaskRunner> | 196 scoped_refptr<base::SingleThreadTaskRunner> |
190 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { | 197 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { |
191 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 198 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
192 } | 199 } |
193 | 200 |
194 // static | 201 // static |
195 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( | 202 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::Create( |
196 Profile* profile, | 203 Profile* profile, |
197 const ProfileIOData* profile_io_data, | 204 const ProfileIOData* profile_io_data, |
198 content::ProtocolHandlerMap* protocol_handlers) { | 205 content::ProtocolHandlerMap* protocol_handlers, |
| 206 content::ProtocolHandlerScopedVector protocol_interceptors) { |
199 return new ChromeURLRequestContextGetter( | 207 return new ChromeURLRequestContextGetter( |
200 new FactoryForMain(profile_io_data, protocol_handlers)); | 208 new FactoryForMain(profile_io_data, |
| 209 protocol_handlers, |
| 210 protocol_interceptors.Pass())); |
201 } | 211 } |
202 | 212 |
203 // static | 213 // static |
204 ChromeURLRequestContextGetter* | 214 ChromeURLRequestContextGetter* |
205 ChromeURLRequestContextGetter::CreateForMedia( | 215 ChromeURLRequestContextGetter::CreateForMedia( |
206 Profile* profile, const ProfileIOData* profile_io_data) { | 216 Profile* profile, const ProfileIOData* profile_io_data) { |
207 return new ChromeURLRequestContextGetter( | 217 return new ChromeURLRequestContextGetter( |
208 new FactoryForMedia(profile_io_data)); | 218 new FactoryForMedia(profile_io_data)); |
209 } | 219 } |
210 | 220 |
211 // static | 221 // static |
212 ChromeURLRequestContextGetter* | 222 ChromeURLRequestContextGetter* |
213 ChromeURLRequestContextGetter::CreateForExtensions( | 223 ChromeURLRequestContextGetter::CreateForExtensions( |
214 Profile* profile, const ProfileIOData* profile_io_data) { | 224 Profile* profile, const ProfileIOData* profile_io_data) { |
215 return new ChromeURLRequestContextGetter( | 225 return new ChromeURLRequestContextGetter( |
216 new FactoryForExtensions(profile_io_data)); | 226 new FactoryForExtensions(profile_io_data)); |
217 } | 227 } |
218 | 228 |
219 // static | 229 // static |
220 ChromeURLRequestContextGetter* | 230 ChromeURLRequestContextGetter* |
221 ChromeURLRequestContextGetter::CreateForIsolatedApp( | 231 ChromeURLRequestContextGetter::CreateForIsolatedApp( |
222 Profile* profile, | 232 Profile* profile, |
223 const ProfileIOData* profile_io_data, | 233 const ProfileIOData* profile_io_data, |
224 const StoragePartitionDescriptor& partition_descriptor, | 234 const StoragePartitionDescriptor& partition_descriptor, |
225 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 235 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
226 protocol_handler_interceptor, | 236 protocol_handler_interceptor, |
227 content::ProtocolHandlerMap* protocol_handlers) { | 237 content::ProtocolHandlerMap* protocol_handlers, |
| 238 content::ProtocolHandlerScopedVector protocol_interceptors) { |
228 ChromeURLRequestContextGetter* main_context = | 239 ChromeURLRequestContextGetter* main_context = |
229 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 240 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
230 return new ChromeURLRequestContextGetter( | 241 return new ChromeURLRequestContextGetter( |
231 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, | 242 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, |
232 main_context, | 243 main_context, |
233 protocol_handler_interceptor.Pass(), | 244 protocol_handler_interceptor.Pass(), |
234 protocol_handlers)); | 245 protocol_handlers, |
| 246 protocol_interceptors.Pass())); |
235 } | 247 } |
236 | 248 |
237 // static | 249 // static |
238 ChromeURLRequestContextGetter* | 250 ChromeURLRequestContextGetter* |
239 ChromeURLRequestContextGetter::CreateForIsolatedMedia( | 251 ChromeURLRequestContextGetter::CreateForIsolatedMedia( |
240 Profile* profile, | 252 Profile* profile, |
241 ChromeURLRequestContextGetter* app_context, | 253 ChromeURLRequestContextGetter* app_context, |
242 const ProfileIOData* profile_io_data, | 254 const ProfileIOData* profile_io_data, |
243 const StoragePartitionDescriptor& partition_descriptor) { | 255 const StoragePartitionDescriptor& partition_descriptor) { |
244 return new ChromeURLRequestContextGetter( | 256 return new ChromeURLRequestContextGetter( |
(...skipping 12 matching lines...) Expand all Loading... |
257 | 269 |
258 ChromeURLRequestContext::~ChromeURLRequestContext() { | 270 ChromeURLRequestContext::~ChromeURLRequestContext() { |
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
260 } | 272 } |
261 | 273 |
262 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | 274 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { |
263 URLRequestContext::CopyFrom(other); | 275 URLRequestContext::CopyFrom(other); |
264 | 276 |
265 // Copy ChromeURLRequestContext parameters. | 277 // Copy ChromeURLRequestContext parameters. |
266 } | 278 } |
OLD | NEW |