OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/weak_ptr.h" |
13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | 16 #include "base/path_service.h" |
15 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
16 #include "base/string_util.h" | 18 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
18 #include "base/time.h" | 20 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 22 #include "base/values.h" |
21 #include "crypto/nss_util.h" | 23 #include "crypto/nss_util.h" |
22 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chromeos/cros_settings.h" |
23 #include "chrome/browser/chromeos/cros/cros_library.h" | 26 #include "chrome/browser/chromeos/cros/cros_library.h" |
24 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 27 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
25 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 28 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
26 #include "chrome/browser/chromeos/login/default_user_images.h" | 29 #include "chrome/browser/chromeos/login/default_user_images.h" |
27 #include "chrome/browser/chromeos/login/login_display.h" | 30 #include "chrome/browser/chromeos/login/login_display.h" |
28 #include "chrome/browser/chromeos/login/ownership_service.h" | 31 #include "chrome/browser/chromeos/login/ownership_service.h" |
29 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 32 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
30 #include "chrome/browser/chromeos/wm_ipc.h" | 33 #include "chrome/browser/chromeos/wm_ipc.h" |
31 #include "chrome/browser/defaults.h" | 34 #include "chrome/browser/defaults.h" |
32 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if (file_util::WriteFile(image_path, | 128 if (file_util::WriteFile(image_path, |
126 reinterpret_cast<char*>(&encoded_image[0]), | 129 reinterpret_cast<char*>(&encoded_image[0]), |
127 encoded_image.size()) == -1) { | 130 encoded_image.size()) == -1) { |
128 LOG(ERROR) << "Failed to save image to file."; | 131 LOG(ERROR) << "Failed to save image to file."; |
129 return; | 132 return; |
130 } | 133 } |
131 | 134 |
132 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
133 BrowserThread::UI, | 136 BrowserThread::UI, |
134 FROM_HERE, | 137 FROM_HERE, |
135 NewRunnableFunction(&SavePathToLocalState, | 138 base::Bind(&SavePathToLocalState, |
136 username, image_path.value())); | 139 username, image_path.value())); |
137 } | 140 } |
138 | 141 |
139 // Deletes user's image file. Runs on FILE thread. | 142 // Deletes user's image file. Runs on FILE thread. |
140 void DeleteUserImage(const FilePath& image_path) { | 143 void DeleteUserImage(const FilePath& image_path) { |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
142 if (!file_util::Delete(image_path, false)) { | 145 if (!file_util::Delete(image_path, false)) { |
143 LOG(ERROR) << "Failed to remove user image."; | 146 LOG(ERROR) << "Failed to remove user image."; |
144 return; | 147 return; |
145 } | 148 } |
146 } | 149 } |
(...skipping 19 matching lines...) Expand all Loading... |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
167 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); | 170 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); |
168 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); | 171 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); |
169 | 172 |
170 g_user_manager.Get().set_current_user_is_owner(is_owner); | 173 g_user_manager.Get().set_current_user_is_owner(is_owner); |
171 | 174 |
172 // UserManager should be accessed only on UI thread. | 175 // UserManager should be accessed only on UI thread. |
173 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
174 BrowserThread::UI, | 177 BrowserThread::UI, |
175 FROM_HERE, | 178 FROM_HERE, |
176 NewRunnableFunction(&UpdateOwnership, is_owner)); | 179 base::Bind(&UpdateOwnership, is_owner)); |
177 } | 180 } |
178 | 181 |
179 // Used to handle the asynchronous response of deleting a cryptohome directory. | 182 // Used to handle the asynchronous response of deleting a cryptohome directory. |
180 class RemoveAttempt : public CryptohomeLibrary::Delegate { | 183 class RemoveAttempt : public CryptohomeLibrary::Delegate { |
181 public: | 184 public: |
182 // Creates new remove attempt for the given user. Note, |delegate| can | 185 // Creates new remove attempt for the given user. Note, |delegate| can |
183 // be NULL. | 186 // be NULL. |
184 RemoveAttempt(const std::string& user_email, | 187 RemoveAttempt(const std::string& user_email, |
185 chromeos::RemoveUserDelegate* delegate) | 188 chromeos::RemoveUserDelegate* delegate) |
186 : user_email_(user_email), | 189 : user_email_(user_email), |
187 delegate_(delegate), | 190 delegate_(delegate), |
188 method_factory_(this) { | 191 pointer_factory_(this) { |
189 RemoveUser(); | 192 RemoveUser(); |
190 } | 193 } |
191 | 194 |
192 virtual ~RemoveAttempt() {} | 195 virtual ~RemoveAttempt() {} |
193 | 196 |
194 void RemoveUser() { | 197 void RemoveUser() { |
195 // Owner is not allowed to be removed from the device. | 198 // Owner is not allowed to be removed from the device. |
196 // Must not proceed without signature verification. | 199 // Must not proceed without signature verification. |
197 UserCrosSettingsProvider user_settings; | 200 CrosSettings* cros_settings = CrosSettings::Get(); |
198 bool trusted_owner_available = user_settings.RequestTrustedOwner( | 201 bool trusted_owner_available = cros_settings->GetTrusted( |
199 method_factory_.NewRunnableMethod(&RemoveAttempt::RemoveUser)); | 202 kDeviceOwner, |
| 203 base::Bind(&RemoveAttempt::RemoveUser, pointer_factory_.GetWeakPtr())); |
200 if (!trusted_owner_available) { | 204 if (!trusted_owner_available) { |
201 // Value of owner email is still not verified. | 205 // Value of owner email is still not verified. |
202 // Another attempt will be invoked after verification completion. | 206 // Another attempt will be invoked after verification completion. |
203 return; | 207 return; |
204 } | 208 } |
205 if (user_email_ == UserCrosSettingsProvider::cached_owner()) { | 209 std::string owner; |
| 210 cros_settings->GetString(kDeviceOwner, &owner); |
| 211 if (user_email_ == owner) { |
206 // Owner is not allowed to be removed from the device. Probably on | 212 // Owner is not allowed to be removed from the device. Probably on |
207 // the stack, so deffer the deletion. | 213 // the stack, so deffer the deletion. |
208 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 214 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
209 return; | 215 return; |
210 } | 216 } |
211 | 217 |
212 if (delegate_) | 218 if (delegate_) |
213 delegate_->OnBeforeUserRemoved(user_email_); | 219 delegate_->OnBeforeUserRemoved(user_email_); |
214 | 220 |
215 chromeos::UserManager::Get()->RemoveUserFromList(user_email_); | 221 chromeos::UserManager::Get()->RemoveUserFromList(user_email_); |
(...skipping 17 matching lines...) Expand all Loading... |
233 << " failed, return code: " << return_code; | 239 << " failed, return code: " << return_code; |
234 } | 240 } |
235 delete this; | 241 delete this; |
236 } | 242 } |
237 | 243 |
238 private: | 244 private: |
239 std::string user_email_; | 245 std::string user_email_; |
240 chromeos::RemoveUserDelegate* delegate_; | 246 chromeos::RemoveUserDelegate* delegate_; |
241 | 247 |
242 // Factory of callbacks. | 248 // Factory of callbacks. |
243 ScopedRunnableMethodFactory<RemoveAttempt> method_factory_; | 249 base::WeakPtrFactory<RemoveAttempt> pointer_factory_; |
244 | 250 |
245 DISALLOW_COPY_AND_ASSIGN(RemoveAttempt); | 251 DISALLOW_COPY_AND_ASSIGN(RemoveAttempt); |
246 }; | 252 }; |
247 | 253 |
248 } // namespace | 254 } // namespace |
249 | 255 |
250 UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 256 UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
251 is_displayname_unique_(false) { | 257 is_displayname_unique_(false) { |
252 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 258 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
253 kDefaultImageResources[0]); | 259 kDefaultImageResources[0]); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 482 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
477 | 483 |
478 prefs->SavePersistentPrefs(); | 484 prefs->SavePersistentPrefs(); |
479 | 485 |
480 int default_image_id = kDefaultImagesCount; | 486 int default_image_id = kDefaultImagesCount; |
481 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { | 487 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { |
482 FilePath image_path(image_path_string); | 488 FilePath image_path(image_path_string); |
483 BrowserThread::PostTask( | 489 BrowserThread::PostTask( |
484 BrowserThread::FILE, | 490 BrowserThread::FILE, |
485 FROM_HERE, | 491 FROM_HERE, |
486 NewRunnableFunction(&DeleteUserImage, | 492 base::Bind(&DeleteUserImage, image_path)); |
487 image_path)); | |
488 } | 493 } |
489 } | 494 } |
490 | 495 |
491 bool UserManager::IsKnownUser(const std::string& email) { | 496 bool UserManager::IsKnownUser(const std::string& email) { |
492 std::vector<User> users = GetUsers(); | 497 std::vector<User> users = GetUsers(); |
493 for (std::vector<User>::iterator it = users.begin(); | 498 for (std::vector<User>::iterator it = users.begin(); |
494 it < users.end(); | 499 it < users.end(); |
495 ++it) { | 500 ++it) { |
496 if (it->email() == email) | 501 if (it->email() == email) |
497 return true; | 502 return true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 535 |
531 void UserManager::SaveUserImage(const std::string& username, | 536 void UserManager::SaveUserImage(const std::string& username, |
532 const SkBitmap& image) { | 537 const SkBitmap& image) { |
533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
534 FilePath image_path = GetImagePathForUser(username); | 539 FilePath image_path = GetImagePathForUser(username); |
535 DVLOG(1) << "Saving user image to " << image_path.value(); | 540 DVLOG(1) << "Saving user image to " << image_path.value(); |
536 | 541 |
537 BrowserThread::PostTask( | 542 BrowserThread::PostTask( |
538 BrowserThread::FILE, | 543 BrowserThread::FILE, |
539 FROM_HERE, | 544 FROM_HERE, |
540 NewRunnableFunction(&SaveImageToFile, | 545 base::Bind(&SaveImageToFile, |
541 image, image_path, username)); | 546 image, image_path, username)); |
542 } | 547 } |
543 | 548 |
544 void UserManager::SaveUserOAuthStatus(const std::string& username, | 549 void UserManager::SaveUserOAuthStatus(const std::string& username, |
545 OAuthTokenStatus oauth_token_status) { | 550 OAuthTokenStatus oauth_token_status) { |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
547 SaveOAuthTokenStatusToLocalState(username, oauth_token_status); | 552 SaveOAuthTokenStatusToLocalState(username, oauth_token_status); |
548 } | 553 } |
549 | 554 |
550 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( | 555 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( |
551 const std::string& username) { | 556 const std::string& username) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 // Only load the Opencryptoki library into NSS if we have this switch. | 683 // Only load the Opencryptoki library into NSS if we have this switch. |
679 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 684 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
680 // http://crosbug.com/12295 and http://crosbug.com/12304 | 685 // http://crosbug.com/12295 and http://crosbug.com/12304 |
681 if (CommandLine::ForCurrentProcess()->HasSwitch( | 686 if (CommandLine::ForCurrentProcess()->HasSwitch( |
682 switches::kLoadOpencryptoki)) { | 687 switches::kLoadOpencryptoki)) { |
683 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); | 688 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); |
684 } | 689 } |
685 | 690 |
686 // Schedules current user ownership check on file thread. | 691 // Schedules current user ownership check on file thread. |
687 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 692 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
688 NewRunnableFunction(&CheckOwnership)); | 693 base::Bind(&CheckOwnership)); |
689 } | 694 } |
690 | 695 |
691 void UserManager::Observe(int type, | 696 void UserManager::Observe(int type, |
692 const NotificationSource& source, | 697 const NotificationSource& source, |
693 const NotificationDetails& details) { | 698 const NotificationDetails& details) { |
694 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | 699 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
695 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 700 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
696 NewRunnableFunction(&CheckOwnership)); | 701 base::Bind(&CheckOwnership)); |
697 } | 702 } |
698 } | 703 } |
699 | 704 |
700 bool UserManager::current_user_is_owner() const { | 705 bool UserManager::current_user_is_owner() const { |
701 base::AutoLock lk(current_user_is_owner_lock_); | 706 base::AutoLock lk(current_user_is_owner_lock_); |
702 return current_user_is_owner_; | 707 return current_user_is_owner_; |
703 } | 708 } |
704 | 709 |
705 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { | 710 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { |
706 base::AutoLock lk(current_user_is_owner_lock_); | 711 base::AutoLock lk(current_user_is_owner_lock_); |
707 current_user_is_owner_ = current_user_is_owner; | 712 current_user_is_owner_ = current_user_is_owner; |
708 } | 713 } |
709 | 714 |
710 void UserManager::AddObserver(Observer* obs) { | 715 void UserManager::AddObserver(Observer* obs) { |
711 observer_list_.AddObserver(obs); | 716 observer_list_.AddObserver(obs); |
712 } | 717 } |
713 | 718 |
714 void UserManager::RemoveObserver(Observer* obs) { | 719 void UserManager::RemoveObserver(Observer* obs) { |
715 observer_list_.RemoveObserver(obs); | 720 observer_list_.RemoveObserver(obs); |
716 } | 721 } |
717 | 722 |
718 void UserManager::NotifyLocalStateChanged() { | 723 void UserManager::NotifyLocalStateChanged() { |
719 FOR_EACH_OBSERVER( | 724 FOR_EACH_OBSERVER( |
720 Observer, | 725 Observer, |
721 observer_list_, | 726 observer_list_, |
722 LocalStateChanged(this)); | 727 LocalStateChanged(this)); |
723 } | 728 } |
724 | 729 |
725 } // namespace chromeos | 730 } // namespace chromeos |
OLD | NEW |