| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #include "net/url_request/url_request_job_factory_impl.h" | 83 #include "net/url_request/url_request_job_factory_impl.h" |
| 84 | 84 |
| 85 #if defined(ENABLE_MANAGED_USERS) | 85 #if defined(ENABLE_MANAGED_USERS) |
| 86 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 86 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 87 #include "chrome/browser/managed_mode/managed_user_service.h" | 87 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 88 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 88 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 92 #include "chrome/browser/chromeos/drive/drive_protocol_handler.h" | 92 #include "chrome/browser/chromeos/drive/drive_protocol_handler.h" |
| 93 #include "chrome/browser/chromeos/login/user.h" |
| 94 #include "chrome/browser/chromeos/login/user_manager.h" |
| 95 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" |
| 93 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" | 96 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
| 94 #include "chrome/browser/chromeos/settings/cros_settings.h" | 97 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 95 #include "chrome/browser/policy/profile_policy_connector.h" | 98 #include "chrome/browser/policy/profile_policy_connector.h" |
| 96 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 99 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 100 #include "chromeos/dbus/cryptohome_client.h" |
| 101 #include "chromeos/dbus/dbus_thread_manager.h" |
| 97 #include "chromeos/settings/cros_settings_names.h" | 102 #include "chromeos/settings/cros_settings_names.h" |
| 103 #include "content/public/browser/nss_context.h" |
| 104 #include "crypto/nss_util.h" |
| 105 #include "crypto/nss_util_internal.h" |
| 98 #endif // defined(OS_CHROMEOS) | 106 #endif // defined(OS_CHROMEOS) |
| 99 | 107 |
| 100 using content::BrowserContext; | 108 using content::BrowserContext; |
| 101 using content::BrowserThread; | 109 using content::BrowserThread; |
| 102 using content::ResourceContext; | 110 using content::ResourceContext; |
| 103 | 111 |
| 104 namespace { | 112 namespace { |
| 105 | 113 |
| 106 // ---------------------------------------------------------------------------- | 114 // ---------------------------------------------------------------------------- |
| 107 // CookieMonster::Delegate implementation | 115 // CookieMonster::Delegate implementation |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 base::Closure policy_cert_trusted_callback = | 241 base::Closure policy_cert_trusted_callback = |
| 234 base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask), | 242 base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask), |
| 235 content::BrowserThread::UI, | 243 content::BrowserThread::UI, |
| 236 FROM_HERE, | 244 FROM_HERE, |
| 237 connector->GetPolicyCertTrustedCallback()); | 245 connector->GetPolicyCertTrustedCallback()); |
| 238 scoped_ptr<policy::PolicyCertVerifier> cert_verifier( | 246 scoped_ptr<policy::PolicyCertVerifier> cert_verifier( |
| 239 new policy::PolicyCertVerifier(policy_cert_trusted_callback)); | 247 new policy::PolicyCertVerifier(policy_cert_trusted_callback)); |
| 240 connector->SetPolicyCertVerifier(cert_verifier.get()); | 248 connector->SetPolicyCertVerifier(cert_verifier.get()); |
| 241 return cert_verifier.Pass(); | 249 return cert_verifier.Pass(); |
| 242 } | 250 } |
| 243 #endif | 251 |
| 252 void DidGetTPMInfoForUserOnUIThread(const std::string& username_hash, |
| 253 chromeos::DBusMethodCallStatus call_status, |
| 254 const std::string& label, |
| 255 const std::string& user_pin, |
| 256 int slot_id) { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 258 if (call_status == chromeos::DBUS_METHOD_CALL_FAILURE) { |
| 259 NOTREACHED() << "dbus error getting TPM info for " << username_hash; |
| 260 return; |
| 261 } |
| 262 VLOG(1) << __func__ << " "<< username_hash << " " << slot_id; |
| 263 BrowserThread::PostTask( |
| 264 BrowserThread::IO, |
| 265 FROM_HERE, |
| 266 base::Bind( |
| 267 &crypto::InitializeTPMForChromeOSUser, username_hash, slot_id)); |
| 268 } |
| 269 |
| 270 void GetTPMInfoForUserOnUIThread(const std::string& username, |
| 271 const std::string& username_hash) { |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 273 VLOG(1) << __func__ << " " << username << " " << username_hash; |
| 274 chromeos::DBusThreadManager::Get() |
| 275 ->GetCryptohomeClient() |
| 276 ->Pkcs11GetTpmTokenInfoForUser( |
| 277 username, |
| 278 base::Bind(&DidGetTPMInfoForUserOnUIThread, username_hash)); |
| 279 } |
| 280 |
| 281 void StartTPMSlotInitializionOnIOThread(const std::string& username, |
| 282 const std::string& username_hash) { |
| 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 284 VLOG(1) << __func__ << " " << username << " " << username_hash; |
| 285 |
| 286 BrowserThread::PostTask( |
| 287 BrowserThread::UI, |
| 288 FROM_HERE, |
| 289 base::Bind(&GetTPMInfoForUserOnUIThread, username, username_hash)); |
| 290 } |
| 291 |
| 292 void StartNSSInitOnIOThread(const std::string& username, |
| 293 const std::string& username_hash, |
| 294 const base::FilePath& path, |
| 295 bool is_primary_user) { |
| 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 297 VLOG(1) << "username:" << username << " hash:" << username_hash |
| 298 << " is_primary_user:" << is_primary_user; |
| 299 |
| 300 if (!crypto::InitializeNSSForChromeOSUser( |
| 301 username, username_hash, is_primary_user, path)) |
| 302 return; |
| 303 |
| 304 if (crypto::IsTPMTokenEnabledForNSS()) { |
| 305 if (crypto::IsTPMTokenReady()) { |
| 306 StartTPMSlotInitializionOnIOThread(username, username_hash); |
| 307 } else { |
| 308 VLOG(1) << "waiting for tpm ready ..."; |
| 309 crypto::OnTPMReady(base::Bind( |
| 310 &StartTPMSlotInitializionOnIOThread, username, username_hash)); |
| 311 } |
| 312 } else { |
| 313 crypto::InitializePrivateSoftwareSlotForChromeOSUser(username_hash); |
| 314 } |
| 315 } |
| 316 #endif // defined(OS_CHROMEOS) |
| 244 } // namespace | 317 } // namespace |
| 245 | 318 |
| 246 void ProfileIOData::InitializeOnUIThread(Profile* profile) { | 319 void ProfileIOData::InitializeOnUIThread(Profile* profile) { |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 248 PrefService* pref_service = profile->GetPrefs(); | 321 PrefService* pref_service = profile->GetPrefs(); |
| 249 PrefService* local_state_pref_service = g_browser_process->local_state(); | 322 PrefService* local_state_pref_service = g_browser_process->local_state(); |
| 250 | 323 |
| 251 scoped_ptr<ProfileParams> params(new ProfileParams); | 324 scoped_ptr<ProfileParams> params(new ProfileParams); |
| 252 params->path = profile->GetPath(); | 325 params->path = profile->GetPath(); |
| 253 | 326 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 .reset(ProxyServiceFactory::CreateProxyConfigService( | 364 .reset(ProxyServiceFactory::CreateProxyConfigService( |
| 292 profile->GetProxyConfigTracker())); | 365 profile->GetProxyConfigTracker())); |
| 293 #if defined(ENABLE_MANAGED_USERS) | 366 #if defined(ENABLE_MANAGED_USERS) |
| 294 ManagedUserService* managed_user_service = | 367 ManagedUserService* managed_user_service = |
| 295 ManagedUserServiceFactory::GetForProfile(profile); | 368 ManagedUserServiceFactory::GetForProfile(profile); |
| 296 params->managed_mode_url_filter = | 369 params->managed_mode_url_filter = |
| 297 managed_user_service->GetURLFilterForIOThread(); | 370 managed_user_service->GetURLFilterForIOThread(); |
| 298 #endif | 371 #endif |
| 299 #if defined(OS_CHROMEOS) | 372 #if defined(OS_CHROMEOS) |
| 300 params->cert_verifier = CreatePolicyCertVerifier(profile); | 373 params->cert_verifier = CreatePolicyCertVerifier(profile); |
| 374 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 375 if (user_manager) { |
| 376 chromeos::User* user = user_manager->GetUserByProfile(profile); |
| 377 if (user) { |
| 378 params->username_hash = user->username_hash(); |
| 379 bool is_primary_user = (user_manager->GetPrimaryUser() == user); |
| 380 BrowserThread::PostTask(BrowserThread::IO, |
| 381 FROM_HERE, |
| 382 base::Bind(&StartNSSInitOnIOThread, |
| 383 user->email(), |
| 384 user->username_hash(), |
| 385 profile->GetPath(), |
| 386 is_primary_user)); |
| 387 } |
| 388 } |
| 389 if (params->username_hash.empty()) |
| 390 LOG(WARNING) << "no username_hash"; |
| 301 #endif | 391 #endif |
| 302 | 392 |
| 303 params->profile = profile; | 393 params->profile = profile; |
| 304 profile_params_.reset(params.release()); | 394 profile_params_.reset(params.release()); |
| 305 | 395 |
| 306 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 396 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 307 &enable_referrers_, | 397 &enable_referrers_, |
| 308 &enable_do_not_track_, | 398 &enable_do_not_track_, |
| 309 &force_safesearch_, | 399 &force_safesearch_, |
| 310 pref_service); | 400 pref_service); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 797 } |
| 708 | 798 |
| 709 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { | 799 net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { |
| 710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 711 DCHECK(io_data_->initialized_); | 801 DCHECK(io_data_->initialized_); |
| 712 return request_context_; | 802 return request_context_; |
| 713 } | 803 } |
| 714 | 804 |
| 715 scoped_ptr<net::ClientCertStore> | 805 scoped_ptr<net::ClientCertStore> |
| 716 ProfileIOData::ResourceContext::CreateClientCertStore() { | 806 ProfileIOData::ResourceContext::CreateClientCertStore() { |
| 717 #if !defined(USE_OPENSSL) | 807 #if defined(OS_CHROMEOS) |
| 808 return scoped_ptr<net::ClientCertStore>( |
| 809 new chromeos::ClientCertStoreChromeOS(this)); |
| 810 #elif !defined(USE_OPENSSL) |
| 718 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreImpl()); | 811 return scoped_ptr<net::ClientCertStore>(new net::ClientCertStoreImpl()); |
| 719 #else | 812 #else |
| 720 // OpenSSL does not use the ClientCertStore infrastructure. On Android client | 813 // OpenSSL does not use the ClientCertStore infrastructure. On Android client |
| 721 // cert matching is done by the OS as part of the call to show the cert | 814 // cert matching is done by the OS as part of the call to show the cert |
| 722 // selection dialog. | 815 // selection dialog. |
| 723 return scoped_ptr<net::ClientCertStore>(); | 816 return scoped_ptr<net::ClientCertStore>(); |
| 724 #endif | 817 #endif |
| 725 } | 818 } |
| 726 | 819 |
| 727 bool ProfileIOData::ResourceContext::AllowMicAccess(const GURL& origin) { | 820 bool ProfileIOData::ResourceContext::AllowMicAccess(const GURL& origin) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 } | 928 } |
| 836 | 929 |
| 837 #if defined(ENABLE_MANAGED_USERS) | 930 #if defined(ENABLE_MANAGED_USERS) |
| 838 managed_mode_url_filter_ = profile_params_->managed_mode_url_filter; | 931 managed_mode_url_filter_ = profile_params_->managed_mode_url_filter; |
| 839 #endif | 932 #endif |
| 840 | 933 |
| 841 #if defined(OS_CHROMEOS) | 934 #if defined(OS_CHROMEOS) |
| 842 profile_params_->cert_verifier->InitializeOnIOThread(); | 935 profile_params_->cert_verifier->InitializeOnIOThread(); |
| 843 cert_verifier_ = profile_params_->cert_verifier.Pass(); | 936 cert_verifier_ = profile_params_->cert_verifier.Pass(); |
| 844 main_request_context_->set_cert_verifier(cert_verifier_.get()); | 937 main_request_context_->set_cert_verifier(cert_verifier_.get()); |
| 938 |
| 939 content::SetChromeOSUserForResourceContext(resource_context_.get(), |
| 940 profile_params_->username_hash); |
| 845 #else | 941 #else |
| 846 main_request_context_->set_cert_verifier( | 942 main_request_context_->set_cert_verifier( |
| 847 io_thread_globals->cert_verifier.get()); | 943 io_thread_globals->cert_verifier.get()); |
| 848 #endif | 944 #endif |
| 849 | 945 |
| 850 InitializeInternal(profile_params_.get(), protocol_handlers); | 946 InitializeInternal(profile_params_.get(), protocol_handlers); |
| 851 | 947 |
| 852 profile_params_.reset(); | 948 profile_params_.reset(); |
| 853 initialized_ = true; | 949 initialized_ = true; |
| 854 } | 950 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 void ProfileIOData::SetCookieSettingsForTesting( | 1088 void ProfileIOData::SetCookieSettingsForTesting( |
| 993 CookieSettings* cookie_settings) { | 1089 CookieSettings* cookie_settings) { |
| 994 DCHECK(!cookie_settings_.get()); | 1090 DCHECK(!cookie_settings_.get()); |
| 995 cookie_settings_ = cookie_settings; | 1091 cookie_settings_ = cookie_settings; |
| 996 } | 1092 } |
| 997 | 1093 |
| 998 void ProfileIOData::set_signin_names_for_testing( | 1094 void ProfileIOData::set_signin_names_for_testing( |
| 999 SigninNamesOnIOThread* signin_names) { | 1095 SigninNamesOnIOThread* signin_names) { |
| 1000 signin_names_.reset(signin_names); | 1096 signin_names_.reset(signin_names); |
| 1001 } | 1097 } |
| OLD | NEW |