profile_io_data.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 3// found in the LICENSE file. 4 5#include "chrome/browser/profiles/profile_io_data.h" 6 7#include <string> 8 9#include "base/basictypes.h" 10#include "base/bind.h" 11#include "base/bind_helpers.h" 12#include "base/callback.h" 13#include "base/command_line.h" 14#include "base/compiler_specific.h" 15#include "base/debug/alias.h" 16#include "base/logging.h" 17#include "base/path_service.h" 18#include "base/prefs/pref_service.h" 19#include "base/stl_util.h" 20#include "base/strings/string_number_conversions.h" 21#include "base/strings/string_util.h" 22#include "base/strings/stringprintf.h" 23#include "base/threading/sequenced_worker_pool.h" 24#include "chrome/browser/browser_process.h" 25#include "chrome/browser/chrome_notification_types.h" 26#include "chrome/browser/content_settings/content_settings_provider.h" 27#include "chrome/browser/content_settings/cookie_settings.h" 28#include "chrome/browser/content_settings/host_content_settings_map.h" 29#include "chrome/browser/custom_handlers/protocol_handler_registry.h" 30#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 31#include "chrome/browser/download/download_service.h" 32#include "chrome/browser/download/download_service_factory.h" 33#include "chrome/browser/extensions/extension_protocols.h" 34#include "chrome/browser/extensions/extension_resource_protocols.h" 35#include "chrome/browser/io_thread.h" 36#include "chrome/browser/media/media_device_id_salt.h" 37#include "chrome/browser/net/about_protocol_handler.h" 38#include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" 39#include "chrome/browser/net/chrome_http_user_agent_settings.h" 40#include "chrome/browser/net/chrome_net_log.h" 41#include "chrome/browser/net/chrome_network_delegate.h" 42#include "chrome/browser/net/cookie_store_util.h" 43#include "chrome/browser/net/proxy_service_factory.h" 44#include "chrome/browser/profiles/profile.h" 45#include "chrome/browser/profiles/profile_manager.h" 46#include "chrome/browser/signin/signin_names_io_thread.h" 47#include "chrome/common/chrome_paths.h" 48#include "chrome/common/chrome_switches.h" 49#include "chrome/common/net/url_fixer_upper.h" 50#include "chrome/common/pref_names.h" 51#include "chrome/common/url_constants.h" 52#include "components/startup_metric_utils/startup_metric_utils.h" 53#include "content/public/browser/browser_thread.h" 54#include "content/public/browser/host_zoom_map.h" 55#include "content/public/browser/notification_service.h" 56#include "content/public/browser/resource_context.h" 57#include "extensions/browser/extension_system.h" 58#include "extensions/browser/info_map.h" 59#include "extensions/common/constants.h" 60#include "net/base/keygen_handler.h" 61#include "net/cookies/canonical_cookie.h" 62#include "net/http/http_transaction_factory.h" 63#include "net/http/http_util.h" 64#include "net/http/transport_security_persister.h" 65#include "net/proxy/proxy_config_service_fixed.h" 66#include "net/proxy/proxy_script_fetcher_impl.h" 67#include "net/proxy/proxy_service.h" 68#include "net/ssl/client_cert_store.h" 69#include "net/ssl/server_bound_cert_service.h" 70#include "net/url_request/data_protocol_handler.h" 71#include "net/url_request/file_protocol_handler.h" 72#include "net/url_request/ftp_protocol_handler.h" 73#include "net/url_request/protocol_intercept_job_factory.h" 74#include "net/url_request/url_request.h" 75#include "net/url_request/url_request_file_job.h" 76#include "net/url_request/url_request_job_factory_impl.h" 77 78#if defined(ENABLE_CONFIGURATION_POLICY) 79#include "chrome/browser/policy/cloud/policy_header_service_factory.h" 80#include "chrome/browser/policy/policy_helpers.h" 81#include "components/policy/core/browser/url_blacklist_manager.h" 82#include "components/policy/core/common/cloud/policy_header_io_helper.h" 83#include "components/policy/core/common/cloud/policy_header_service.h" 84#include "components/policy/core/common/cloud/user_cloud_policy_manager.h" 85#endif 86 87#if defined(ENABLE_MANAGED_USERS) 88#include "chrome/browser/managed_mode/managed_mode_url_filter.h" 89#include "chrome/browser/managed_mode/managed_user_service.h" 90#include "chrome/browser/managed_mode/managed_user_service_factory.h" 91#endif 92 93#if defined(OS_CHROMEOS) 94#include "chrome/browser/chromeos/drive/drive_protocol_handler.h" 95#include "chrome/browser/chromeos/login/user.h" 96#include "chrome/browser/chromeos/login/user_manager.h" 97#include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" 98#include "chrome/browser/chromeos/policy/policy_cert_service.h" 99#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" 100#include "chrome/browser/chromeos/policy/policy_cert_verifier.h" 101#include "chrome/browser/chromeos/settings/cros_settings.h" 102#include "chromeos/dbus/cryptohome_client.h" 103#include "chromeos/dbus/dbus_thread_manager.h" 104#include "chromeos/settings/cros_settings_names.h" 105#include "crypto/nss_util.h" 106#include "crypto/nss_util_internal.h" 107#include "net/cert/multi_threaded_cert_verifier.h" 108#include "net/ssl/client_cert_store_chromeos.h" 109#endif // defined(OS_CHROMEOS) 110 111#if defined(USE_NSS) 112#include "chrome/browser/ui/crypto_module_delegate_nss.h" 113#include "net/ssl/client_cert_store_nss.h" 114#endif 115 116#if defined(OS_WIN) 117#include "net/ssl/client_cert_store_win.h" 118#endif 119 120#if defined(OS_MACOSX) 121#include "net/ssl/client_cert_store_mac.h" 122#endif 123 124using content::BrowserContext; 125using content::BrowserThread; 126using content::ResourceContext; 127 128namespace { 129 130#if defined(DEBUG_DEVTOOLS) 131bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { 132 std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); 133 bundled_path_prefix = "/" + bundled_path_prefix + "/"; 134 135 if (!url.SchemeIs(content::kChromeDevToolsScheme) || 136 url.host() != chrome::kChromeUIDevToolsHost || 137 !StartsWithASCII(url.path(), bundled_path_prefix, false)) { 138 return false; 139 } 140 141 if (!url.is_valid()) { 142 NOTREACHED(); 143 return false; 144 } 145 146 // Remove Query and Ref from URL. 147 GURL stripped_url; 148 GURL::Replacements replacements; 149 replacements.ClearQuery(); 150 replacements.ClearRef(); 151 stripped_url = url.ReplaceComponents(replacements); 152 153 std::string relative_path; 154 const std::string& spec = stripped_url.possibly_invalid_spec(); 155 const url_parse::Parsed& parsed = 156 stripped_url.parsed_for_possibly_invalid_spec(); 157 int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); 158 if (offset < static_cast<int>(spec.size())) 159 relative_path.assign(spec.substr(offset + bundled_path_prefix.length())); 160 161 // Check that |relative_path| is not an absolute path (otherwise 162 // AppendASCII() will DCHECK). The awkward use of StringType is because on 163 // some systems FilePath expects a std::string, but on others a std::wstring. 164 base::FilePath p( 165 base::FilePath::StringType(relative_path.begin(), relative_path.end())); 166 if (p.IsAbsolute()) 167 return false; 168 169 base::FilePath inspector_dir; 170 if (!PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) 171 return false; 172 173 if (inspector_dir.empty()) 174 return false; 175 176 *path = inspector_dir.AppendASCII(relative_path); 177 return true; 178} 179 180class DebugDevToolsInterceptor 181 : public net::URLRequestJobFactory::ProtocolHandler { 182 public: 183 DebugDevToolsInterceptor() {} 184 virtual ~DebugDevToolsInterceptor() {} 185 186 virtual net::URLRequestJob* MaybeCreateJob( 187 net::URLRequest* request, 188 net::NetworkDelegate* network_delegate) const OVERRIDE { 189 base::FilePath path; 190 if (IsSupportedDevToolsURL(request->url(), &path)) 191 return new net::URLRequestFileJob( 192 request, network_delegate, path, 193 content::BrowserThread::GetBlockingPool()-> 194 GetTaskRunnerWithShutdownBehavior( 195 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 196 197 return NULL; 198 } 199}; 200#endif // defined(DEBUG_DEVTOOLS) 201 202#if defined(OS_CHROMEOS) 203// The following four functions are responsible for initializing NSS for each 204// profile on ChromeOS, which has a separate NSS database and TPM slot 205// per-profile. 206// 207// Initialization basically follows these steps: 208// 1) Get some info from chromeos::UserManager about the User for this profile. 209// 2) Tell nss_util to initialize the software slot for this profile. 210// 3) Wait for the TPM module to be loaded by nss_util if it isn't already. 211// 4) Ask CryptohomeClient which TPM slot id corresponds to this profile. 212// 5) Tell nss_util to use that slot id on the TPM module. 213// 214// Some of these steps must happen on the UI thread, others must happen on the 215// IO thread: 216// UI thread IO Thread 217// 218// ProfileIOData::InitializeOnUIThread 219// | 220// chromeos::UserManager::GetUserByProfile 221// \---------------------------------------v 222// StartNSSInitOnIOThread 223// | 224// crypto::InitializeNSSForChromeOSUser 225// | 226// crypto::IsTPMTokenReady 227// | 228// StartTPMSlotInitializationOnIOThread 229// v---------------------------------------/ 230// GetTPMInfoForUserOnUIThread 231// | 232// CryptohomeClient::Pkcs11GetTpmTokenInfoForUser 233// | 234// DidGetTPMInfoForUserOnUIThread 235// \---------------------------------------v 236// crypto::InitializeTPMForChromeOSUser 237 238void DidGetTPMInfoForUserOnUIThread(const std::string& username_hash, 239 chromeos::DBusMethodCallStatus call_status, 240 const std::string& label, 241 const std::string& user_pin, 242 int slot_id) { 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 244 if (call_status == chromeos::DBUS_METHOD_CALL_FAILURE) { 245 NOTREACHED() << "dbus error getting TPM info for " << username_hash; 246 return; 247 } 248 DVLOG(1) << "Got TPM slot for " << username_hash << ": " << slot_id; 249 BrowserThread::PostTask( 250 BrowserThread::IO, 251 FROM_HERE, 252 base::Bind( 253 &crypto::InitializeTPMForChromeOSUser, username_hash, slot_id)); 254} 255 256void GetTPMInfoForUserOnUIThread(const std::string& username, 257 const std::string& username_hash) { 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 259 DVLOG(1) << "Getting TPM info from cryptohome for " 260 << " " << username << " " << username_hash; 261 chromeos::DBusThreadManager::Get() 262 ->GetCryptohomeClient() 263 ->Pkcs11GetTpmTokenInfoForUser( 264 username, 265 base::Bind(&DidGetTPMInfoForUserOnUIThread, username_hash)); 266} 267 268void StartTPMSlotInitializationOnIOThread(const std::string& username, 269 const std::string& username_hash) { 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 271 272 BrowserThread::PostTask( 273 BrowserThread::UI, 274 FROM_HERE, 275 base::Bind(&GetTPMInfoForUserOnUIThread, username, username_hash)); 276} 277 278void StartNSSInitOnIOThread(const std::string& username, 279 const std::string& username_hash, 280 const base::FilePath& path, 281 bool is_primary_user) { 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 283 DVLOG(1) << "Starting NSS init for " << username 284 << " hash:" << username_hash 285 << " is_primary_user:" << is_primary_user; 286 287 if (!crypto::InitializeNSSForChromeOSUser( 288 username, username_hash, is_primary_user, path)) { 289 // If the user already exists in nss_util's map, it is already initialized 290 // or in the process of being initialized. In either case, there's no need 291 // to do anything. 292 return; 293 } 294 295 if (crypto::IsTPMTokenEnabledForNSS()) { 296 if (crypto::IsTPMTokenReady(base::Bind( 297 &StartTPMSlotInitializationOnIOThread, username, username_hash))) { 298 StartTPMSlotInitializationOnIOThread(username, username_hash); 299 } else { 300 DVLOG(1) << "Waiting for tpm ready ..."; 301 } 302 } else { 303 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash); 304 } 305} 306#endif // defined(OS_CHROMEOS) 307 308} // namespace 309 310void ProfileIOData::InitializeOnUIThread(Profile* profile) { 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 312 PrefService* pref_service = profile->GetPrefs(); 313 PrefService* local_state_pref_service = g_browser_process->local_state(); 314 315 scoped_ptr<ProfileParams> params(new ProfileParams); 316 params->path = profile->GetPath(); 317 318 params->io_thread = g_browser_process->io_thread(); 319 320 params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); 321 params->host_content_settings_map = profile->GetHostContentSettingsMap(); 322 params->ssl_config_service = profile->GetSSLConfigService(); 323 params->cookie_monster_delegate = 324 chrome_browser_net::CreateCookieDelegate(profile); 325 params->extension_info_map = 326 extensions::ExtensionSystem::Get(profile)->info_map(); 327 328 ProtocolHandlerRegistry* protocol_handler_registry = 329 ProtocolHandlerRegistryFactory::GetForProfile(profile); 330 DCHECK(protocol_handler_registry); 331 332 // The profile instance is only available here in the InitializeOnUIThread 333 // method, so we create the url job factory here, then save it for 334 // later delivery to the job factory in Init(). 335 params->protocol_handler_interceptor = 336 protocol_handler_registry->CreateJobInterceptorFactory(); 337 338 params->proxy_config_service 339 .reset(ProxyServiceFactory::CreateProxyConfigService( 340 profile->GetProxyConfigTracker())); 341#if defined(ENABLE_MANAGED_USERS) 342 ManagedUserService* managed_user_service = 343 ManagedUserServiceFactory::GetForProfile(profile); 344 params->managed_mode_url_filter = 345 managed_user_service->GetURLFilterForIOThread(); 346#endif 347#if defined(OS_CHROMEOS) 348 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); 349 if (user_manager) { 350 chromeos::User* user = user_manager->GetUserByProfile(profile); 351 if (user) { 352 params->username_hash = user->username_hash(); 353 bool is_primary_user = (user_manager->GetPrimaryUser() == user); 354 BrowserThread::PostTask(BrowserThread::IO, 355 FROM_HERE, 356 base::Bind(&StartNSSInitOnIOThread, 357 user->email(), 358 user->username_hash(), 359 profile->GetPath(), 360 is_primary_user)); 361 } 362 } 363 if (params->username_hash.empty()) 364 LOG(WARNING) << "no username_hash"; 365#endif 366 367 params->profile = profile; 368 profile_params_.reset(params.release()); 369 370 ChromeNetworkDelegate::InitializePrefsOnUIThread( 371 &enable_referrers_, 372 &enable_do_not_track_, 373 &force_safesearch_, 374 pref_service); 375 376 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy = 377 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 378#if defined(ENABLE_PRINTING) 379 printing_enabled_.Init(prefs::kPrintingEnabled, pref_service); 380 printing_enabled_.MoveToThread(io_message_loop_proxy); 381#endif 382 383 chrome_http_user_agent_settings_.reset( 384 new ChromeHttpUserAgentSettings(pref_service)); 385 386 // These members are used only for one click sign in, which is not enabled 387 // in incognito mode. So no need to initialize them. 388 if (!IsOffTheRecord()) { 389 signin_names_.reset(new SigninNamesOnIOThread()); 390 391 google_services_user_account_id_.Init( 392 prefs::kGoogleServicesUserAccountId, pref_service); 393 google_services_user_account_id_.MoveToThread(io_message_loop_proxy); 394 395 google_services_username_.Init( 396 prefs::kGoogleServicesUsername, pref_service); 397 google_services_username_.MoveToThread(io_message_loop_proxy); 398 399 google_services_username_pattern_.Init( 400 prefs::kGoogleServicesUsernamePattern, local_state_pref_service); 401 google_services_username_pattern_.MoveToThread(io_message_loop_proxy); 402 403 reverse_autologin_enabled_.Init( 404 prefs::kReverseAutologinEnabled, pref_service); 405 reverse_autologin_enabled_.MoveToThread(io_message_loop_proxy); 406 407 one_click_signin_rejected_email_list_.Init( 408 prefs::kReverseAutologinRejectedEmailList, pref_service); 409 one_click_signin_rejected_email_list_.MoveToThread(io_message_loop_proxy); 410 411 sync_disabled_.Init(prefs::kSyncManaged, pref_service); 412 sync_disabled_.MoveToThread(io_message_loop_proxy); 413 414 signin_allowed_.Init(prefs::kSigninAllowed, pref_service); 415 signin_allowed_.MoveToThread(io_message_loop_proxy); 416 } 417 418 quick_check_enabled_.Init(prefs::kQuickCheckEnabled, 419 local_state_pref_service); 420 quick_check_enabled_.MoveToThread(io_message_loop_proxy); 421 422 media_device_id_salt_ = new MediaDeviceIDSalt(pref_service, IsOffTheRecord()); 423 424 network_prediction_enabled_.Init(prefs::kNetworkPredictionEnabled, 425 pref_service); 426 network_prediction_enabled_.MoveToThread(io_message_loop_proxy); 427 428#if defined(OS_CHROMEOS) 429 cert_verifier_ = policy::PolicyCertServiceFactory::CreateForProfile(profile); 430#endif 431 // The URLBlacklistManager has to be created on the UI thread to register 432 // observers of |pref_service|, and it also has to clean up on 433 // ShutdownOnUIThread to release these observers on the right thread. 434 // Don't pass it in |profile_params_| to make sure it is correctly cleaned up, 435 // in particular when this ProfileIOData isn't |initialized_| during deletion. 436#if defined(ENABLE_CONFIGURATION_POLICY) 437 policy::URLBlacklist::SegmentURLCallback callback = 438 static_cast<policy::URLBlacklist::SegmentURLCallback>( 439 URLFixerUpper::SegmentURL); 440 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 441 scoped_refptr<base::SequencedTaskRunner> background_task_runner = 442 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 443 url_blacklist_manager_.reset( 444 new policy::URLBlacklistManager(pref_service, 445 background_task_runner, 446 io_message_loop_proxy, 447 callback, 448 policy::OverrideBlacklistForURL)); 449 450 if (!IsOffTheRecord()) { 451 // Add policy headers for non-incognito requests. 452 policy::PolicyHeaderService* policy_header_service = 453 policy::PolicyHeaderServiceFactory::GetForBrowserContext(profile); 454 if (policy_header_service) { 455 policy_header_helper_ = policy_header_service->CreatePolicyHeaderIOHelper( 456 io_message_loop_proxy); 457 } 458 } 459#endif 460 461 initialized_on_UI_thread_ = true; 462 463 // We need to make sure that content initializes its own data structures that 464 // are associated with each ResourceContext because we might post this 465 // object to the IO thread after this function. 466 BrowserContext::EnsureResourceContextInitialized(profile); 467} 468 469ProfileIOData::MediaRequestContext::MediaRequestContext() { 470} 471 472void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory( 473 scoped_ptr<net::HttpTransactionFactory> http_factory) { 474 http_factory_ = http_factory.Pass(); 475 set_http_transaction_factory(http_factory_.get()); 476} 477 478ProfileIOData::MediaRequestContext::~MediaRequestContext() {} 479 480ProfileIOData::AppRequestContext::AppRequestContext() { 481} 482 483void ProfileIOData::AppRequestContext::SetCookieStore( 484 net::CookieStore* cookie_store) { 485 cookie_store_ = cookie_store; 486 set_cookie_store(cookie_store); 487} 488 489void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( 490 scoped_ptr<net::HttpTransactionFactory> http_factory) { 491 http_factory_ = http_factory.Pass(); 492 set_http_transaction_factory(http_factory_.get()); 493} 494 495void ProfileIOData::AppRequestContext::SetJobFactory( 496 scoped_ptr<net::URLRequestJobFactory> job_factory) { 497 job_factory_ = job_factory.Pass(); 498 set_job_factory(job_factory_.get()); 499} 500 501ProfileIOData::AppRequestContext::~AppRequestContext() {} 502 503ProfileIOData::ProfileParams::ProfileParams() 504 : io_thread(NULL), 505 profile(NULL) { 506} 507 508ProfileIOData::ProfileParams::~ProfileParams() {} 509 510ProfileIOData::ProfileIOData(Profile::ProfileType profile_type) 511 : initialized_(false), 512 resource_context_(new ResourceContext(this)), 513 initialized_on_UI_thread_(false), 514 profile_type_(profile_type) { 515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 516} 517 518ProfileIOData::~ProfileIOData() { 519 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 521 522 // Pull the contents of the request context maps onto the stack for sanity 523 // checking of values in a minidump. http://crbug.com/260425 524 size_t num_app_contexts = app_request_context_map_.size(); 525 size_t num_media_contexts = isolated_media_request_context_map_.size(); 526 size_t current_context = 0; 527 static const size_t kMaxCachedContexts = 20; 528 ChromeURLRequestContext* app_context_cache[kMaxCachedContexts] = {0}; 529 void* app_context_vtable_cache[kMaxCachedContexts] = {0}; 530 ChromeURLRequestContext* media_context_cache[kMaxCachedContexts] = {0}; 531 void* media_context_vtable_cache[kMaxCachedContexts] = {0}; 532 void* tmp_vtable = NULL; 533 base::debug::Alias(&num_app_contexts); 534 base::debug::Alias(&num_media_contexts); 535 base::debug::Alias(¤t_context); 536 base::debug::Alias(app_context_cache); 537 base::debug::Alias(app_context_vtable_cache); 538 base::debug::Alias(media_context_cache); 539 base::debug::Alias(media_context_vtable_cache); 540 base::debug::Alias(&tmp_vtable); 541 542 current_context = 0; 543 for (URLRequestContextMap::const_iterator it = 544 app_request_context_map_.begin(); 545 current_context < kMaxCachedContexts && 546 it != app_request_context_map_.end(); 547 ++it, ++current_context) { 548 app_context_cache[current_context] = it->second; 549 memcpy(&app_context_vtable_cache[current_context], 550 static_cast<void*>(it->second), sizeof(void*)); 551 } 552 553 current_context = 0; 554 for (URLRequestContextMap::const_iterator it = 555 isolated_media_request_context_map_.begin(); 556 current_context < kMaxCachedContexts && 557 it != isolated_media_request_context_map_.end(); 558 ++it, ++current_context) { 559 media_context_cache[current_context] = it->second; 560 memcpy(&media_context_vtable_cache[current_context], 561 static_cast<void*>(it->second), sizeof(void*)); 562 } 563 564 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they 565 // are already done in the URLRequestContext destructor. 566 if (main_request_context_) 567 main_request_context_->AssertNoURLRequests(); 568 if (extensions_request_context_) 569 extensions_request_context_->AssertNoURLRequests(); 570 571 current_context = 0; 572 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); 573 it != app_request_context_map_.end(); ++it) { 574 if (current_context < kMaxCachedContexts) { 575 CHECK_EQ(app_context_cache[current_context], it->second); 576 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); 577 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); 578 } 579 it->second->AssertNoURLRequests(); 580 delete it->second; 581 current_context++; 582 } 583 584 current_context = 0; 585 for (URLRequestContextMap::iterator it = 586 isolated_media_request_context_map_.begin(); 587 it != isolated_media_request_context_map_.end(); ++it) { 588 if (current_context < kMaxCachedContexts) { 589 CHECK_EQ(media_context_cache[current_context], it->second); 590 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); 591 CHECK_EQ(media_context_vtable_cache[current_context], tmp_vtable); 592 } 593 it->second->AssertNoURLRequests(); 594 delete it->second; 595 current_context++; 596 } 597} 598 599// static 600ProfileIOData* ProfileIOData::FromResourceContext( 601 content::ResourceContext* rc) { 602 return (static_cast<ResourceContext*>(rc))->io_data_; 603} 604 605// static 606bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { 607 DCHECK_EQ(scheme, StringToLowerASCII(scheme)); 608 static const char* const kProtocolList[] = { 609 content::kFileScheme, 610 content::kChromeDevToolsScheme, 611 chrome::kDomDistillerScheme, 612 extensions::kExtensionScheme, 613 extensions::kExtensionResourceScheme, 614 content::kChromeUIScheme, 615 content::kDataScheme, 616#if defined(OS_CHROMEOS) 617 chrome::kDriveScheme, 618#endif // defined(OS_CHROMEOS) 619 content::kAboutScheme, 620#if !defined(DISABLE_FTP_SUPPORT) 621 content::kFtpScheme, 622#endif // !defined(DISABLE_FTP_SUPPORT) 623 content::kBlobScheme, 624 content::kFileSystemScheme, 625 chrome::kChromeSearchScheme, 626 }; 627 for (size_t i = 0; i < arraysize(kProtocolList); ++i) { 628 if (scheme == kProtocolList[i]) 629 return true; 630 } 631 return net::URLRequest::IsHandledProtocol(scheme); 632} 633 634// static 635bool ProfileIOData::IsHandledURL(const GURL& url) { 636 if (!url.is_valid()) { 637 // We handle error cases. 638 return true; 639 } 640 641 return IsHandledProtocol(url.scheme()); 642} 643 644// static 645void ProfileIOData::InstallProtocolHandlers( 646 net::URLRequestJobFactoryImpl* job_factory, 647 content::ProtocolHandlerMap* protocol_handlers) { 648 for (content::ProtocolHandlerMap::iterator it = 649 protocol_handlers->begin(); 650 it != protocol_handlers->end(); 651 ++it) { 652 bool set_protocol = job_factory->SetProtocolHandler( 653 it->first, it->second.release()); 654 DCHECK(set_protocol); 655 } 656 protocol_handlers->clear(); 657} 658 659content::ResourceContext* ProfileIOData::GetResourceContext() const { 660 return resource_context_.get(); 661} 662 663ChromeURLRequestContext* ProfileIOData::GetMainRequestContext() const { 664 DCHECK(initialized_); 665 return main_request_context_.get(); 666} 667 668ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { 669 DCHECK(initialized_); 670 ChromeURLRequestContext* context = AcquireMediaRequestContext(); 671 DCHECK(context); 672 return context; 673} 674 675ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { 676 DCHECK(initialized_); 677 return extensions_request_context_.get(); 678} 679 680ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( 681 ChromeURLRequestContext* main_context, 682 const StoragePartitionDescriptor& partition_descriptor, 683 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 684 protocol_handler_interceptor, 685 content::ProtocolHandlerMap* protocol_handlers, 686 content::ProtocolHandlerScopedVector protocol_interceptors) const { 687 DCHECK(initialized_); 688 ChromeURLRequestContext* context = NULL; 689 if (ContainsKey(app_request_context_map_, partition_descriptor)) { 690 context = app_request_context_map_[partition_descriptor]; 691 } else { 692 context = 693 AcquireIsolatedAppRequestContext(main_context, 694 partition_descriptor, 695 protocol_handler_interceptor.Pass(), 696 protocol_handlers, 697 protocol_interceptors.Pass()); 698 app_request_context_map_[partition_descriptor] = context; 699 } 700 DCHECK(context); 701 return context; 702} 703 704ChromeURLRequestContext* ProfileIOData::GetIsolatedMediaRequestContext( 705 ChromeURLRequestContext* app_context, 706 const StoragePartitionDescriptor& partition_descriptor) const { 707 DCHECK(initialized_); 708 ChromeURLRequestContext* context = NULL; 709 if (ContainsKey(isolated_media_request_context_map_, partition_descriptor)) { 710 context = isolated_media_request_context_map_[partition_descriptor]; 711 } else { 712 context = AcquireIsolatedMediaRequestContext(app_context, 713 partition_descriptor); 714 isolated_media_request_context_map_[partition_descriptor] = context; 715 } 716 DCHECK(context); 717 return context; 718} 719 720extensions::InfoMap* ProfileIOData::GetExtensionInfoMap() const { 721 DCHECK(initialized_) << "ExtensionSystem not initialized"; 722 return extension_info_map_.get(); 723} 724 725CookieSettings* ProfileIOData::GetCookieSettings() const { 726 // Allow either Init() or SetCookieSettingsForTesting() to initialize. 727 DCHECK(initialized_ || cookie_settings_.get()); 728 return cookie_settings_.get(); 729} 730 731HostContentSettingsMap* ProfileIOData::GetHostContentSettingsMap() const { 732 DCHECK(initialized_); 733 return host_content_settings_map_.get(); 734} 735 736ResourceContext::SaltCallback ProfileIOData::GetMediaDeviceIDSalt() const { 737 return base::Bind(&MediaDeviceIDSalt::GetSalt, media_device_id_salt_); 738} 739 740bool ProfileIOData::IsOffTheRecord() const { 741 return profile_type() == Profile::INCOGNITO_PROFILE 742 || profile_type() == Profile::GUEST_PROFILE; 743} 744 745void ProfileIOData::InitializeMetricsEnabledStateOnUIThread() { 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 747#if defined(OS_CHROMEOS) 748 // Just fetch the value from ChromeOS' settings while we're on the UI thread. 749 // TODO(stevet): For now, this value is only set on profile initialization. 750 // We will want to do something similar to the PrefMember method below in the 751 // future to more accurately capture this state. 752 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, 753 &enable_metrics_); 754#elif defined(OS_ANDROID) 755 // TODO(dwkang): rename or unify the pref for UMA once we have conclusion 756 // in crbugs.com/246495. 757 // Android has it's own preferences for metrics / crash uploading. 758 enable_metrics_.Init(prefs::kCrashReportingEnabled, 759 g_browser_process->local_state()); 760 enable_metrics_.MoveToThread( 761 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 762#else 763 // Prep the PrefMember and send it to the IO thread, since this value will be 764 // read from there. 765 enable_metrics_.Init(prefs::kMetricsReportingEnabled, 766 g_browser_process->local_state()); 767 enable_metrics_.MoveToThread( 768 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 769#endif // defined(OS_CHROMEOS) 770} 771 772bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const { 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 774#if defined(OS_CHROMEOS) 775 return enable_metrics_; 776#else 777 return enable_metrics_.GetValue(); 778#endif // defined(OS_CHROMEOS) 779} 780 781base::WeakPtr<net::HttpServerProperties> 782ProfileIOData::http_server_properties() const { 783 return http_server_properties_->GetWeakPtr(); 784} 785 786void ProfileIOData::set_http_server_properties( 787 scoped_ptr<net::HttpServerProperties> http_server_properties) const { 788 http_server_properties_ = http_server_properties.Pass(); 789} 790 791ProfileIOData::ResourceContext::ResourceContext(ProfileIOData* io_data) 792 : io_data_(io_data), 793 host_resolver_(NULL), 794 request_context_(NULL) { 795 DCHECK(io_data); 796} 797 798ProfileIOData::ResourceContext::~ResourceContext() {} 799 800net::HostResolver* ProfileIOData::ResourceContext::GetHostResolver() { 801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 802 DCHECK(io_data_->initialized_); 803 return host_resolver_; 804} 805 806net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { 807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 808 DCHECK(io_data_->initialized_); 809 return request_context_; 810} 811 812scoped_ptr<net::ClientCertStore> 813ProfileIOData::ResourceContext::CreateClientCertStore() { 814 if (!io_data_->client_cert_store_factory_.is_null()) 815 return io_data_->client_cert_store_factory_.Run(); 816#if defined(OS_CHROMEOS) 817 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreChromeOS( 818 io_data_->username_hash(), 819 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate, 820 chrome::kCryptoModulePasswordClientAuth))); 821#elif defined(USE_NSS) 822 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS( 823 base::Bind(&CreateCryptoModuleBlockingPasswordDelegate, 824 chrome::kCryptoModulePasswordClientAuth))); 825#elif defined(OS_WIN) 826 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreWin()); 827#elif defined(OS_MACOSX) 828 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreMac()); 829#elif defined(USE_OPENSSL) 830 // OpenSSL does not use the ClientCertStore infrastructure. On Android client 831 // cert matching is done by the OS as part of the call to show the cert 832 // selection dialog. 833 return scoped_ptr<net::ClientCertStore>(); 834#else 835#error Unknown platform. 836#endif 837} 838 839void ProfileIOData::ResourceContext::CreateKeygenHandler( 840 uint32 key_size_in_bits, 841 const std::string& challenge_string, 842 const GURL& url, 843 const base::Callback<void(scoped_ptr<net::KeygenHandler>)>& callback) { 844 DCHECK(!callback.is_null()); 845#if defined(USE_NSS) 846 scoped_ptr<net::KeygenHandler> keygen_handler( 847 new net::KeygenHandler(key_size_in_bits, challenge_string, url)); 848 849 scoped_ptr<ChromeNSSCryptoModuleDelegate> delegate( 850 new ChromeNSSCryptoModuleDelegate(chrome::kCryptoModulePasswordKeygen, 851 net::HostPortPair::FromURL(url))); 852 ChromeNSSCryptoModuleDelegate* delegate_ptr = delegate.get(); 853 keygen_handler->set_crypto_module_delegate( 854 delegate.PassAs<crypto::NSSCryptoModuleDelegate>()); 855 856 base::Closure bound_callback = 857 base::Bind(callback, base::Passed(&keygen_handler)); 858 if (delegate_ptr->InitializeSlot(this, bound_callback)) { 859 // Initialization complete, run the callback synchronously. 860 bound_callback.Run(); 861 return; 862 } 863 // Otherwise, the InitializeSlot will run the callback asynchronously. 864#else 865 callback.Run(make_scoped_ptr( 866 new net::KeygenHandler(key_size_in_bits, challenge_string, url))); 867#endif 868} 869 870bool ProfileIOData::ResourceContext::AllowMicAccess(const GURL& origin) { 871 return AllowContentAccess(origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 872} 873 874bool ProfileIOData::ResourceContext::AllowCameraAccess(const GURL& origin) { 875 return AllowContentAccess(origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 876} 877 878bool ProfileIOData::ResourceContext::AllowContentAccess( 879 const GURL& origin, ContentSettingsType type) { 880 HostContentSettingsMap* content_settings = 881 io_data_->GetHostContentSettingsMap(); 882 ContentSetting setting = content_settings->GetContentSetting( 883 origin, origin, type, NO_RESOURCE_IDENTIFIER); 884 return setting == CONTENT_SETTING_ALLOW; 885} 886 887ResourceContext::SaltCallback 888ProfileIOData::ResourceContext::GetMediaDeviceIDSalt() { 889 return io_data_->GetMediaDeviceIDSalt(); 890} 891 892// static 893std::string ProfileIOData::GetSSLSessionCacheShard() { 894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 895 // The SSL session cache is partitioned by setting a string. This returns a 896 // unique string to partition the SSL session cache. Each time we create a 897 // new profile, we'll get a fresh SSL session cache which is separate from 898 // the other profiles. 899 static unsigned ssl_session_cache_instance = 0; 900 return base::StringPrintf("profile/%u", ssl_session_cache_instance++); 901} 902 903void ProfileIOData::Init( 904 content::ProtocolHandlerMap* protocol_handlers, 905 content::ProtocolHandlerScopedVector protocol_interceptors) const { 906 // The basic logic is implemented here. The specific initialization 907 // is done in InitializeInternal(), implemented by subtypes. Static helper 908 // functions have been provided to assist in common operations. 909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 910 DCHECK(!initialized_); 911 912 startup_metric_utils::ScopedSlowStartupUMA 913 scoped_timer("Startup.SlowStartupProfileIODataInit"); 914 915 // TODO(jhawkins): Remove once crbug.com/102004 is fixed. 916 CHECK(initialized_on_UI_thread_); 917 918 // TODO(jhawkins): Return to DCHECK once crbug.com/102004 is fixed. 919 CHECK(profile_params_.get()); 920 921 IOThread* const io_thread = profile_params_->io_thread; 922 IOThread::Globals* const io_thread_globals = io_thread->globals(); 923 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 924 925 // Create the common request contexts. 926 main_request_context_.reset(new ChromeURLRequestContext()); 927 extensions_request_context_.reset(new ChromeURLRequestContext()); 928 929 ChromeNetworkDelegate* network_delegate = 930 new ChromeNetworkDelegate( 931 io_thread_globals->extension_event_router_forwarder.get(), 932 &enable_referrers_); 933 if (command_line.HasSwitch(switches::kEnableClientHints)) 934 network_delegate->SetEnableClientHints(); 935 network_delegate->set_extension_info_map( 936 profile_params_->extension_info_map.get()); 937#if defined(ENABLE_CONFIGURATION_POLICY) 938 network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get()); 939#endif 940 network_delegate->set_profile(profile_params_->profile); 941 network_delegate->set_profile_path(profile_params_->path); 942 network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); 943 network_delegate->set_enable_do_not_track(&enable_do_not_track_); 944 network_delegate->set_force_google_safe_search(&force_safesearch_); 945 network_delegate_.reset(network_delegate); 946 947 fraudulent_certificate_reporter_.reset( 948 new chrome_browser_net::ChromeFraudulentCertificateReporter( 949 main_request_context_.get())); 950 951 // NOTE: Proxy service uses the default io thread network delegate, not the 952 // delegate just created. 953 proxy_service_.reset( 954 ProxyServiceFactory::CreateProxyService( 955 io_thread->net_log(), 956 io_thread_globals->proxy_script_fetcher_context.get(), 957 io_thread_globals->system_network_delegate.get(), 958 profile_params_->proxy_config_service.release(), 959 command_line, 960 quick_check_enabled_.GetValue())); 961 962 transport_security_state_.reset(new net::TransportSecurityState()); 963 transport_security_persister_.reset( 964 new net::TransportSecurityPersister( 965 transport_security_state_.get(), 966 profile_params_->path, 967 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 968 IsOffTheRecord())); 969 970 // Take ownership over these parameters. 971 cookie_settings_ = profile_params_->cookie_settings; 972 host_content_settings_map_ = profile_params_->host_content_settings_map; 973 extension_info_map_ = profile_params_->extension_info_map; 974 975 resource_context_->host_resolver_ = io_thread_globals->host_resolver.get(); 976 resource_context_->request_context_ = main_request_context_.get(); 977 978#if defined(ENABLE_MANAGED_USERS) 979 managed_mode_url_filter_ = profile_params_->managed_mode_url_filter; 980#endif 981 982#if defined(OS_CHROMEOS) 983 username_hash_ = profile_params_->username_hash; 984 scoped_refptr<net::CertVerifyProc> verify_proc; 985 if (chromeos::UserManager::IsMultipleProfilesAllowed()) { 986 crypto::ScopedPK11Slot public_slot = 987 crypto::GetPublicSlotForChromeOSUser(username_hash_); 988 // The private slot won't be ready by this point. It shouldn't be necessary 989 // for cert trust purposes anyway. 990 verify_proc = new chromeos::CertVerifyProcChromeOS(public_slot.Pass()); 991 } else { 992 verify_proc = net::CertVerifyProc::CreateDefault(); 993 } 994 if (cert_verifier_) { 995 cert_verifier_->InitializeOnIOThread(verify_proc); 996 main_request_context_->set_cert_verifier(cert_verifier_.get()); 997 } else { 998 main_request_context_->set_cert_verifier( 999 new net::MultiThreadedCertVerifier(verify_proc.get())); 1000 } 1001#else 1002 main_request_context_->set_cert_verifier( 1003 io_thread_globals->cert_verifier.get()); 1004#endif 1005 1006 InitializeInternal( 1007 profile_params_.get(), protocol_handlers, protocol_interceptors.Pass()); 1008 1009 profile_params_.reset(); 1010 initialized_ = true; 1011} 1012 1013void ProfileIOData::ApplyProfileParamsToContext( 1014 ChromeURLRequestContext* context) const { 1015 context->set_http_user_agent_settings( 1016 chrome_http_user_agent_settings_.get()); 1017 context->set_ssl_config_service(profile_params_->ssl_config_service.get()); 1018} 1019 1020scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults( 1021 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory, 1022 content::ProtocolHandlerScopedVector protocol_interceptors, 1023 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 1024 protocol_handler_interceptor, 1025 net::NetworkDelegate* network_delegate, 1026 net::FtpTransactionFactory* ftp_transaction_factory) const { 1027 // NOTE(willchan): Keep these protocol handlers in sync with 1028 // ProfileIOData::IsHandledProtocol(). 1029 bool set_protocol = job_factory->SetProtocolHandler( 1030 content::kFileScheme, 1031 new net::FileProtocolHandler( 1032 content::BrowserThread::GetBlockingPool()-> 1033 GetTaskRunnerWithShutdownBehavior( 1034 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); 1035 DCHECK(set_protocol); 1036 1037 DCHECK(extension_info_map_.get()); 1038 set_protocol = job_factory->SetProtocolHandler( 1039 extensions::kExtensionScheme, 1040 CreateExtensionProtocolHandler(profile_type(), 1041 extension_info_map_.get())); 1042 DCHECK(set_protocol); 1043 set_protocol = job_factory->SetProtocolHandler( 1044 extensions::kExtensionResourceScheme, 1045 CreateExtensionResourceProtocolHandler()); 1046 DCHECK(set_protocol); 1047 set_protocol = job_factory->SetProtocolHandler( 1048 content::kDataScheme, new net::DataProtocolHandler()); 1049 DCHECK(set_protocol); 1050#if defined(OS_CHROMEOS) 1051 if (!IsOffTheRecord() && profile_params_) { 1052 set_protocol = job_factory->SetProtocolHandler( 1053 chrome::kDriveScheme, 1054 new drive::DriveProtocolHandler(profile_params_->profile)); 1055 DCHECK(set_protocol); 1056 } 1057#endif // defined(OS_CHROMEOS) 1058 1059 job_factory->SetProtocolHandler( 1060 content::kAboutScheme, new chrome_browser_net::AboutProtocolHandler()); 1061#if !defined(DISABLE_FTP_SUPPORT) 1062 DCHECK(ftp_transaction_factory); 1063 job_factory->SetProtocolHandler( 1064 content::kFtpScheme, 1065 new net::FtpProtocolHandler(ftp_transaction_factory)); 1066#endif // !defined(DISABLE_FTP_SUPPORT) 1067 1068#if defined(DEBUG_DEVTOOLS) 1069 protocol_interceptors.push_back(new DebugDevToolsInterceptor); 1070#endif 1071 1072 // Set up interceptors in the reverse order. 1073 scoped_ptr<net::URLRequestJobFactory> top_job_factory = 1074 job_factory.PassAs<net::URLRequestJobFactory>(); 1075 for (content::ProtocolHandlerScopedVector::reverse_iterator i = 1076 protocol_interceptors.rbegin(); 1077 i != protocol_interceptors.rend(); 1078 ++i) { 1079 top_job_factory.reset(new net::ProtocolInterceptJobFactory( 1080 top_job_factory.Pass(), make_scoped_ptr(*i))); 1081 } 1082 protocol_interceptors.weak_clear(); 1083 1084 if (protocol_handler_interceptor) { 1085 protocol_handler_interceptor->Chain(top_job_factory.Pass()); 1086 return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>(); 1087 } else { 1088 return top_job_factory.Pass(); 1089 } 1090} 1091 1092void ProfileIOData::ShutdownOnUIThread() { 1093 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1094 1095 if (signin_names_) 1096 signin_names_->ReleaseResourcesOnUIThread(); 1097 1098 google_services_user_account_id_.Destroy(); 1099 google_services_username_.Destroy(); 1100 google_services_username_pattern_.Destroy(); 1101 reverse_autologin_enabled_.Destroy(); 1102 one_click_signin_rejected_email_list_.Destroy(); 1103 enable_referrers_.Destroy(); 1104 enable_do_not_track_.Destroy(); 1105 force_safesearch_.Destroy(); 1106#if !defined(OS_CHROMEOS) 1107 enable_metrics_.Destroy(); 1108#endif 1109 safe_browsing_enabled_.Destroy(); 1110 printing_enabled_.Destroy(); 1111 sync_disabled_.Destroy(); 1112 signin_allowed_.Destroy(); 1113 network_prediction_enabled_.Destroy(); 1114 quick_check_enabled_.Destroy(); 1115 if (media_device_id_salt_) 1116 media_device_id_salt_->ShutdownOnUIThread(); 1117 session_startup_pref_.Destroy(); 1118#if defined(ENABLE_CONFIGURATION_POLICY) 1119 if (url_blacklist_manager_) 1120 url_blacklist_manager_->ShutdownOnUIThread(); 1121#endif 1122 if (chrome_http_user_agent_settings_) 1123 chrome_http_user_agent_settings_->CleanupOnUIThread(); 1124 bool posted = BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); 1125 if (!posted) 1126 delete this; 1127} 1128 1129void ProfileIOData::set_server_bound_cert_service( 1130 net::ServerBoundCertService* server_bound_cert_service) const { 1131 server_bound_cert_service_.reset(server_bound_cert_service); 1132} 1133 1134void ProfileIOData::DestroyResourceContext() { 1135 resource_context_.reset(); 1136} 1137 1138void ProfileIOData::PopulateNetworkSessionParams( 1139 const ProfileParams* profile_params, 1140 net::HttpNetworkSession::Params* params) const { 1141 1142 ChromeURLRequestContext* context = main_request_context(); 1143 1144 IOThread* const io_thread = profile_params->io_thread; 1145 1146 io_thread->InitializeNetworkSessionParams(params); 1147 1148 params->host_resolver = context->host_resolver(); 1149 params->cert_verifier = context->cert_verifier(); 1150 params->server_bound_cert_service = context->server_bound_cert_service(); 1151 params->transport_security_state = context->transport_security_state(); 1152 params->cert_transparency_verifier = context->cert_transparency_verifier(); 1153 params->proxy_service = context->proxy_service(); 1154 params->ssl_session_cache_shard = GetSSLSessionCacheShard(); 1155 params->ssl_config_service = context->ssl_config_service(); 1156 params->http_auth_handler_factory = context->http_auth_handler_factory(); 1157 params->network_delegate = network_delegate(); 1158 params->http_server_properties = context->http_server_properties(); 1159 params->net_log = context->net_log(); 1160} 1161 1162void ProfileIOData::SetCookieSettingsForTesting( 1163 CookieSettings* cookie_settings) { 1164 DCHECK(!cookie_settings_.get()); 1165 cookie_settings_ = cookie_settings; 1166} 1167 1168void ProfileIOData::set_signin_names_for_testing( 1169 SigninNamesOnIOThread* signin_names) { 1170 signin_names_.reset(signin_names); 1171} 1172