| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 void ProfileIOData::ResourceContext::EnsureInitialized() { |
| 492 io_data_->LazyInitialize(); | 493 DCHECK(io_data_->initialized_); |
| 493 } | 494 } |
| 494 | 495 |
| 495 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { | 496 net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { |
| 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 497 EnsureInitialized(); | 498 EnsureInitialized(); |
| 498 return host_resolver_; | 499 return host_resolver_; |
| 499 } | 500 } |
| 500 | 501 |
| 501 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { | 502 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { |
| 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 503 EnsureInitialized(); | 504 EnsureInitialized(); |
| 504 return request_context_; | 505 return request_context_; |
| 505 } | 506 } |
| 506 | 507 |
| 507 // static | 508 // static |
| 508 std::string ProfileIOData::GetSSLSessionCacheShard() { | 509 std::string ProfileIOData::GetSSLSessionCacheShard() { |
| 509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 510 // The SSL session cache is partitioned by setting a string. This returns a | 511 // 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 | 512 // 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 | 513 // new profile, we'll get a fresh SSL session cache which is separate from |
| 513 // the other profiles. | 514 // the other profiles. |
| 514 static unsigned ssl_session_cache_instance = 0; | 515 static unsigned ssl_session_cache_instance = 0; |
| 515 return StringPrintf("profile/%u", ssl_session_cache_instance++); | 516 return StringPrintf("profile/%u", ssl_session_cache_instance++); |
| 516 } | 517 } |
| 517 | 518 |
| 518 void ProfileIOData::LazyInitialize() const { | 519 ChromeURLRequestContext* ProfileIOData::GetMainRequestContext( |
| 520 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 521 blob_protocol_handler, |
| 522 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 523 file_system_protocol_handler, |
| 524 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 525 developer_protocol_handler) const { |
| 519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 520 if (initialized_) | 527 DCHECK(!initialized_); |
| 521 return; | |
| 522 | 528 |
| 523 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. | 529 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. |
| 524 CHECK(initialized_on_UI_thread_); | 530 CHECK(initialized_on_UI_thread_); |
| 525 | 531 |
| 526 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. | 532 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. |
| 527 CHECK(profile_params_.get()); | 533 CHECK(profile_params_.get()); |
| 528 | 534 |
| 529 IOThread* const io_thread = profile_params_->io_thread; | 535 IOThread* const io_thread = profile_params_->io_thread; |
| 530 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 536 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 531 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 537 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; | 589 extension_info_map_ = profile_params_->extension_info_map; |
| 584 | 590 |
| 585 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); | 591 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); |
| 586 resource_context_->request_context_ = main_request_context_.get(); | 592 resource_context_->request_context_ = main_request_context_.get(); |
| 587 | 593 |
| 588 if (profile_params_->resource_prefetch_predictor_observer_.get()) { | 594 if (profile_params_->resource_prefetch_predictor_observer_.get()) { |
| 589 resource_prefetch_predictor_observer_.reset( | 595 resource_prefetch_predictor_observer_.reset( |
| 590 profile_params_->resource_prefetch_predictor_observer_.release()); | 596 profile_params_->resource_prefetch_predictor_observer_.release()); |
| 591 } | 597 } |
| 592 | 598 |
| 593 LazyInitializeInternal(profile_params_.get()); | 599 LazyInitializeInternal(profile_params_.get(), |
| 600 blob_protocol_handler.Pass(), |
| 601 file_system_protocol_handler.Pass(), |
| 602 developer_protocol_handler.Pass()); |
| 594 | 603 |
| 595 profile_params_.reset(); | 604 profile_params_.reset(); |
| 596 initialized_ = true; | 605 initialized_ = true; |
| 606 |
| 607 return main_request_context_.get(); |
| 597 } | 608 } |
| 598 | 609 |
| 599 void ProfileIOData::ApplyProfileParamsToContext( | 610 void ProfileIOData::ApplyProfileParamsToContext( |
| 600 ChromeURLRequestContext* context) const { | 611 ChromeURLRequestContext* context) const { |
| 601 context->set_is_incognito(is_incognito()); | 612 context->set_is_incognito(is_incognito()); |
| 602 context->set_http_user_agent_settings( | 613 context->set_http_user_agent_settings( |
| 603 chrome_http_user_agent_settings_.get()); | 614 chrome_http_user_agent_settings_.get()); |
| 604 context->set_ssl_config_service(profile_params_->ssl_config_service); | 615 context->set_ssl_config_service(profile_params_->ssl_config_service); |
| 605 } | 616 } |
| 606 | 617 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 void ProfileIOData::SetCookieSettingsForTesting( | 739 void ProfileIOData::SetCookieSettingsForTesting( |
| 729 CookieSettings* cookie_settings) { | 740 CookieSettings* cookie_settings) { |
| 730 DCHECK(!cookie_settings_.get()); | 741 DCHECK(!cookie_settings_.get()); |
| 731 cookie_settings_ = cookie_settings; | 742 cookie_settings_ = cookie_settings; |
| 732 } | 743 } |
| 733 | 744 |
| 734 void ProfileIOData::set_signin_names_for_testing( | 745 void ProfileIOData::set_signin_names_for_testing( |
| 735 SigninNamesOnIOThread* signin_names) { | 746 SigninNamesOnIOThread* signin_names) { |
| 736 signin_names_.reset(signin_names); | 747 signin_names_.reset(signin_names); |
| 737 } | 748 } |
| OLD | NEW |