| 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/chromeos/login/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 RealTPMTokenInfoDelegate::RealTPMTokenInfoDelegate() : token_ready_(false) {} | 232 RealTPMTokenInfoDelegate::RealTPMTokenInfoDelegate() : token_ready_(false) {} |
| 233 RealTPMTokenInfoDelegate::~RealTPMTokenInfoDelegate() {} | 233 RealTPMTokenInfoDelegate::~RealTPMTokenInfoDelegate() {} |
| 234 | 234 |
| 235 bool RealTPMTokenInfoDelegate::IsTokenAvailable() const { | 235 bool RealTPMTokenInfoDelegate::IsTokenAvailable() const { |
| 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 return CrosLibrary::Get()->GetCryptohomeLibrary()->TpmIsEnabled(); | 237 return CrosLibrary::Get()->GetCryptohomeLibrary()->TpmIsEnabled(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 bool RealTPMTokenInfoDelegate::IsTokenReady() const { | 240 bool RealTPMTokenInfoDelegate::IsTokenReady() const { |
| 241 // Note: This should only be getting called from the UI thread, however |
| 242 // if this does get called from another thread and token_ready_ is true, |
| 243 // we can safely just return true here. |
| 244 // TODO(stevenjb/gspencer): Clean this up to improve thread safety. |
| 245 if (token_ready_) |
| 246 return true; |
| 241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 242 if (!token_ready_) { | 248 // Retrieve token_name_ and user_pin_ here since they will never change |
| 243 // Retrieve token_name_ and user_pin_ here since they will never change | 249 // and CryptohomeLibrary calls are not thread safe. |
| 244 // and CryptohomeLibrary calls are not thread safe. | 250 if (CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11IsTpmTokenReady()) { |
| 245 if (CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11IsTpmTokenReady()) { | 251 CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11GetTpmTokenInfo( |
| 246 CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11GetTpmTokenInfo( | 252 &token_name_, &user_pin_); |
| 247 &token_name_, &user_pin_); | 253 token_ready_ = true; |
| 248 token_ready_ = true; | |
| 249 } | |
| 250 } | 254 } |
| 251 return token_ready_; | 255 return token_ready_; |
| 252 } | 256 } |
| 253 | 257 |
| 254 void RealTPMTokenInfoDelegate::GetTokenInfo(std::string* token_name, | 258 void RealTPMTokenInfoDelegate::GetTokenInfo(std::string* token_name, |
| 255 std::string* user_pin) const { | 259 std::string* user_pin) const { |
| 256 // May be called from a non UI thread, but must only be called after | 260 // May be called from a non UI thread, but must only be called after |
| 257 // IsTokenReady() returns true. | 261 // IsTokenReady() returns true. |
| 258 CHECK(token_ready_); | 262 CHECK(token_ready_); |
| 259 if (token_name) | 263 if (token_name) |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 } | 722 } |
| 719 } | 723 } |
| 720 | 724 |
| 721 void UserManager::StubUserLoggedIn() { | 725 void UserManager::StubUserLoggedIn() { |
| 722 logged_in_user_ = &stub_user_; | 726 logged_in_user_ = &stub_user_; |
| 723 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), | 727 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), |
| 724 kStubDefaultImageIndex); | 728 kStubDefaultImageIndex); |
| 725 } | 729 } |
| 726 | 730 |
| 727 void UserManager::NotifyOnLogin() { | 731 void UserManager::NotifyOnLogin() { |
| 732 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 728 content::NotificationService::current()->Notify( | 733 content::NotificationService::current()->Notify( |
| 729 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 734 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 730 content::Source<UserManager>(this), | 735 content::Source<UserManager>(this), |
| 731 content::Details<const User>(logged_in_user_)); | 736 content::Details<const User>(logged_in_user_)); |
| 732 | 737 |
| 733 chromeos::input_method::InputMethodManager::GetInstance()-> | 738 chromeos::input_method::InputMethodManager::GetInstance()-> |
| 734 SetDeferImeStartup(false); | 739 SetDeferImeStartup(false); |
| 735 // Shut down the IME so that it will reload the user's settings. | 740 // Shut down the IME so that it will reload the user's settings. |
| 736 chromeos::input_method::InputMethodManager::GetInstance()-> | 741 chromeos::input_method::InputMethodManager::GetInstance()-> |
| 737 StopInputMethodDaemon(); | 742 StopInputMethodDaemon(); |
| 738 | 743 |
| 739 #if defined(TOOLKIT_USES_GTK) | 744 #if defined(TOOLKIT_USES_GTK) |
| 740 // Let the window manager know that we're logged in now. | 745 // Let the window manager know that we're logged in now. |
| 741 WmIpc::instance()->SetLoggedInProperty(true); | 746 WmIpc::instance()->SetLoggedInProperty(true); |
| 742 #endif | 747 #endif |
| 743 | 748 |
| 744 // Ensure we've opened the real user's key/certificate database. | 749 // Ensure we've opened the real user's key/certificate database. |
| 745 crypto::OpenPersistentNSSDB(); | 750 crypto::OpenPersistentNSSDB(); |
| 746 | 751 |
| 747 // Only load the Opencryptoki library into NSS if we have this switch. | 752 // Only load the Opencryptoki library into NSS if we have this switch. |
| 748 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 753 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
| 749 // http://crosbug.com/12295 and http://crosbug.com/12304 | 754 // http://crosbug.com/12295 and http://crosbug.com/12304 |
| 750 if (CommandLine::ForCurrentProcess()->HasSwitch( | 755 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 751 switches::kLoadOpencryptoki)) { | 756 switches::kLoadOpencryptoki)) { |
| 752 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); | 757 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); |
| 753 CertLibrary* cert_library; | 758 CertLibrary* cert_library; |
| 754 cert_library = chromeos::CrosLibrary::Get()->GetCertLibrary(); | 759 cert_library = chromeos::CrosLibrary::Get()->GetCertLibrary(); |
| 760 // Note: this calls crypto::EnsureTPMTokenReady() |
| 755 cert_library->RequestCertificates(); | 761 cert_library->RequestCertificates(); |
| 756 } | 762 } |
| 757 | 763 |
| 758 // Schedules current user ownership check on file thread. | 764 // Schedules current user ownership check on file thread. |
| 759 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 765 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 760 base::Bind(&UserManager::CheckOwnership, | 766 base::Bind(&UserManager::CheckOwnership, |
| 761 base::Unretained(this))); | 767 base::Unretained(this))); |
| 762 } | 768 } |
| 763 | 769 |
| 764 void UserManager::SetInitialUserImage(const std::string& username) { | 770 void UserManager::SetInitialUserImage(const std::string& username) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1001 |
| 996 User* UserManager::CreateUser(const std::string& email) const { | 1002 User* UserManager::CreateUser(const std::string& email) const { |
| 997 User* user = new User(email, email == kGuestUser); | 1003 User* user = new User(email, email == kGuestUser); |
| 998 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 1004 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 999 // Used to determine whether user's display name is unique. | 1005 // Used to determine whether user's display name is unique. |
| 1000 ++display_name_count_[user->GetDisplayName()]; | 1006 ++display_name_count_[user->GetDisplayName()]; |
| 1001 return user; | 1007 return user; |
| 1002 } | 1008 } |
| 1003 | 1009 |
| 1004 } // namespace chromeos | 1010 } // namespace chromeos |
| OLD | NEW |