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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 using content::BrowserThread; | 60 using content::BrowserThread; |
61 | 61 |
62 typedef GoogleServiceAuthError AuthError; | 62 typedef GoogleServiceAuthError AuthError; |
63 | 63 |
64 namespace chromeos { | 64 namespace chromeos { |
65 | 65 |
66 namespace { | 66 namespace { |
67 | 67 |
68 // A vector pref of the users who have logged into the device. | 68 // A vector pref of the users who have logged into the device. |
69 const char kLoggedInUsers[] = "LoggedInUsers"; | 69 const char kLoggedInUsers[] = "LoggedInUsers"; |
| 70 // A dictionary that maps usernames to file paths to their wallpapers. |
| 71 const char kUserWallpapers[] = "UserWallpapers"; |
70 // A dictionary that maps usernames to file paths to their images. | 72 // A dictionary that maps usernames to file paths to their images. |
71 const char kUserImages[] = "UserImages"; | 73 const char kUserImages[] = "UserImages"; |
72 // A dictionary that maps usernames to the displayed (non-canonical) emails. | 74 // A dictionary that maps usernames to the displayed (non-canonical) emails. |
73 const char kUserDisplayEmail[] = "UserDisplayEmail"; | 75 const char kUserDisplayEmail[] = "UserDisplayEmail"; |
74 // A dictionary that maps usernames to OAuth token presence flag. | 76 // A dictionary that maps usernames to OAuth token presence flag. |
75 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; | 77 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; |
76 | 78 |
| 79 // The default wallpaper index. |
| 80 const int kDefaultWallpaperIndex = 0; |
| 81 |
77 // Incognito user is represented by an empty string (since some code already | 82 // Incognito user is represented by an empty string (since some code already |
78 // depends on that and it's hard to figure out what). | 83 // depends on that and it's hard to figure out what). |
79 const char kGuestUser[] = ""; | 84 const char kGuestUser[] = ""; |
80 | 85 |
81 // Stub user email (for test paths). | 86 // Stub user email (for test paths). |
82 const char kStubUser[] = "stub-user@example.com"; | 87 const char kStubUser[] = "stub-user@example.com"; |
83 | 88 |
84 // Names of nodes with info about user image. | 89 // Names of nodes with info about user image. |
85 const char kImagePathNodeName[] = "path"; | 90 const char kImagePathNodeName[] = "path"; |
86 const char kImageIndexNodeName[] = "index"; | 91 const char kImageIndexNodeName[] = "index"; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // static | 301 // static |
297 UserManager* UserManager::Get() { | 302 UserManager* UserManager::Get() { |
298 // Not thread-safe. | 303 // Not thread-safe. |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
300 return &g_user_manager.Get(); | 305 return &g_user_manager.Get(); |
301 } | 306 } |
302 | 307 |
303 // static | 308 // static |
304 void UserManager::RegisterPrefs(PrefService* local_state) { | 309 void UserManager::RegisterPrefs(PrefService* local_state) { |
305 local_state->RegisterListPref(kLoggedInUsers, PrefService::UNSYNCABLE_PREF); | 310 local_state->RegisterListPref(kLoggedInUsers, PrefService::UNSYNCABLE_PREF); |
| 311 local_state->RegisterDictionaryPref(kUserWallpapers, |
| 312 PrefService::UNSYNCABLE_PREF); |
306 local_state->RegisterDictionaryPref(kUserImages, | 313 local_state->RegisterDictionaryPref(kUserImages, |
307 PrefService::UNSYNCABLE_PREF); | 314 PrefService::UNSYNCABLE_PREF); |
308 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, | 315 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, |
309 PrefService::UNSYNCABLE_PREF); | 316 PrefService::UNSYNCABLE_PREF); |
310 local_state->RegisterDictionaryPref(kUserDisplayEmail, | 317 local_state->RegisterDictionaryPref(kUserDisplayEmail, |
311 PrefService::UNSYNCABLE_PREF); | 318 PrefService::UNSYNCABLE_PREF); |
312 } | 319 } |
313 | 320 |
314 const UserList& UserManager::GetUsers() const { | 321 const UserList& UserManager::GetUsers() const { |
315 const_cast<UserManager*>(this)->EnsureUsersLoaded(); | 322 const_cast<UserManager*>(this)->EnsureUsersLoaded(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 UserList::iterator user_to_remove = users_.end(); | 443 UserList::iterator user_to_remove = users_.end(); |
437 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | 444 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { |
438 std::string user_email = (*it)->email(); | 445 std::string user_email = (*it)->email(); |
439 // Skip user that we would like to delete. | 446 // Skip user that we would like to delete. |
440 if (email != user_email) | 447 if (email != user_email) |
441 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 448 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
442 else | 449 else |
443 user_to_remove = it; | 450 user_to_remove = it; |
444 } | 451 } |
445 | 452 |
| 453 DictionaryPrefUpdate prefs_wallpapers_update(prefs, kUserWallpapers); |
| 454 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); |
| 455 |
446 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | 456 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); |
447 std::string image_path_string; | 457 std::string image_path_string; |
448 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | 458 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); |
449 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | 459 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); |
450 | 460 |
451 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 461 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
452 int oauth_status; | 462 int oauth_status; |
453 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 463 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
454 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 464 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
455 | 465 |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 base::Bind(&UserManager::CheckOwnership, | 842 base::Bind(&UserManager::CheckOwnership, |
833 base::Unretained(this))); | 843 base::Unretained(this))); |
834 } | 844 } |
835 | 845 |
836 void UserManager::SetInitialUserImage(const std::string& username) { | 846 void UserManager::SetInitialUserImage(const std::string& username) { |
837 // Choose a random default image. | 847 // Choose a random default image. |
838 int image_id = base::RandInt(0, kDefaultImagesCount - 1); | 848 int image_id = base::RandInt(0, kDefaultImagesCount - 1); |
839 SaveUserDefaultImageIndex(username, image_id); | 849 SaveUserDefaultImageIndex(username, image_id); |
840 } | 850 } |
841 | 851 |
| 852 int UserManager::GetUserWallpaper(const std::string& username) { |
| 853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 854 |
| 855 PrefService* local_state = g_browser_process->local_state(); |
| 856 const DictionaryValue* user_wallpapers = |
| 857 local_state->GetDictionary(kUserWallpapers); |
| 858 int index = kDefaultWallpaperIndex; |
| 859 user_wallpapers->GetIntegerWithoutPathExpansion(username, |
| 860 &index); |
| 861 return index; |
| 862 } |
| 863 |
| 864 void UserManager::SaveWallpaperToLocalState(const std::string& username, |
| 865 int wallpaper_index) { |
| 866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 867 |
| 868 PrefService* local_state = g_browser_process->local_state(); |
| 869 DictionaryPrefUpdate wallpapers_update(local_state, kUserWallpapers); |
| 870 wallpapers_update->SetWithoutPathExpansion(username, |
| 871 new base::FundamentalValue(wallpaper_index)); |
| 872 } |
| 873 |
842 void UserManager::SetUserImage(const std::string& username, | 874 void UserManager::SetUserImage(const std::string& username, |
843 int image_index, | 875 int image_index, |
844 const SkBitmap& image) { | 876 const SkBitmap& image) { |
845 User* user = const_cast<User*>(FindUser(username)); | 877 User* user = const_cast<User*>(FindUser(username)); |
846 // User may have been removed by now. | 878 // User may have been removed by now. |
847 if (user) { | 879 if (user) { |
848 // For existing users, a valid image index should have been set upon loading | 880 // For existing users, a valid image index should have been set upon loading |
849 // them from Local State. | 881 // them from Local State. |
850 DCHECK(user->image_index() != User::kInvalidImageIndex || | 882 DCHECK(user->image_index() != User::kInvalidImageIndex || |
851 current_user_is_new_); | 883 current_user_is_new_); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 | 1099 |
1068 User* UserManager::CreateUser(const std::string& email) const { | 1100 User* UserManager::CreateUser(const std::string& email) const { |
1069 User* user = new User(email, email == kGuestUser); | 1101 User* user = new User(email, email == kGuestUser); |
1070 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 1102 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
1071 // Used to determine whether user's display name is unique. | 1103 // Used to determine whether user's display name is unique. |
1072 ++display_name_count_[user->GetDisplayName()]; | 1104 ++display_name_count_[user->GetDisplayName()]; |
1073 return user; | 1105 return user; |
1074 } | 1106 } |
1075 | 1107 |
1076 } // namespace chromeos | 1108 } // namespace chromeos |
OLD | NEW |