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