| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
| 37 // Helper factories | 37 // Helper factories |
| 38 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
| 39 | 39 |
| 40 // Factory that creates the main ChromeURLRequestContext. | 40 // Factory that creates the main ChromeURLRequestContext. |
| 41 class FactoryForMain : public ChromeURLRequestContextFactory { | 41 class FactoryForMain : public ChromeURLRequestContextFactory { |
| 42 public: | 42 public: |
| 43 explicit FactoryForMain(const ProfileIOData* profile_io_data) | 43 FactoryForMain( |
| 44 : profile_io_data_(profile_io_data) {} | 44 const ProfileIOData* profile_io_data, |
| 45 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 46 blob_protocol_handler, |
| 47 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 48 file_system_protocol_handler, |
| 49 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 50 developer_protocol_handler) |
| 51 : profile_io_data_(profile_io_data), |
| 52 blob_protocol_handler_(blob_protocol_handler.Pass()), |
| 53 file_system_protocol_handler_(file_system_protocol_handler.Pass()), |
| 54 developer_protocol_handler_(developer_protocol_handler.Pass()) {} |
| 45 | 55 |
| 46 virtual ChromeURLRequestContext* Create() OVERRIDE { | 56 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| 57 profile_io_data_->Init(blob_protocol_handler_.Pass(), |
| 58 file_system_protocol_handler_.Pass(), |
| 59 developer_protocol_handler_.Pass()); |
| 47 return profile_io_data_->GetMainRequestContext(); | 60 return profile_io_data_->GetMainRequestContext(); |
| 48 } | 61 } |
| 49 | 62 |
| 50 private: | 63 private: |
| 51 const ProfileIOData* const profile_io_data_; | 64 const ProfileIOData* const profile_io_data_; |
| 65 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler_; |
| 66 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 67 file_system_protocol_handler_; |
| 68 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 69 developer_protocol_handler_; |
| 52 }; | 70 }; |
| 53 | 71 |
| 54 // Factory that creates the ChromeURLRequestContext for extensions. | 72 // Factory that creates the ChromeURLRequestContext for extensions. |
| 55 class FactoryForExtensions : public ChromeURLRequestContextFactory { | 73 class FactoryForExtensions : public ChromeURLRequestContextFactory { |
| 56 public: | 74 public: |
| 57 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) | 75 explicit FactoryForExtensions(const ProfileIOData* profile_io_data) |
| 58 : profile_io_data_(profile_io_data) {} | 76 : profile_io_data_(profile_io_data) {} |
| 59 | 77 |
| 60 virtual ChromeURLRequestContext* Create() OVERRIDE { | 78 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| 61 return profile_io_data_->GetExtensionsRequestContext(); | 79 return profile_io_data_->GetExtensionsRequestContext(); |
| 62 } | 80 } |
| 63 | 81 |
| 64 private: | 82 private: |
| 65 const ProfileIOData* const profile_io_data_; | 83 const ProfileIOData* const profile_io_data_; |
| 66 }; | 84 }; |
| 67 | 85 |
| 68 // Factory that creates the ChromeURLRequestContext for a given isolated app. | 86 // Factory that creates the ChromeURLRequestContext for a given isolated app. |
| 69 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | 87 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { |
| 70 public: | 88 public: |
| 71 FactoryForIsolatedApp( | 89 FactoryForIsolatedApp( |
| 72 const ProfileIOData* profile_io_data, | 90 const ProfileIOData* profile_io_data, |
| 73 const StoragePartitionDescriptor& partition_descriptor, | 91 const StoragePartitionDescriptor& partition_descriptor, |
| 74 ChromeURLRequestContextGetter* main_context, | 92 ChromeURLRequestContextGetter* main_context, |
| 75 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 93 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 76 protocol_handler_interceptor) | 94 protocol_handler_interceptor, |
| 95 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 96 blob_protocol_handler, |
| 97 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 98 file_system_protocol_handler, |
| 99 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 100 developer_protocol_handler) |
| 77 : profile_io_data_(profile_io_data), | 101 : profile_io_data_(profile_io_data), |
| 78 partition_descriptor_(partition_descriptor), | 102 partition_descriptor_(partition_descriptor), |
| 79 main_request_context_getter_(main_context), | 103 main_request_context_getter_(main_context), |
| 80 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) {} | 104 protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), |
| 105 blob_protocol_handler_(blob_protocol_handler.Pass()), |
| 106 file_system_protocol_handler_(file_system_protocol_handler.Pass()), |
| 107 developer_protocol_handler_(developer_protocol_handler.Pass()) {} |
| 81 | 108 |
| 82 virtual ChromeURLRequestContext* Create() OVERRIDE { | 109 virtual ChromeURLRequestContext* Create() OVERRIDE { |
| 83 // We will copy most of the state from the main request context. | 110 // We will copy most of the state from the main request context. |
| 84 // | 111 // |
| 85 // Note that this factory is one-shot. After Create() is called once, the | 112 // Note that this factory is one-shot. After Create() is called once, the |
| 86 // factory is actually destroyed. Thus it is safe to destructively pass | 113 // factory is actually destroyed. Thus it is safe to destructively pass |
| 87 // state onwards. | 114 // state onwards. |
| 88 return profile_io_data_->GetIsolatedAppRequestContext( | 115 return profile_io_data_->GetIsolatedAppRequestContext( |
| 89 main_request_context_getter_->GetIOContext(), partition_descriptor_, | 116 main_request_context_getter_->GetIOContext(), partition_descriptor_, |
| 90 protocol_handler_interceptor_.Pass()); | 117 protocol_handler_interceptor_.Pass(), blob_protocol_handler_.Pass(), |
| 118 file_system_protocol_handler_.Pass(), |
| 119 developer_protocol_handler_.Pass()); |
| 91 } | 120 } |
| 92 | 121 |
| 93 private: | 122 private: |
| 94 const ProfileIOData* const profile_io_data_; | 123 const ProfileIOData* const profile_io_data_; |
| 95 const StoragePartitionDescriptor partition_descriptor_; | 124 const StoragePartitionDescriptor partition_descriptor_; |
| 96 scoped_refptr<ChromeURLRequestContextGetter> | 125 scoped_refptr<ChromeURLRequestContextGetter> |
| 97 main_request_context_getter_; | 126 main_request_context_getter_; |
| 98 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 127 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 99 protocol_handler_interceptor_; | 128 protocol_handler_interceptor_; |
| 129 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 130 blob_protocol_handler_; |
| 131 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 132 file_system_protocol_handler_; |
| 133 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 134 developer_protocol_handler_; |
| 100 }; | 135 }; |
| 101 | 136 |
| 102 // Factory that creates the media ChromeURLRequestContext for a given isolated | 137 // Factory that creates the media ChromeURLRequestContext for a given isolated |
| 103 // app. The media context is based on the corresponding isolated app's context. | 138 // app. The media context is based on the corresponding isolated app's context. |
| 104 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { | 139 class FactoryForIsolatedMedia : public ChromeURLRequestContextFactory { |
| 105 public: | 140 public: |
| 106 FactoryForIsolatedMedia( | 141 FactoryForIsolatedMedia( |
| 107 const ProfileIOData* profile_io_data, | 142 const ProfileIOData* profile_io_data, |
| 108 const StoragePartitionDescriptor& partition_descriptor, | 143 const StoragePartitionDescriptor& partition_descriptor, |
| 109 ChromeURLRequestContextGetter* app_context) | 144 ChromeURLRequestContextGetter* app_context) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 210 } |
| 176 | 211 |
| 177 scoped_refptr<base::SingleThreadTaskRunner> | 212 scoped_refptr<base::SingleThreadTaskRunner> |
| 178 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { | 213 ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 179 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 214 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 180 } | 215 } |
| 181 | 216 |
| 182 // static | 217 // static |
| 183 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal( | 218 ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal( |
| 184 Profile* profile, | 219 Profile* profile, |
| 185 const ProfileIOData* profile_io_data) { | 220 const ProfileIOData* profile_io_data, |
| 221 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 222 blob_protocol_handler, |
| 223 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 224 file_system_protocol_handler, |
| 225 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 226 developer_protocol_handler) { |
| 186 DCHECK(!profile->IsOffTheRecord()); | 227 DCHECK(!profile->IsOffTheRecord()); |
| 187 return new ChromeURLRequestContextGetter( | 228 return new ChromeURLRequestContextGetter( |
| 188 new FactoryForMain(profile_io_data)); | 229 new FactoryForMain(profile_io_data, |
| 230 blob_protocol_handler.Pass(), |
| 231 file_system_protocol_handler.Pass(), |
| 232 developer_protocol_handler.Pass())); |
| 189 } | 233 } |
| 190 | 234 |
| 191 // static | 235 // static |
| 192 ChromeURLRequestContextGetter* | 236 ChromeURLRequestContextGetter* |
| 193 ChromeURLRequestContextGetter::CreateOriginalForMedia( | 237 ChromeURLRequestContextGetter::CreateOriginalForMedia( |
| 194 Profile* profile, const ProfileIOData* profile_io_data) { | 238 Profile* profile, const ProfileIOData* profile_io_data) { |
| 195 DCHECK(!profile->IsOffTheRecord()); | 239 DCHECK(!profile->IsOffTheRecord()); |
| 196 return new ChromeURLRequestContextGetter( | 240 return new ChromeURLRequestContextGetter( |
| 197 new FactoryForMedia(profile_io_data)); | 241 new FactoryForMedia(profile_io_data)); |
| 198 } | 242 } |
| 199 | 243 |
| 200 // static | 244 // static |
| 201 ChromeURLRequestContextGetter* | 245 ChromeURLRequestContextGetter* |
| 202 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 246 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
| 203 Profile* profile, const ProfileIOData* profile_io_data) { | 247 Profile* profile, const ProfileIOData* profile_io_data) { |
| 204 DCHECK(!profile->IsOffTheRecord()); | 248 DCHECK(!profile->IsOffTheRecord()); |
| 205 return new ChromeURLRequestContextGetter( | 249 return new ChromeURLRequestContextGetter( |
| 206 new FactoryForExtensions(profile_io_data)); | 250 new FactoryForExtensions(profile_io_data)); |
| 207 } | 251 } |
| 208 | 252 |
| 209 // static | 253 // static |
| 210 ChromeURLRequestContextGetter* | 254 ChromeURLRequestContextGetter* |
| 211 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 255 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
| 212 Profile* profile, | 256 Profile* profile, |
| 213 const ProfileIOData* profile_io_data, | 257 const ProfileIOData* profile_io_data, |
| 214 const StoragePartitionDescriptor& partition_descriptor, | 258 const StoragePartitionDescriptor& partition_descriptor, |
| 215 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 259 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 216 protocol_handler_interceptor) { | 260 protocol_handler_interceptor, |
| 261 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 262 blob_protocol_handler, |
| 263 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 264 file_system_protocol_handler, |
| 265 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 266 developer_protocol_handler) { |
| 217 DCHECK(!profile->IsOffTheRecord()); | 267 DCHECK(!profile->IsOffTheRecord()); |
| 218 ChromeURLRequestContextGetter* main_context = | 268 ChromeURLRequestContextGetter* main_context = |
| 219 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 269 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
| 220 return new ChromeURLRequestContextGetter( | 270 return new ChromeURLRequestContextGetter( |
| 221 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, | 271 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, |
| 222 main_context, protocol_handler_interceptor.Pass())); | 272 main_context, protocol_handler_interceptor.Pass(), |
| 273 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
| 274 developer_protocol_handler.Pass())); |
| 223 } | 275 } |
| 224 | 276 |
| 225 // static | 277 // static |
| 226 ChromeURLRequestContextGetter* | 278 ChromeURLRequestContextGetter* |
| 227 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( | 279 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( |
| 228 Profile* profile, | 280 Profile* profile, |
| 229 ChromeURLRequestContextGetter* app_context, | 281 ChromeURLRequestContextGetter* app_context, |
| 230 const ProfileIOData* profile_io_data, | 282 const ProfileIOData* profile_io_data, |
| 231 const StoragePartitionDescriptor& partition_descriptor) { | 283 const StoragePartitionDescriptor& partition_descriptor) { |
| 232 DCHECK(!profile->IsOffTheRecord()); | 284 DCHECK(!profile->IsOffTheRecord()); |
| 233 return new ChromeURLRequestContextGetter( | 285 return new ChromeURLRequestContextGetter( |
| 234 new FactoryForIsolatedMedia( | 286 new FactoryForIsolatedMedia( |
| 235 profile_io_data, partition_descriptor, app_context)); | 287 profile_io_data, partition_descriptor, app_context)); |
| 236 } | 288 } |
| 237 | 289 |
| 238 // static | 290 // static |
| 239 ChromeURLRequestContextGetter* | 291 ChromeURLRequestContextGetter* |
| 240 ChromeURLRequestContextGetter::CreateOffTheRecord( | 292 ChromeURLRequestContextGetter::CreateOffTheRecord( |
| 241 Profile* profile, const ProfileIOData* profile_io_data) { | 293 Profile* profile, |
| 294 const ProfileIOData* profile_io_data, |
| 295 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 296 blob_protocol_handler, |
| 297 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 298 file_system_protocol_handler, |
| 299 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 300 developer_protocol_handler) { |
| 242 DCHECK(profile->IsOffTheRecord()); | 301 DCHECK(profile->IsOffTheRecord()); |
| 243 return new ChromeURLRequestContextGetter( | 302 return new ChromeURLRequestContextGetter( |
| 244 new FactoryForMain(profile_io_data)); | 303 new FactoryForMain(profile_io_data, |
| 304 blob_protocol_handler.Pass(), |
| 305 file_system_protocol_handler.Pass(), |
| 306 developer_protocol_handler.Pass())); |
| 245 } | 307 } |
| 246 | 308 |
| 247 // static | 309 // static |
| 248 ChromeURLRequestContextGetter* | 310 ChromeURLRequestContextGetter* |
| 249 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( | 311 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
| 250 Profile* profile, const ProfileIOData* profile_io_data) { | 312 Profile* profile, const ProfileIOData* profile_io_data) { |
| 251 DCHECK(profile->IsOffTheRecord()); | 313 DCHECK(profile->IsOffTheRecord()); |
| 252 return new ChromeURLRequestContextGetter( | 314 return new ChromeURLRequestContextGetter( |
| 253 new FactoryForExtensions(profile_io_data)); | 315 new FactoryForExtensions(profile_io_data)); |
| 254 } | 316 } |
| 255 | 317 |
| 256 // static | 318 // static |
| 257 ChromeURLRequestContextGetter* | 319 ChromeURLRequestContextGetter* |
| 258 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( | 320 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( |
| 259 Profile* profile, | 321 Profile* profile, |
| 260 const ProfileIOData* profile_io_data, | 322 const ProfileIOData* profile_io_data, |
| 261 const StoragePartitionDescriptor& partition_descriptor, | 323 const StoragePartitionDescriptor& partition_descriptor, |
| 262 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 324 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 263 protocol_handler_interceptor) { | 325 protocol_handler_interceptor, |
| 326 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 327 blob_protocol_handler, |
| 328 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 329 file_system_protocol_handler, |
| 330 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 331 developer_protocol_handler) { |
| 264 DCHECK(profile->IsOffTheRecord()); | 332 DCHECK(profile->IsOffTheRecord()); |
| 265 ChromeURLRequestContextGetter* main_context = | 333 ChromeURLRequestContextGetter* main_context = |
| 266 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | 334 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); |
| 267 return new ChromeURLRequestContextGetter( | 335 return new ChromeURLRequestContextGetter( |
| 268 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, | 336 new FactoryForIsolatedApp(profile_io_data, partition_descriptor, |
| 269 main_context, protocol_handler_interceptor.Pass())); | 337 main_context, protocol_handler_interceptor.Pass(), |
| 338 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
| 339 developer_protocol_handler.Pass())); |
| 270 } | 340 } |
| 271 | 341 |
| 272 // ---------------------------------------------------------------------------- | 342 // ---------------------------------------------------------------------------- |
| 273 // ChromeURLRequestContext | 343 // ChromeURLRequestContext |
| 274 // ---------------------------------------------------------------------------- | 344 // ---------------------------------------------------------------------------- |
| 275 | 345 |
| 276 ChromeURLRequestContext::ChromeURLRequestContext( | 346 ChromeURLRequestContext::ChromeURLRequestContext( |
| 277 ContextType type, | 347 ContextType type, |
| 278 chrome_browser_net::LoadTimeStats* load_time_stats) | 348 chrome_browser_net::LoadTimeStats* load_time_stats) |
| 279 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 349 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 280 load_time_stats_(load_time_stats) { | 350 load_time_stats_(load_time_stats) { |
| 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 282 if (load_time_stats_) | 352 if (load_time_stats_) |
| 283 load_time_stats_->RegisterURLRequestContext(this, type); | 353 load_time_stats_->RegisterURLRequestContext(this, type); |
| 284 } | 354 } |
| 285 | 355 |
| 286 ChromeURLRequestContext::~ChromeURLRequestContext() { | 356 ChromeURLRequestContext::~ChromeURLRequestContext() { |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 288 if (load_time_stats_) | 358 if (load_time_stats_) |
| 289 load_time_stats_->UnregisterURLRequestContext(this); | 359 load_time_stats_->UnregisterURLRequestContext(this); |
| 290 } | 360 } |
| 291 | 361 |
| 292 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | 362 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { |
| 293 URLRequestContext::CopyFrom(other); | 363 URLRequestContext::CopyFrom(other); |
| 294 | 364 |
| 295 // Copy ChromeURLRequestContext parameters. | 365 // Copy ChromeURLRequestContext parameters. |
| 296 } | 366 } |
| OLD | NEW |