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/location.h" | 13 #include "base/location.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/weak_ptr.h" |
14 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | 17 #include "base/path_service.h" |
16 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
17 #include "base/string_util.h" | 19 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
19 #include "base/time.h" | 21 #include "base/time.h" |
20 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 23 #include "base/values.h" |
22 #include "crypto/nss_util.h" | 24 #include "crypto/nss_util.h" |
23 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chromeos/cros_settings.h" |
24 #include "chrome/browser/chromeos/cros/cros_library.h" | 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
25 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 28 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
26 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 29 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
27 #include "chrome/browser/chromeos/login/default_user_images.h" | 30 #include "chrome/browser/chromeos/login/default_user_images.h" |
28 #include "chrome/browser/chromeos/login/login_display.h" | 31 #include "chrome/browser/chromeos/login/login_display.h" |
29 #include "chrome/browser/chromeos/login/ownership_service.h" | 32 #include "chrome/browser/chromeos/login/ownership_service.h" |
30 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 33 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
31 #include "chrome/browser/chromeos/wm_ipc.h" | 34 #include "chrome/browser/chromeos/wm_ipc.h" |
32 #include "chrome/browser/defaults.h" | 35 #include "chrome/browser/defaults.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 36 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (file_util::WriteFile(image_path, | 143 if (file_util::WriteFile(image_path, |
141 reinterpret_cast<char*>(&encoded_image[0]), | 144 reinterpret_cast<char*>(&encoded_image[0]), |
142 encoded_image.size()) == -1) { | 145 encoded_image.size()) == -1) { |
143 LOG(ERROR) << "Failed to save image to file."; | 146 LOG(ERROR) << "Failed to save image to file."; |
144 return; | 147 return; |
145 } | 148 } |
146 | 149 |
147 BrowserThread::PostTask( | 150 BrowserThread::PostTask( |
148 BrowserThread::UI, | 151 BrowserThread::UI, |
149 FROM_HERE, | 152 FROM_HERE, |
150 NewRunnableFunction(&SaveImageToLocalState, | 153 base::Bind(&SaveImageToLocalState, |
151 username, image_path.value(), image_index)); | 154 username, image_path.value(), image_index)); |
152 } | 155 } |
153 | 156 |
154 // Deletes user's image file. Runs on FILE thread. | 157 // Deletes user's image file. Runs on FILE thread. |
155 void DeleteUserImage(const FilePath& image_path) { | 158 void DeleteUserImage(const FilePath& image_path) { |
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
157 if (!file_util::Delete(image_path, false)) { | 160 if (!file_util::Delete(image_path, false)) { |
158 LOG(ERROR) << "Failed to remove user image."; | 161 LOG(ERROR) << "Failed to remove user image."; |
159 return; | 162 return; |
160 } | 163 } |
161 } | 164 } |
(...skipping 19 matching lines...) Expand all Loading... |
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
182 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); | 185 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); |
183 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); | 186 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); |
184 | 187 |
185 g_user_manager.Get().set_current_user_is_owner(is_owner); | 188 g_user_manager.Get().set_current_user_is_owner(is_owner); |
186 | 189 |
187 // UserManager should be accessed only on UI thread. | 190 // UserManager should be accessed only on UI thread. |
188 BrowserThread::PostTask( | 191 BrowserThread::PostTask( |
189 BrowserThread::UI, | 192 BrowserThread::UI, |
190 FROM_HERE, | 193 FROM_HERE, |
191 NewRunnableFunction(&UpdateOwnership, is_owner)); | 194 base::Bind(&UpdateOwnership, is_owner)); |
192 } | 195 } |
193 | 196 |
194 // Used to handle the asynchronous response of deleting a cryptohome directory. | 197 // Used to handle the asynchronous response of deleting a cryptohome directory. |
195 class RemoveAttempt : public CryptohomeLibrary::Delegate { | 198 class RemoveAttempt : public CryptohomeLibrary::Delegate { |
196 public: | 199 public: |
197 // Creates new remove attempt for the given user. Note, |delegate| can | 200 // Creates new remove attempt for the given user. Note, |delegate| can |
198 // be NULL. | 201 // be NULL. |
199 RemoveAttempt(const std::string& user_email, | 202 RemoveAttempt(const std::string& user_email, |
200 chromeos::RemoveUserDelegate* delegate) | 203 chromeos::RemoveUserDelegate* delegate) |
201 : user_email_(user_email), | 204 : user_email_(user_email), |
202 delegate_(delegate), | 205 delegate_(delegate), |
203 method_factory_(this) { | 206 pointer_factory_(this) { |
204 RemoveUser(); | 207 RemoveUser(); |
205 } | 208 } |
206 | 209 |
207 virtual ~RemoveAttempt() {} | 210 virtual ~RemoveAttempt() {} |
208 | 211 |
209 void RemoveUser() { | 212 void RemoveUser() { |
210 // Owner is not allowed to be removed from the device. | 213 // Owner is not allowed to be removed from the device. |
211 // Must not proceed without signature verification. | 214 // Must not proceed without signature verification. |
212 UserCrosSettingsProvider user_settings; | 215 CrosSettings* cros_settings = CrosSettings::Get(); |
213 bool trusted_owner_available = user_settings.RequestTrustedOwner( | 216 bool trusted_owner_available = cros_settings->GetTrusted( |
214 method_factory_.NewRunnableMethod(&RemoveAttempt::RemoveUser)); | 217 kDeviceOwner, |
| 218 base::Bind(&RemoveAttempt::RemoveUser, pointer_factory_.GetWeakPtr())); |
215 if (!trusted_owner_available) { | 219 if (!trusted_owner_available) { |
216 // Value of owner email is still not verified. | 220 // Value of owner email is still not verified. |
217 // Another attempt will be invoked after verification completion. | 221 // Another attempt will be invoked after verification completion. |
218 return; | 222 return; |
219 } | 223 } |
220 if (user_email_ == UserCrosSettingsProvider::cached_owner()) { | 224 std::string owner; |
| 225 cros_settings->GetString(kDeviceOwner, &owner); |
| 226 if (user_email_ == owner) { |
221 // Owner is not allowed to be removed from the device. Probably on | 227 // Owner is not allowed to be removed from the device. Probably on |
222 // the stack, so deffer the deletion. | 228 // the stack, so deffer the deletion. |
223 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 229 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
224 return; | 230 return; |
225 } | 231 } |
226 | 232 |
227 if (delegate_) | 233 if (delegate_) |
228 delegate_->OnBeforeUserRemoved(user_email_); | 234 delegate_->OnBeforeUserRemoved(user_email_); |
229 | 235 |
230 chromeos::UserManager::Get()->RemoveUserFromList(user_email_); | 236 chromeos::UserManager::Get()->RemoveUserFromList(user_email_); |
(...skipping 17 matching lines...) Expand all Loading... |
248 << " failed, return code: " << return_code; | 254 << " failed, return code: " << return_code; |
249 } | 255 } |
250 delete this; | 256 delete this; |
251 } | 257 } |
252 | 258 |
253 private: | 259 private: |
254 std::string user_email_; | 260 std::string user_email_; |
255 chromeos::RemoveUserDelegate* delegate_; | 261 chromeos::RemoveUserDelegate* delegate_; |
256 | 262 |
257 // Factory of callbacks. | 263 // Factory of callbacks. |
258 ScopedRunnableMethodFactory<RemoveAttempt> method_factory_; | 264 base::WeakPtrFactory<RemoveAttempt> pointer_factory_; |
259 | 265 |
260 DISALLOW_COPY_AND_ASSIGN(RemoveAttempt); | 266 DISALLOW_COPY_AND_ASSIGN(RemoveAttempt); |
261 }; | 267 }; |
262 | 268 |
263 } // namespace | 269 } // namespace |
264 | 270 |
265 UserManager::User::User() | 271 UserManager::User::User() |
266 : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 272 : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
267 is_displayname_unique_(false), | 273 is_displayname_unique_(false), |
268 default_image_index_(kInvalidImageIndex) { | 274 default_image_index_(kInvalidImageIndex) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 546 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
541 | 547 |
542 prefs->SavePersistentPrefs(); | 548 prefs->SavePersistentPrefs(); |
543 | 549 |
544 int default_image_id = kDefaultImagesCount; | 550 int default_image_id = kDefaultImagesCount; |
545 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { | 551 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { |
546 FilePath image_path(image_path_string); | 552 FilePath image_path(image_path_string); |
547 BrowserThread::PostTask( | 553 BrowserThread::PostTask( |
548 BrowserThread::FILE, | 554 BrowserThread::FILE, |
549 FROM_HERE, | 555 FROM_HERE, |
550 NewRunnableFunction(&DeleteUserImage, | 556 base::Bind(&DeleteUserImage, image_path)); |
551 image_path)); | |
552 } | 557 } |
553 } | 558 } |
554 | 559 |
555 bool UserManager::IsKnownUser(const std::string& email) { | 560 bool UserManager::IsKnownUser(const std::string& email) { |
556 std::vector<User> users = GetUsers(); | 561 std::vector<User> users = GetUsers(); |
557 for (std::vector<User>::iterator it = users.begin(); | 562 for (std::vector<User>::iterator it = users.begin(); |
558 it < users.end(); | 563 it < users.end(); |
559 ++it) { | 564 ++it) { |
560 if (it->email() == email) | 565 if (it->email() == email) |
561 return true; | 566 return true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 void UserManager::SaveUserImage(const std::string& username, | 603 void UserManager::SaveUserImage(const std::string& username, |
599 const SkBitmap& image, | 604 const SkBitmap& image, |
600 int image_index) { | 605 int image_index) { |
601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
602 FilePath image_path = GetImagePathForUser(username); | 607 FilePath image_path = GetImagePathForUser(username); |
603 DVLOG(1) << "Saving user image to " << image_path.value(); | 608 DVLOG(1) << "Saving user image to " << image_path.value(); |
604 | 609 |
605 BrowserThread::PostTask( | 610 BrowserThread::PostTask( |
606 BrowserThread::FILE, | 611 BrowserThread::FILE, |
607 FROM_HERE, | 612 FROM_HERE, |
608 NewRunnableFunction(&SaveImageToFile, | 613 base::Bind(&SaveImageToFile, |
609 image, image_path, username, image_index)); | 614 image, image_path, username, image_index)); |
610 } | 615 } |
611 | 616 |
612 void UserManager::SaveUserOAuthStatus(const std::string& username, | 617 void UserManager::SaveUserOAuthStatus(const std::string& username, |
613 OAuthTokenStatus oauth_token_status) { | 618 OAuthTokenStatus oauth_token_status) { |
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
615 SaveOAuthTokenStatusToLocalState(username, oauth_token_status); | 620 SaveOAuthTokenStatusToLocalState(username, oauth_token_status); |
616 } | 621 } |
617 | 622 |
618 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( | 623 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( |
619 const std::string& username) { | 624 const std::string& username) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 // Only load the Opencryptoki library into NSS if we have this switch. | 768 // Only load the Opencryptoki library into NSS if we have this switch. |
764 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 769 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
765 // http://crosbug.com/12295 and http://crosbug.com/12304 | 770 // http://crosbug.com/12295 and http://crosbug.com/12304 |
766 if (CommandLine::ForCurrentProcess()->HasSwitch( | 771 if (CommandLine::ForCurrentProcess()->HasSwitch( |
767 switches::kLoadOpencryptoki)) { | 772 switches::kLoadOpencryptoki)) { |
768 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); | 773 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); |
769 } | 774 } |
770 | 775 |
771 // Schedules current user ownership check on file thread. | 776 // Schedules current user ownership check on file thread. |
772 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 777 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
773 NewRunnableFunction(&CheckOwnership)); | 778 base::Bind(&CheckOwnership)); |
774 } | 779 } |
775 | 780 |
776 void UserManager::Observe(int type, | 781 void UserManager::Observe(int type, |
777 const NotificationSource& source, | 782 const NotificationSource& source, |
778 const NotificationDetails& details) { | 783 const NotificationDetails& details) { |
779 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | 784 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
780 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 785 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
781 NewRunnableFunction(&CheckOwnership)); | 786 base::Bind(&CheckOwnership)); |
782 } | 787 } |
783 } | 788 } |
784 | 789 |
785 bool UserManager::current_user_is_owner() const { | 790 bool UserManager::current_user_is_owner() const { |
786 base::AutoLock lk(current_user_is_owner_lock_); | 791 base::AutoLock lk(current_user_is_owner_lock_); |
787 return current_user_is_owner_; | 792 return current_user_is_owner_; |
788 } | 793 } |
789 | 794 |
790 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { | 795 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { |
791 base::AutoLock lk(current_user_is_owner_lock_); | 796 base::AutoLock lk(current_user_is_owner_lock_); |
(...skipping 14 matching lines...) Expand all Loading... |
806 observer_list_, | 811 observer_list_, |
807 LocalStateChanged(this)); | 812 LocalStateChanged(this)); |
808 } | 813 } |
809 | 814 |
810 void UserManager::DownloadProfileImage() { | 815 void UserManager::DownloadProfileImage() { |
811 profile_image_downloader_.reset(new ProfileImageDownloader(this)); | 816 profile_image_downloader_.reset(new ProfileImageDownloader(this)); |
812 profile_image_downloader_->Start(); | 817 profile_image_downloader_->Start(); |
813 } | 818 } |
814 | 819 |
815 } // namespace chromeos | 820 } // namespace chromeos |
OLD | NEW |