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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/nss_util.h" | 12 #include "base/nss_util.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 // Resource IDs of default user images. | 59 // Resource IDs of default user images. |
59 const int kDefaultImageResources[] = { | 60 const int kDefaultImageResources[] = { |
60 IDR_LOGIN_DEFAULT_USER, | 61 IDR_LOGIN_DEFAULT_USER, |
61 IDR_LOGIN_DEFAULT_USER_1, | 62 IDR_LOGIN_DEFAULT_USER_1, |
62 IDR_LOGIN_DEFAULT_USER_2, | 63 IDR_LOGIN_DEFAULT_USER_2, |
63 IDR_LOGIN_DEFAULT_USER_3, | 64 IDR_LOGIN_DEFAULT_USER_3, |
64 IDR_LOGIN_DEFAULT_USER_4 | 65 IDR_LOGIN_DEFAULT_USER_4 |
65 }; | 66 }; |
66 | 67 |
67 // The one true UserManager. | 68 base::LazyInstance<UserManager> g_user_manager(base::LINKER_INITIALIZED); |
68 static UserManager* user_manager_ = NULL; | |
69 | 69 |
70 // Stores path to the image in local state. Runs on UI thread. | 70 // Stores path to the image in local state. Runs on UI thread. |
71 void SavePathToLocalState(const std::string& username, | 71 void SavePathToLocalState(const std::string& username, |
72 const std::string& image_path) { | 72 const std::string& image_path) { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
74 PrefService* local_state = g_browser_process->local_state(); | 74 PrefService* local_state = g_browser_process->local_state(); |
75 DictionaryValue* images = | 75 DictionaryValue* images = |
76 local_state->GetMutableDictionary(kUserImages); | 76 local_state->GetMutableDictionary(kUserImages); |
77 images->SetWithoutPathExpansion(username, new StringValue(image_path)); | 77 images->SetWithoutPathExpansion(username, new StringValue(image_path)); |
78 DVLOG(1) << "Saving path to user image in Local State."; | 78 DVLOG(1) << "Saving path to user image in Local State."; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return true; | 125 return true; |
126 } | 126 } |
127 } | 127 } |
128 return false; | 128 return false; |
129 } | 129 } |
130 | 130 |
131 // Updates current user ownership on UI thread. | 131 // Updates current user ownership on UI thread. |
132 void UpdateOwnership(bool is_owner) { | 132 void UpdateOwnership(bool is_owner) { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
134 | 134 |
135 UserManager* user_manager = UserManager::Get(); | 135 g_user_manager.Get().set_current_user_is_owner(is_owner); |
136 user_manager->set_current_user_is_owner(is_owner); | 136 NotificationService::current()->Notify(NotificationType::OWNERSHIP_CHECKED, |
137 | 137 NotificationService::AllSources(), |
| 138 NotificationService::NoDetails()); |
138 if (is_owner) { | 139 if (is_owner) { |
139 // Also update cached value. | 140 // Also update cached value. |
140 UserCrosSettingsProvider::UpdateCachedOwner( | 141 UserCrosSettingsProvider::UpdateCachedOwner( |
141 user_manager->logged_in_user().email()); | 142 g_user_manager.Get().logged_in_user().email()); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 // Checks current user's ownership on file thread. | 146 // Checks current user's ownership on file thread. |
146 void CheckOwnership() { | 147 void CheckOwnership() { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
148 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); | 149 bool is_owner = OwnershipService::GetSharedInstance()->CurrentUserIsOwner(); |
149 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); | 150 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); |
150 | 151 |
| 152 g_user_manager.Get().set_current_user_is_owner(is_owner); |
| 153 |
151 // UserManager should be accessed only on UI thread. | 154 // UserManager should be accessed only on UI thread. |
152 BrowserThread::PostTask( | 155 BrowserThread::PostTask( |
153 BrowserThread::UI, | 156 BrowserThread::UI, |
154 FROM_HERE, | 157 FROM_HERE, |
155 NewRunnableFunction(&UpdateOwnership, is_owner)); | 158 NewRunnableFunction(&UpdateOwnership, is_owner)); |
156 } | 159 } |
157 | 160 |
158 // Used to handle the asynchronous response of deleting a cryptohome directory. | 161 // Used to handle the asynchronous response of deleting a cryptohome directory. |
159 class RemoveAttempt : public CryptohomeLibrary::Delegate { | 162 class RemoveAttempt : public CryptohomeLibrary::Delegate { |
160 public: | 163 public: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 user_email.length() - domain_start); | 254 user_email.length() - domain_start); |
252 return base::StringPrintf("%s (%s)", | 255 return base::StringPrintf("%s (%s)", |
253 GetDisplayName().c_str(), | 256 GetDisplayName().c_str(), |
254 domain.c_str()); | 257 domain.c_str()); |
255 } | 258 } |
256 | 259 |
257 // static | 260 // static |
258 UserManager* UserManager::Get() { | 261 UserManager* UserManager::Get() { |
259 // Not thread-safe. | 262 // Not thread-safe. |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
261 if (!user_manager_) | 264 return &g_user_manager.Get(); |
262 user_manager_ = new UserManager(); | |
263 return user_manager_; | |
264 } | 265 } |
265 | 266 |
266 // static | 267 // static |
267 void UserManager::RegisterPrefs(PrefService* local_state) { | 268 void UserManager::RegisterPrefs(PrefService* local_state) { |
268 local_state->RegisterListPref(kLoggedInUsers); | 269 local_state->RegisterListPref(kLoggedInUsers); |
269 local_state->RegisterDictionaryPref(kUserImages); | 270 local_state->RegisterDictionaryPref(kUserImages); |
270 } | 271 } |
271 | 272 |
272 std::vector<UserManager::User> UserManager::GetUsers() const { | 273 std::vector<UserManager::User> UserManager::GetUsers() const { |
273 std::vector<User> users; | 274 std::vector<User> users; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 void UserManager::Observe(NotificationType type, | 570 void UserManager::Observe(NotificationType type, |
570 const NotificationSource& source, | 571 const NotificationSource& source, |
571 const NotificationDetails& details) { | 572 const NotificationDetails& details) { |
572 if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | 573 if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
573 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 574 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
574 NewRunnableFunction(&CheckOwnership)); | 575 NewRunnableFunction(&CheckOwnership)); |
575 } | 576 } |
576 } | 577 } |
577 | 578 |
578 bool UserManager::current_user_is_owner() const { | 579 bool UserManager::current_user_is_owner() const { |
| 580 base::AutoLock lk(current_user_is_owner_lock_); |
579 return current_user_is_owner_; | 581 return current_user_is_owner_; |
580 } | 582 } |
581 | 583 |
582 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { | 584 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { |
| 585 base::AutoLock lk(current_user_is_owner_lock_); |
583 current_user_is_owner_ = current_user_is_owner; | 586 current_user_is_owner_ = current_user_is_owner; |
584 } | 587 } |
585 | 588 |
586 } // namespace chromeos | 589 } // namespace chromeos |
OLD | NEW |