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