Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 10805007: [cros] UserManager cleanup regarding stub/demo users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused fields and fix compile Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_impl.h" 5 #include "chrome/browser/chromeos/login/user_manager_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/desktop_background/desktop_background_controller.h" 10 #include "ash/desktop_background/desktop_background_controller.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "ui/gfx/image/image_skia.h" 59 #include "ui/gfx/image/image_skia.h"
60 60
61 using content::BrowserThread; 61 using content::BrowserThread;
62 62
63 typedef GoogleServiceAuthError AuthError; 63 typedef GoogleServiceAuthError AuthError;
64 64
65 namespace chromeos { 65 namespace chromeos {
66 66
67 namespace { 67 namespace {
68 68
69 // Incognito user is represented by an empty string (since some code already
70 // depends on that and it's hard to figure out what).
71 const char kGuestUser[] = "";
72
73 // Names of nodes with info about user image. 69 // Names of nodes with info about user image.
74 const char kImagePathNodeName[] = "path"; 70 const char kImagePathNodeName[] = "path";
75 const char kImageIndexNodeName[] = "index"; 71 const char kImageIndexNodeName[] = "index";
76 const char kImageURLNodeName[] = "url"; 72 const char kImageURLNodeName[] = "url";
77 73
78 const char kWallpaperTypeNodeName[] = "type"; 74 const char kWallpaperTypeNodeName[] = "type";
79 const char kWallpaperIndexNodeName[] = "index"; 75 const char kWallpaperIndexNodeName[] = "index";
80 const char kWallpaperDateNodeName[] = "date"; 76 const char kWallpaperDateNodeName[] = "date";
81 77
82 // Default wallpaper index used in OOBE (first boot). 78 // Default wallpaper index used in OOBE (first boot).
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 241 }
246 242
247 const UserList& UserManagerImpl::GetUsers() const { 243 const UserList& UserManagerImpl::GetUsers() const {
248 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 244 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
249 return users_; 245 return users_;
250 } 246 }
251 247
252 void UserManagerImpl::UserLoggedIn(const std::string& email, 248 void UserManagerImpl::UserLoggedIn(const std::string& email,
253 bool browser_restart) { 249 bool browser_restart) {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
251 DCHECK(!IsUserLoggedIn());
pastarmovj 2012/07/18 19:03:36 I remember we had some issues with this check the
Ivan Korotkov 2012/07/19 12:20:21 Right. I've recently submitted which slightly cha
255 252
256 if (email == kGuestUser) { 253 if (email == kGuestUser) {
257 GuestUserLoggedIn(); 254 GuestUserLoggedIn();
258 return; 255 return;
259 } 256 }
260 257
261 if (email == kDemoUser) { 258 if (email == kDemoUser) {
262 DemoUserLoggedIn(); 259 DemoUserLoggedIn();
263 return; 260 return;
264 } 261 }
(...skipping 17 matching lines...) Expand all
282 std::string user_email = (*it)->email(); 279 std::string user_email = (*it)->email();
283 // Skip the most recent user. 280 // Skip the most recent user.
284 if (email != user_email) 281 if (email != user_email)
285 prefs_users_update->Append(Value::CreateStringValue(user_email)); 282 prefs_users_update->Append(Value::CreateStringValue(user_email));
286 else 283 else
287 logged_in_user = it; 284 logged_in_user = it;
288 } 285 }
289 286
290 if (logged_in_user == users_.end()) { 287 if (logged_in_user == users_.end()) {
291 is_current_user_new_ = true; 288 is_current_user_new_ = true;
292 logged_in_user_ = CreateUser(email); 289 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ false);
pastarmovj 2012/07/18 19:03:36 Do you need those comments here? I can see how you
Ivan Korotkov 2012/07/19 12:20:21 I'd rather leave them because bool arguments alway
293 } else { 290 } else {
294 logged_in_user_ = *logged_in_user; 291 logged_in_user_ = *logged_in_user;
295 users_.erase(logged_in_user); 292 users_.erase(logged_in_user);
296 } 293 }
297 // This user must be in the front of the user list. 294 // This user must be in the front of the user list.
298 users_.insert(users_.begin(), logged_in_user_); 295 users_.insert(users_.begin(), logged_in_user_);
299 296
300 if (is_current_user_new_) { 297 if (is_current_user_new_) {
301 SaveUserDisplayName(GetLoggedInUser().email(), 298 SaveUserDisplayName(GetLoggedInUser().email(),
302 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true))); 299 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true)));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 EnsureLoggedInUserWallpaperLoaded(); 343 EnsureLoggedInUserWallpaperLoaded();
347 } 344 }
348 345
349 NotifyOnLogin(); 346 NotifyOnLogin();
350 } 347 }
351 348
352 void UserManagerImpl::DemoUserLoggedIn() { 349 void UserManagerImpl::DemoUserLoggedIn() {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
354 is_current_user_new_ = true; 351 is_current_user_new_ = true;
355 is_current_user_ephemeral_ = true; 352 is_current_user_ephemeral_ = true;
356 logged_in_user_ = new User(kDemoUser, false); 353 logged_in_user_ = CreateUser(kDemoUser, /* is_ephemeral= */ true);
357 SetInitialUserImage(kDemoUser); 354 SetInitialUserImage(kDemoUser);
358 SetInitialUserWallpaper(kDemoUser); 355 SetInitialUserWallpaper(kDemoUser);
359 NotifyOnLogin(); 356 NotifyOnLogin();
360 } 357 }
361 358
362 void UserManagerImpl::GuestUserLoggedIn() { 359 void UserManagerImpl::GuestUserLoggedIn() {
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
364 is_current_user_ephemeral_ = true; 361 is_current_user_ephemeral_ = true;
365 SetInitialUserWallpaper(kGuestUser); 362 SetInitialUserWallpaper(kGuestUser);
366 logged_in_user_ = new User(kGuestUser, true); 363 logged_in_user_ = CreateUser(kGuestUser, /* is_ephemeral= */ true);
367 NotifyOnLogin(); 364 NotifyOnLogin();
368 } 365 }
369 366
370 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { 367 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
372 is_current_user_new_ = true; 369 is_current_user_new_ = true;
373 is_current_user_ephemeral_ = true; 370 is_current_user_ephemeral_ = true;
374 logged_in_user_ = CreateUser(email); 371 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ true);
375 SetInitialUserImage(email); 372 SetInitialUserImage(email);
376 SetInitialUserWallpaper(email); 373 SetInitialUserWallpaper(email);
377 NotifyOnLogin(); 374 NotifyOnLogin();
378 } 375 }
379 376
380 void UserManagerImpl::InitializeWallpaper() { 377 void UserManagerImpl::InitializeWallpaper() {
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
382 if (!IsUserLoggedIn()) { 379 if (!IsUserLoggedIn()) {
383 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) { 380 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) {
384 if (!WizardController::IsDeviceRegistered()) { 381 if (!WizardController::IsDeviceRegistered()) {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 const DictionaryValue* prefs_display_emails = 820 const DictionaryValue* prefs_display_emails =
824 local_state->GetDictionary(UserManager::kUserDisplayEmail); 821 local_state->GetDictionary(UserManager::kUserDisplayEmail);
825 822
826 int user_image_size = GetCurrentUserImageSize(); 823 int user_image_size = GetCurrentUserImageSize();
827 824
828 if (prefs_users) { 825 if (prefs_users) {
829 for (ListValue::const_iterator it = prefs_users->begin(); 826 for (ListValue::const_iterator it = prefs_users->begin();
830 it != prefs_users->end(); ++it) { 827 it != prefs_users->end(); ++it) {
831 std::string email; 828 std::string email;
832 if ((*it)->GetAsString(&email)) { 829 if ((*it)->GetAsString(&email)) {
833 User* user = CreateUser(email); 830 User* user = CreateUser(email, /* is_ephemeral= */ false);
834 users_.push_back(user); 831 users_.push_back(user);
835 832
836 if (prefs_images) { 833 if (prefs_images) {
837 // Get account image path. 834 // Get account image path.
838 // TODO(avayvod): Reading image path as a string is here for 835 // TODO(avayvod): Reading image path as a string is here for
839 // backward compatibility. 836 // backward compatibility.
840 std::string image_path; 837 std::string image_path;
841 base::DictionaryValue* image_properties; 838 base::DictionaryValue* image_properties;
842 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { 839 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) {
843 int image_id = User::kInvalidImageIndex; 840 int image_id = User::kInvalidImageIndex;
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 base::TimeDelta delta = base::Time::Now() - profile_image_load_start_time_; 1607 base::TimeDelta delta = base::Time::Now() - profile_image_load_start_time_;
1611 AddProfileImageTimeHistogram(kDownloadFailure, profile_image_download_reason_, 1608 AddProfileImageTimeHistogram(kDownloadFailure, profile_image_download_reason_,
1612 delta); 1609 delta);
1613 1610
1614 content::NotificationService::current()->Notify( 1611 content::NotificationService::current()->Notify(
1615 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, 1612 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
1616 content::Source<UserManagerImpl>(this), 1613 content::Source<UserManagerImpl>(this),
1617 content::NotificationService::NoDetails()); 1614 content::NotificationService::NoDetails());
1618 } 1615 }
1619 1616
1620 User* UserManagerImpl::CreateUser(const std::string& email) const { 1617 User* UserManagerImpl::CreateUser(const std::string& email,
1621 User* user = new User(email, email == kGuestUser); 1618 bool is_ephemeral) const {
1622 user->set_oauth_token_status(LoadUserOAuthStatus(email)); 1619 User* user = new User(email);
1620 if (!is_ephemeral)
1621 user->set_oauth_token_status(LoadUserOAuthStatus(email));
1623 return user; 1622 return user;
1624 } 1623 }
1625 1624
1626 void UserManagerImpl::RemoveUserFromListInternal(const std::string& email) { 1625 void UserManagerImpl::RemoveUserFromListInternal(const std::string& email) {
1627 // Clear the prefs view of the users. 1626 // Clear the prefs view of the users.
1628 PrefService* prefs = g_browser_process->local_state(); 1627 PrefService* prefs = g_browser_process->local_state();
1629 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); 1628 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers);
1630 prefs_users_update->Clear(); 1629 prefs_users_update->Clear();
1631 1630
1632 UserList::iterator user_to_remove = users_.end(); 1631 UserList::iterator user_to_remove = users_.end();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 BrowserThread::PostTask( 1687 BrowserThread::PostTask(
1689 BrowserThread::FILE, 1688 BrowserThread::FILE,
1690 FROM_HERE, 1689 FROM_HERE,
1691 base::Bind(&UserManagerImpl::DeleteUserImage, 1690 base::Bind(&UserManagerImpl::DeleteUserImage,
1692 base::Unretained(this), 1691 base::Unretained(this),
1693 image_path)); 1692 image_path));
1694 } 1693 }
1695 } 1694 }
1696 1695
1697 } // namespace chromeos 1696 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/policy/user_cloud_policy_store_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698