| 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/profiles/profile_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 return IsHandledProtocol(url.scheme()); | 359 return IsHandledProtocol(url.scheme()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 content::ResourceContext* ProfileIOData::GetResourceContext() const { | 362 content::ResourceContext* ProfileIOData::GetResourceContext() const { |
| 363 return resource_context_.get(); | 363 return resource_context_.get(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 ChromeURLDataManagerBackend* | 366 ChromeURLDataManagerBackend* |
| 367 ProfileIOData::GetChromeURLDataManagerBackend() const { | 367 ProfileIOData::GetChromeURLDataManagerBackend() const { |
| 368 LazyInitialize(); | 368 DCHECK(initialized_); |
| 369 return chrome_url_data_manager_backend_.get(); | 369 return chrome_url_data_manager_backend_.get(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 ChromeURLRequestContext* | 372 ChromeURLRequestContext* |
| 373 ProfileIOData::GetMainRequestContext() const { | |
| 374 LazyInitialize(); | |
| 375 return main_request_context_.get(); | |
| 376 } | |
| 377 | |
| 378 ChromeURLRequestContext* | |
| 379 ProfileIOData::GetMediaRequestContext() const { | 373 ProfileIOData::GetMediaRequestContext() const { |
| 380 LazyInitialize(); | 374 DCHECK(initialized_); |
| 381 ChromeURLRequestContext* context = | 375 ChromeURLRequestContext* context = |
| 382 AcquireMediaRequestContext(); | 376 AcquireMediaRequestContext(); |
| 383 DCHECK(context); | 377 DCHECK(context); |
| 384 return context; | 378 return context; |
| 385 } | 379 } |
| 386 | 380 |
| 387 ChromeURLRequestContext* | 381 ChromeURLRequestContext* |
| 388 ProfileIOData::GetExtensionsRequestContext() const { | 382 ProfileIOData::GetExtensionsRequestContext() const { |
| 389 LazyInitialize(); | 383 DCHECK(initialized_); |
| 390 return extensions_request_context_.get(); | 384 return extensions_request_context_.get(); |
| 391 } | 385 } |
| 392 | 386 |
| 393 ChromeURLRequestContext* | 387 ChromeURLRequestContext* |
| 394 ProfileIOData::GetIsolatedAppRequestContext( | 388 ProfileIOData::GetIsolatedAppRequestContext( |
| 395 ChromeURLRequestContext* main_context, | 389 ChromeURLRequestContext* main_context, |
| 396 const StoragePartitionDescriptor& partition_descriptor, | 390 const StoragePartitionDescriptor& partition_descriptor, |
| 397 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 391 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 398 protocol_handler_interceptor) const { | 392 protocol_handler_interceptor, |
| 399 LazyInitialize(); | 393 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 394 blob_protocol_handler, |
| 395 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 396 file_system_protocol_handler, |
| 397 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 398 developer_protocol_handler) const { |
| 399 DCHECK(initialized_); |
| 400 ChromeURLRequestContext* context = NULL; | 400 ChromeURLRequestContext* context = NULL; |
| 401 if (ContainsKey(app_request_context_map_, partition_descriptor)) { | 401 if (ContainsKey(app_request_context_map_, partition_descriptor)) { |
| 402 context = app_request_context_map_[partition_descriptor]; | 402 context = app_request_context_map_[partition_descriptor]; |
| 403 } else { | 403 } else { |
| 404 context = AcquireIsolatedAppRequestContext( | 404 context = AcquireIsolatedAppRequestContext( |
| 405 main_context, partition_descriptor, | 405 main_context, partition_descriptor, protocol_handler_interceptor.Pass(), |
| 406 protocol_handler_interceptor.Pass()); | 406 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
| 407 developer_protocol_handler.Pass()); |
| 407 app_request_context_map_[partition_descriptor] = context; | 408 app_request_context_map_[partition_descriptor] = context; |
| 408 } | 409 } |
| 409 DCHECK(context); | 410 DCHECK(context); |
| 410 return context; | 411 return context; |
| 411 } | 412 } |
| 412 | 413 |
| 413 ChromeURLRequestContext* | 414 ChromeURLRequestContext* |
| 414 ProfileIOData::GetIsolatedMediaRequestContext( | 415 ProfileIOData::GetIsolatedMediaRequestContext( |
| 415 ChromeURLRequestContext* app_context, | 416 ChromeURLRequestContext* app_context, |
| 416 const StoragePartitionDescriptor& partition_descriptor) const { | 417 const StoragePartitionDescriptor& partition_descriptor) const { |
| 417 LazyInitialize(); | 418 DCHECK(initialized_); |
| 418 ChromeURLRequestContext* context = NULL; | 419 ChromeURLRequestContext* context = NULL; |
| 419 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { | 420 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { |
| 420 context = isolated_media_request_context_map_[partition_descriptor]; | 421 context = isolated_media_request_context_map_[partition_descriptor]; |
| 421 } else { | 422 } else { |
| 422 context = AcquireIsolatedMediaRequestContext(app_context, | 423 context = AcquireIsolatedMediaRequestContext(app_context, |
| 423 partition_descriptor); | 424 partition_descriptor); |
| 424 isolated_media_request_context_map_[partition_descriptor] = context; | 425 isolated_media_request_context_map_[partition_descriptor] = context; |
| 425 } | 426 } |
| 426 DCHECK(context); | 427 DCHECK(context); |
| 427 return context; | 428 return context; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 482 |
| 482 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) | 483 ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) |
| 483 : io_data_(io_data), | 484 : io_data_(io_data), |
| 484 host_resolver_(NULL), | 485 host_resolver_(NULL), |
| 485 request_context_(NULL) { | 486 request_context_(NULL) { |
| 486 DCHECK(io_data); | 487 DCHECK(io_data); |
| 487 } | 488 } |
| 488 | 489 |
| 489 ProfileIOData::ResourceContext::~ResourceContext() {} | 490 ProfileIOData::ResourceContext::~ResourceContext() {} |
| 490 | 491 |
| 491 void ProfileIOData::ResourceContext::EnsureInitialized() { | |
| 492 io_data_->LazyInitialize(); | |
| 493 } | |
| 494 | |
| 495 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { | 492 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { |
| 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 497 EnsureInitialized(); | 494 DCHECK(io_data_->initialized_); |
| 498 return host_resolver_; | 495 return host_resolver_; |
| 499 } | 496 } |
| 500 | 497 |
| 501 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { | 498 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { |
| 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 503 EnsureInitialized(); | 500 DCHECK(io_data_->initialized_); |
| 504 return request_context_; | 501 return request_context_; |
| 505 } | 502 } |
| 506 | 503 |
| 507 // static | 504 // static |
| 508 std::string ProfileIOData::GetSSLSessionCacheShard() { | 505 std::string ProfileIOData::GetSSLSessionCacheShard() { |
| 509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 510 // The SSL session cache is partitioned by setting a string. This returns a | 507 // The SSL session cache is partitioned by setting a string. This returns a |
| 511 // unique string to partition the SSL session cache. Each time we create a | 508 // unique string to partition the SSL session cache. Each time we create a |
| 512 // new profile, we'll get a fresh SSL session cache which is separate from | 509 // new profile, we'll get a fresh SSL session cache which is separate from |
| 513 // the other profiles. | 510 // the other profiles. |
| 514 static unsigned ssl_session_cache_instance = 0; | 511 static unsigned ssl_session_cache_instance = 0; |
| 515 return StringPrintf("profile/%u", ssl_session_cache_instance++); | 512 return StringPrintf("profile/%u", ssl_session_cache_instance++); |
| 516 } | 513 } |
| 517 | 514 |
| 518 void ProfileIOData::LazyInitialize() const { | 515 ChromeURLRequestContext* ProfileIOData::GetMainRequestContext( |
| 516 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 517 blob_protocol_handler, |
| 518 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 519 file_system_protocol_handler, |
| 520 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 521 developer_protocol_handler) const { |
| 519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 520 if (initialized_) | 523 DCHECK(!initialized_); |
| 521 return; | |
| 522 | 524 |
| 523 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. | 525 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. |
| 524 CHECK(initialized_on_UI_thread_); | 526 CHECK(initialized_on_UI_thread_); |
| 525 | 527 |
| 526 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. | 528 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. |
| 527 CHECK(profile_params_.get()); | 529 CHECK(profile_params_.get()); |
| 528 | 530 |
| 529 IOThread* const io_thread = profile_params_->io_thread; | 531 IOThread* const io_thread = profile_params_->io_thread; |
| 530 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 532 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 531 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 533 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 extension_info_map_ = profile_params_->extension_info_map; | 585 extension_info_map_ = profile_params_->extension_info_map; |
| 584 | 586 |
| 585 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); | 587 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); |
| 586 resource_context_->request_context_ = main_request_context_.get(); | 588 resource_context_->request_context_ = main_request_context_.get(); |
| 587 | 589 |
| 588 if (profile_params_->resource_prefetch_predictor_observer_.get()) { | 590 if (profile_params_->resource_prefetch_predictor_observer_.get()) { |
| 589 resource_prefetch_predictor_observer_.reset( | 591 resource_prefetch_predictor_observer_.reset( |
| 590 profile_params_->resource_prefetch_predictor_observer_.release()); | 592 profile_params_->resource_prefetch_predictor_observer_.release()); |
| 591 } | 593 } |
| 592 | 594 |
| 593 LazyInitializeInternal(profile_params_.get()); | 595 LazyInitializeInternal(profile_params_.get(), |
| 596 blob_protocol_handler.Pass(), |
| 597 file_system_protocol_handler.Pass(), |
| 598 developer_protocol_handler.Pass()); |
| 594 | 599 |
| 595 profile_params_.reset(); | 600 profile_params_.reset(); |
| 596 initialized_ = true; | 601 initialized_ = true; |
| 602 |
| 603 return main_request_context_.get(); |
| 597 } | 604 } |
| 598 | 605 |
| 599 void ProfileIOData::ApplyProfileParamsToContext( | 606 void ProfileIOData::ApplyProfileParamsToContext( |
| 600 ChromeURLRequestContext* context) const { | 607 ChromeURLRequestContext* context) const { |
| 601 context->set_is_incognito(is_incognito()); | 608 context->set_is_incognito(is_incognito()); |
| 602 context->set_http_user_agent_settings( | 609 context->set_http_user_agent_settings( |
| 603 chrome_http_user_agent_settings_.get()); | 610 chrome_http_user_agent_settings_.get()); |
| 604 context->set_ssl_config_service(profile_params_->ssl_config_service); | 611 context->set_ssl_config_service(profile_params_->ssl_config_service); |
| 605 } | 612 } |
| 606 | 613 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 void ProfileIOData::SetCookieSettingsForTesting( | 735 void ProfileIOData::SetCookieSettingsForTesting( |
| 729 CookieSettings* cookie_settings) { | 736 CookieSettings* cookie_settings) { |
| 730 DCHECK(!cookie_settings_.get()); | 737 DCHECK(!cookie_settings_.get()); |
| 731 cookie_settings_ = cookie_settings; | 738 cookie_settings_ = cookie_settings; |
| 732 } | 739 } |
| 733 | 740 |
| 734 void ProfileIOData::set_signin_names_for_testing( | 741 void ProfileIOData::set_signin_names_for_testing( |
| 735 SigninNamesOnIOThread* signin_names) { | 742 SigninNamesOnIOThread* signin_names) { |
| 736 signin_names_.reset(signin_names); | 743 signin_names_.reset(signin_names); |
| 737 } | 744 } |
| OLD | NEW |