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

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

Issue 10590004: [cros] Fake a stub user login when no --login-manager and --login-user are given. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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). 70 // depends on that and it's hard to figure out what).
71 const char kGuestUser[] = ""; 71 const char kGuestUser[] = "";
72 72
73 // Stub user email (for test paths).
74 const char kStubUser[] = "stub-user@example.com";
75
76 // Names of nodes with info about user image. 73 // Names of nodes with info about user image.
77 const char kImagePathNodeName[] = "path"; 74 const char kImagePathNodeName[] = "path";
78 const char kImageIndexNodeName[] = "index"; 75 const char kImageIndexNodeName[] = "index";
79 const char kImageURLNodeName[] = "url"; 76 const char kImageURLNodeName[] = "url";
80 77
81 const char kWallpaperTypeNodeName[] = "type"; 78 const char kWallpaperTypeNodeName[] = "type";
82 const char kWallpaperIndexNodeName[] = "index"; 79 const char kWallpaperIndexNodeName[] = "index";
83 const char kWallpaperDateNodeName[] = "date"; 80 const char kWallpaperDateNodeName[] = "date";
84 81
85 // Default wallpaper index used in OOBE (first boot). 82 // Default wallpaper index used in OOBE (first boot).
86 // Defined here because Chromium default index differs. 83 // Defined here because Chromium default index differs.
87 // Also see ash::WallpaperInfo kDefaultWallpapers in 84 // Also see ash::WallpaperInfo kDefaultWallpapers in
88 // desktop_background_resources.cc 85 // desktop_background_resources.cc
89 #if defined(GOOGLE_CHROME_BUILD) 86 #if defined(GOOGLE_CHROME_BUILD)
90 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0 87 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0
91 #else 88 #else
92 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0 89 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0
93 #endif 90 #endif
94 91
95 const int kThumbnailWidth = 128; 92 const int kThumbnailWidth = 128;
96 const int kThumbnailHeight = 80; 93 const int kThumbnailHeight = 80;
97 94
98 // Index of the default image used for the |kStubUser| user.
99 const int kStubDefaultImageIndex = 0;
100
101 // Delay betweeen user login and attempt to update user's profile data. 95 // Delay betweeen user login and attempt to update user's profile data.
102 const long kProfileDataDownloadDelayMs = 10000; 96 const long kProfileDataDownloadDelayMs = 10000;
103 97
104 // Delay betweeen subsequent profile refresh attempts (24 hrs). 98 // Delay betweeen subsequent profile refresh attempts (24 hrs).
105 const long kProfileRefreshIntervalMs = 24L * 3600 * 1000; 99 const long kProfileRefreshIntervalMs = 24L * 3600 * 1000;
106 100
107 // Enum for reporting histograms about profile picture download. 101 // Enum for reporting histograms about profile picture download.
108 enum ProfileDownloadResult { 102 enum ProfileDownloadResult {
109 kDownloadSuccessChanged, 103 kDownloadSuccessChanged,
110 kDownloadSuccess, 104 kDownloadSuccess,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 current_user_wallpaper_type_(User::UNKNOWN), 219 current_user_wallpaper_type_(User::UNKNOWN),
226 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( 220 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
227 ash::GetInvalidWallpaperIndex())), 221 ash::GetInvalidWallpaperIndex())),
228 ephemeral_users_enabled_(false), 222 ephemeral_users_enabled_(false),
229 observed_sync_service_(NULL), 223 observed_sync_service_(NULL),
230 last_image_set_async_(false), 224 last_image_set_async_(false),
231 downloaded_profile_image_data_url_(chrome::kAboutBlankURL), 225 downloaded_profile_image_data_url_(chrome::kAboutBlankURL),
232 downloading_profile_image_(false) { 226 downloading_profile_image_(false) {
233 // UserManager instance should be used only on UI thread. 227 // UserManager instance should be used only on UI thread.
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
235 // If we're not running on ChromeOS, and are not showing the login manager
236 // or attempting a command line login? Then login the stub user.
237 CommandLine* command_line = CommandLine::ForCurrentProcess();
238 if (!base::chromeos::IsRunningOnChromeOS() &&
239 !command_line->HasSwitch(switches::kLoginManager) &&
240 !command_line->HasSwitch(switches::kLoginPassword) &&
241 !command_line->HasSwitch(switches::kGuestSession)) {
242 StubUserLoggedIn();
243 }
244 229
245 MigrateWallpaperData(); 230 MigrateWallpaperData();
246
247 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 231 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
248 content::NotificationService::AllSources()); 232 content::NotificationService::AllSources());
249 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 233 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
250 content::NotificationService::AllSources()); 234 content::NotificationService::AllSources());
251 RetrieveTrustedDevicePolicies(); 235 RetrieveTrustedDevicePolicies();
252 } 236 }
253 237
254 UserManagerImpl::~UserManagerImpl() { 238 UserManagerImpl::~UserManagerImpl() {
255 // Can't use STLDeleteElements because of the private destructor of User. 239 // Can't use STLDeleteElements because of the private destructor of User.
256 for (size_t i = 0; i < users_.size();++i) 240 for (size_t i = 0; i < users_.size();++i)
257 delete users_[i]; 241 delete users_[i];
258 users_.clear(); 242 users_.clear();
259 if (is_current_user_ephemeral_) 243 if (is_current_user_ephemeral_)
260 delete logged_in_user_; 244 delete logged_in_user_;
261 } 245 }
262 246
263 const UserList& UserManagerImpl::GetUsers() const { 247 const UserList& UserManagerImpl::GetUsers() const {
264 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 248 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
265 return users_; 249 return users_;
266 } 250 }
267 251
268 void UserManagerImpl::UserLoggedIn(const std::string& email, 252 void UserManagerImpl::UserLoggedIn(const std::string& email,
269 bool browser_restart) { 253 bool browser_restart) {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
271 255
272 // Remove the stub user if it is still around.
273 if (logged_in_user_) {
274 DCHECK(IsLoggedInAsStub());
275 delete logged_in_user_;
276 logged_in_user_ = NULL;
277 is_current_user_ephemeral_ = false;
278 }
279
280 if (email == kGuestUser) { 256 if (email == kGuestUser) {
281 GuestUserLoggedIn(); 257 GuestUserLoggedIn();
282 return; 258 return;
283 } 259 }
284 260
285 if (email == kDemoUser) { 261 if (email == kDemoUser) {
286 DemoUserLoggedIn(); 262 DemoUserLoggedIn();
287 return; 263 return;
288 } 264 }
289 265
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { 370 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
396 is_current_user_new_ = true; 372 is_current_user_new_ = true;
397 is_current_user_ephemeral_ = true; 373 is_current_user_ephemeral_ = true;
398 logged_in_user_ = CreateUser(email); 374 logged_in_user_ = CreateUser(email);
399 SetInitialUserImage(email); 375 SetInitialUserImage(email);
400 SetInitialUserWallpaper(email); 376 SetInitialUserWallpaper(email);
401 NotifyOnLogin(); 377 NotifyOnLogin();
402 } 378 }
403 379
404 void UserManagerImpl::StubUserLoggedIn() {
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
406 is_current_user_ephemeral_ = true;
407 logged_in_user_ = new User(kStubUser, false);
408 logged_in_user_->SetImage(UserImage(GetDefaultImage(kStubDefaultImageIndex)),
409 kStubDefaultImageIndex);
410 }
411
412 void UserManagerImpl::InitializeWallpaper() { 380 void UserManagerImpl::InitializeWallpaper() {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 if (!IsUserLoggedIn()) { 382 if (!IsUserLoggedIn()) {
415 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) { 383 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) {
416 if (!WizardController::IsDeviceRegistered()) { 384 if (!WizardController::IsDeviceRegistered()) {
417 // TODO(nkostylev): Add switch to disable wallpaper transition on OOBE. 385 // TODO(nkostylev): Add switch to disable wallpaper transition on OOBE.
418 // Should be used on test images so that they are not slowed down. 386 // Should be used on test images so that they are not slowed down.
419 ash::Shell::GetInstance()->desktop_background_controller()-> 387 ash::Shell::GetInstance()->desktop_background_controller()->
420 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex); 388 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
421 } else { 389 } else {
422 bool show_users = true; 390 bool show_users = true;
423 bool result = CrosSettings::Get()->GetBoolean( 391 bool result = CrosSettings::Get()->GetBoolean(
424 kAccountsPrefShowUserNamesOnSignIn, &show_users); 392 kAccountsPrefShowUserNamesOnSignIn, &show_users);
425 DCHECK(result) << "Unable to fetch setting " 393 DCHECK(result) << "Unable to fetch setting "
426 << kAccountsPrefShowUserNamesOnSignIn; 394 << kAccountsPrefShowUserNamesOnSignIn;
427 if (!show_users) { 395 if (!show_users) {
428 ash::Shell::GetInstance()->desktop_background_controller()-> 396 ash::Shell::GetInstance()->desktop_background_controller()->
429 SetDefaultWallpaper(ash::GetSolidColorIndex()); 397 SetDefaultWallpaper(ash::GetSolidColorIndex());
430 } 398 }
431 } 399 }
432 } 400 }
433 return; 401 return;
434 } else if (IsLoggedInAsStub()) {
435 ash::Shell::GetInstance()->desktop_background_controller()->
436 SetDefaultWallpaper(ash::GetInvalidWallpaperIndex());
437 return;
438 } 402 }
439 UserSelected(GetLoggedInUser().email()); 403 UserSelected(GetLoggedInUser().email());
440 } 404 }
441 405
442 void UserManagerImpl::UserSelected(const std::string& email) { 406 void UserManagerImpl::UserSelected(const std::string& email) {
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
444 if (IsKnownUser(email)) { 408 if (IsKnownUser(email)) {
445 User::WallpaperType type; 409 User::WallpaperType type;
446 int index; 410 int index;
447 base::Time date; 411 base::Time date;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 switch (type) { 679 switch (type) {
716 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: 680 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED:
717 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 681 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
718 base::Bind(&UserManagerImpl::CheckOwnership, 682 base::Bind(&UserManagerImpl::CheckOwnership,
719 base::Unretained(this))); 683 base::Unretained(this)));
720 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 684 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
721 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 685 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
722 base::Unretained(this))); 686 base::Unretained(this)));
723 break; 687 break;
724 case chrome::NOTIFICATION_PROFILE_ADDED: 688 case chrome::NOTIFICATION_PROFILE_ADDED:
725 if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsStub()) { 689 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) {
726 Profile* profile = content::Source<Profile>(source).ptr(); 690 Profile* profile = content::Source<Profile>(source).ptr();
727 if (!profile->IsOffTheRecord() && 691 if (!profile->IsOffTheRecord() &&
728 profile == ProfileManager::GetDefaultProfile()) { 692 profile == ProfileManager::GetDefaultProfile()) {
729 DCHECK(NULL == observed_sync_service_); 693 DCHECK(NULL == observed_sync_service_);
730 observed_sync_service_ = 694 observed_sync_service_ =
731 ProfileSyncServiceFactory::GetForProfile(profile); 695 ProfileSyncServiceFactory::GetForProfile(profile);
732 if (observed_sync_service_) 696 if (observed_sync_service_)
733 observed_sync_service_->AddObserver(this); 697 observed_sync_service_->AddObserver(this);
734 } 698 }
735 } 699 }
736 break; 700 break;
737 default: 701 default:
738 NOTREACHED(); 702 NOTREACHED();
739 } 703 }
740 } 704 }
741 705
742 void UserManagerImpl::OnStateChanged() { 706 void UserManagerImpl::OnStateChanged() {
743 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsStub()); 707 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest());
744 AuthError::State state = observed_sync_service_->GetAuthError().state(); 708 AuthError::State state = observed_sync_service_->GetAuthError().state();
745 if (state != AuthError::NONE && 709 if (state != AuthError::NONE &&
746 state != AuthError::CONNECTION_FAILED && 710 state != AuthError::CONNECTION_FAILED &&
747 state != AuthError::SERVICE_UNAVAILABLE && 711 state != AuthError::SERVICE_UNAVAILABLE &&
748 state != AuthError::REQUEST_CANCELED) { 712 state != AuthError::REQUEST_CANCELED) {
749 // Invalidate OAuth token to force Gaia sign-in flow. This is needed 713 // Invalidate OAuth token to force Gaia sign-in flow. This is needed
750 // because sign-out/sign-in solution is suggested to the user. 714 // because sign-out/sign-in solution is suggested to the user.
751 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is 715 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is
752 // implemented. 716 // implemented.
753 DVLOG(1) << "Invalidate OAuth token because of a sync error."; 717 DVLOG(1) << "Invalidate OAuth token because of a sync error.";
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 } 962 }
999 } 963 }
1000 964
1001 bool UserManagerImpl::AreEphemeralUsersEnabled() const { 965 bool UserManagerImpl::AreEphemeralUsersEnabled() const {
1002 return ephemeral_users_enabled_ && 966 return ephemeral_users_enabled_ &&
1003 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || 967 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ||
1004 !owner_email_.empty()); 968 !owner_email_.empty());
1005 } 969 }
1006 970
1007 bool UserManagerImpl::IsEphemeralUser(const std::string& email) const { 971 bool UserManagerImpl::IsEphemeralUser(const std::string& email) const {
1008 // The guest user always is ephemeral. 972 // The guest and stub user always are ephemeral.
1009 if (email == kGuestUser) 973 if (email == kGuestUser || email == kStubUser)
1010 return true; 974 return true;
1011 975
1012 // The currently logged-in user is ephemeral iff logged in as ephemeral. 976 // The currently logged-in user is ephemeral iff logged in as ephemeral.
1013 if (logged_in_user_ && (email == logged_in_user_->email())) 977 if (logged_in_user_ && (email == logged_in_user_->email()))
1014 return is_current_user_ephemeral_; 978 return is_current_user_ephemeral_;
1015 979
1016 // The owner and any users found in the persistent list are never ephemeral. 980 // The owner and any users found in the persistent list are never ephemeral.
1017 if (email == owner_email_ || FindUserInList(email)) 981 if (email == owner_email_ || FindUserInList(email))
1018 return false; 982 return false;
1019 983
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 BrowserThread::PostTask( 1688 BrowserThread::PostTask(
1725 BrowserThread::FILE, 1689 BrowserThread::FILE,
1726 FROM_HERE, 1690 FROM_HERE,
1727 base::Bind(&UserManagerImpl::DeleteUserImage, 1691 base::Bind(&UserManagerImpl::DeleteUserImage,
1728 base::Unretained(this), 1692 base::Unretained(this),
1729 image_path)); 1693 image_path));
1730 } 1694 }
1731 } 1695 }
1732 1696
1733 } // namespace chromeos 1697 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/chromeos/login/user_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698