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

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: Further test fixes. Created 8 years, 6 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 typedef GoogleServiceAuthError AuthError; 61 typedef GoogleServiceAuthError AuthError;
62 62
63 namespace chromeos { 63 namespace chromeos {
64 64
65 namespace { 65 namespace {
66 66
67 // Incognito user is represented by an empty string (since some code already 67 // Incognito user is represented by an empty string (since some code already
68 // depends on that and it's hard to figure out what). 68 // depends on that and it's hard to figure out what).
69 const char kGuestUser[] = ""; 69 const char kGuestUser[] = "";
70 70
71 // Stub user email (for test paths).
72 const char kStubUser[] = "stub-user@example.com";
73
74 // Names of nodes with info about user image. 71 // Names of nodes with info about user image.
75 const char kImagePathNodeName[] = "path"; 72 const char kImagePathNodeName[] = "path";
76 const char kImageIndexNodeName[] = "index"; 73 const char kImageIndexNodeName[] = "index";
77 74
78 const char kWallpaperTypeNodeName[] = "type"; 75 const char kWallpaperTypeNodeName[] = "type";
79 const char kWallpaperIndexNodeName[] = "index"; 76 const char kWallpaperIndexNodeName[] = "index";
80 77
81 const int kThumbnailWidth = 128; 78 const int kThumbnailWidth = 128;
82 const int kThumbnailHeight = 80; 79 const int kThumbnailHeight = 80;
83 80
84 // Index of the default image used for the |kStubUser| user.
85 const int kStubDefaultImageIndex = 0;
86
87 // Delay betweeen user login and attempt to update user's profile image. 81 // Delay betweeen user login and attempt to update user's profile image.
88 const long kProfileImageDownloadDelayMs = 10000; 82 const long kProfileImageDownloadDelayMs = 10000;
89 83
90 // Enum for reporting histograms about profile picture download. 84 // Enum for reporting histograms about profile picture download.
91 enum ProfileDownloadResult { 85 enum ProfileDownloadResult {
92 kDownloadSuccessChanged, 86 kDownloadSuccessChanged,
93 kDownloadSuccess, 87 kDownloadSuccess,
94 kDownloadFailure, 88 kDownloadFailure,
95 kDownloadDefault, 89 kDownloadDefault,
96 90
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 is_current_user_owner_(false), 190 is_current_user_owner_(false),
197 is_current_user_new_(false), 191 is_current_user_new_(false),
198 is_current_user_ephemeral_(false), 192 is_current_user_ephemeral_(false),
199 current_user_wallpaper_type_(User::UNKNOWN), 193 current_user_wallpaper_type_(User::UNKNOWN),
200 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_( 194 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
201 ash::GetInvalidWallpaperIndex())), 195 ash::GetInvalidWallpaperIndex())),
202 ephemeral_users_enabled_(false), 196 ephemeral_users_enabled_(false),
203 observed_sync_service_(NULL), 197 observed_sync_service_(NULL),
204 last_image_set_async_(false), 198 last_image_set_async_(false),
205 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { 199 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) {
206 // If we're not running on ChromeOS, and are not showing the login manager
207 // or attempting a command line login? Then login the stub user.
208 CommandLine* command_line = CommandLine::ForCurrentProcess();
209 if (!base::chromeos::IsRunningOnChromeOS() &&
210 !command_line->HasSwitch(switches::kLoginManager) &&
211 !command_line->HasSwitch(switches::kLoginPassword) &&
212 !command_line->HasSwitch(switches::kGuestSession)) {
213 StubUserLoggedIn();
214 }
215
216 MigrateWallpaperData(); 200 MigrateWallpaperData();
217
218 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 201 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
219 content::NotificationService::AllSources()); 202 content::NotificationService::AllSources());
220 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 203 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
221 content::NotificationService::AllSources()); 204 content::NotificationService::AllSources());
222 RetrieveTrustedDevicePolicies(); 205 RetrieveTrustedDevicePolicies();
223 } 206 }
224 207
225 UserManagerImpl::~UserManagerImpl() { 208 UserManagerImpl::~UserManagerImpl() {
226 // Can't use STLDeleteElements because of the private destructor of User. 209 // Can't use STLDeleteElements because of the private destructor of User.
227 for (size_t i = 0; i < users_.size();++i) 210 for (size_t i = 0; i < users_.size();++i)
228 delete users_[i]; 211 delete users_[i];
229 users_.clear(); 212 users_.clear();
230 if (is_current_user_ephemeral_) 213 if (is_current_user_ephemeral_)
231 delete logged_in_user_; 214 delete logged_in_user_;
232 } 215 }
233 216
234 const UserList& UserManagerImpl::GetUsers() const { 217 const UserList& UserManagerImpl::GetUsers() const {
235 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 218 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
236 return users_; 219 return users_;
237 } 220 }
238 221
239 void UserManagerImpl::UserLoggedIn(const std::string& email, 222 void UserManagerImpl::UserLoggedIn(const std::string& email,
240 bool browser_restart) { 223 bool browser_restart) {
241 // Remove the stub user if it is still around.
242 if (logged_in_user_) {
243 DCHECK(IsLoggedInAsStub());
244 delete logged_in_user_;
245 logged_in_user_ = NULL;
246 is_current_user_ephemeral_ = false;
247 }
248
249 if (email == kGuestUser) { 224 if (email == kGuestUser) {
250 GuestUserLoggedIn(); 225 GuestUserLoggedIn();
251 return; 226 return;
252 } 227 }
253 228
254 if (email == kDemoUser) { 229 if (email == kDemoUser) {
255 DemoUserLoggedIn(); 230 DemoUserLoggedIn();
256 return; 231 return;
257 } 232 }
258 233
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 326
352 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { 327 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
353 is_current_user_new_ = true; 328 is_current_user_new_ = true;
354 is_current_user_ephemeral_ = true; 329 is_current_user_ephemeral_ = true;
355 logged_in_user_ = CreateUser(email); 330 logged_in_user_ = CreateUser(email);
356 SetInitialUserImage(email); 331 SetInitialUserImage(email);
357 SetInitialUserWallpaper(email); 332 SetInitialUserWallpaper(email);
358 NotifyOnLogin(); 333 NotifyOnLogin();
359 } 334 }
360 335
361 void UserManagerImpl::StubUserLoggedIn() {
362 is_current_user_ephemeral_ = true;
363 logged_in_user_ = new User(kStubUser, false);
364 logged_in_user_->SetImage(UserImage(GetDefaultImage(kStubDefaultImageIndex)),
365 kStubDefaultImageIndex);
366 }
367
368 void UserManagerImpl::InitializeWallpaper() { 336 void UserManagerImpl::InitializeWallpaper() {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
370 338
371 if (!IsUserLoggedIn()) { 339 if (!IsUserLoggedIn()) {
372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) { 340 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNewOobe)) {
373 bool show_users = true; 341 bool show_users = true;
374 bool result = CrosSettings::Get()->GetBoolean( 342 bool result = CrosSettings::Get()->GetBoolean(
375 kAccountsPrefShowUserNamesOnSignIn, &show_users); 343 kAccountsPrefShowUserNamesOnSignIn, &show_users);
376 DCHECK(result) << "Unable to fetch setting " 344 DCHECK(result) << "Unable to fetch setting "
377 << kAccountsPrefShowUserNamesOnSignIn; 345 << kAccountsPrefShowUserNamesOnSignIn;
378 if (!show_users) { 346 if (!show_users) {
379 ash::Shell::GetInstance()->desktop_background_controller()-> 347 ash::Shell::GetInstance()->desktop_background_controller()->
380 SetDefaultWallpaper(ash::GetSolidColorIndex()); 348 SetDefaultWallpaper(ash::GetSolidColorIndex());
381 } 349 }
382 } 350 }
383 return; 351 return;
384 } else if (IsLoggedInAsStub()) {
385 ash::Shell::GetInstance()->desktop_background_controller()->
386 SetDefaultWallpaper(ash::GetInvalidWallpaperIndex());
387 return;
388 } 352 }
389 UserSelected(GetLoggedInUser().email()); 353 UserSelected(GetLoggedInUser().email());
390 } 354 }
391 355
392 void UserManagerImpl::UserSelected(const std::string& email) { 356 void UserManagerImpl::UserSelected(const std::string& email) {
393 if (IsKnownUser(email)) { 357 if (IsKnownUser(email)) {
394 User::WallpaperType type; 358 User::WallpaperType type;
395 int index; 359 int index;
396 GetUserWallpaperProperties(email, &type, &index); 360 GetUserWallpaperProperties(email, &type, &index);
397 if (type == User::RANDOM) { 361 if (type == User::RANDOM) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 switch (type) { 621 switch (type) {
658 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: 622 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED:
659 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 623 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
660 base::Bind(&UserManagerImpl::CheckOwnership, 624 base::Bind(&UserManagerImpl::CheckOwnership,
661 base::Unretained(this))); 625 base::Unretained(this)));
662 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 626 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
663 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 627 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
664 base::Unretained(this))); 628 base::Unretained(this)));
665 break; 629 break;
666 case chrome::NOTIFICATION_PROFILE_ADDED: 630 case chrome::NOTIFICATION_PROFILE_ADDED:
667 if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsStub()) { 631 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) {
668 Profile* profile = content::Source<Profile>(source).ptr(); 632 Profile* profile = content::Source<Profile>(source).ptr();
669 if (!profile->IsOffTheRecord() && 633 if (!profile->IsOffTheRecord() &&
670 profile == ProfileManager::GetDefaultProfile()) { 634 profile == ProfileManager::GetDefaultProfile()) {
671 DCHECK(NULL == observed_sync_service_); 635 DCHECK(NULL == observed_sync_service_);
672 observed_sync_service_ = 636 observed_sync_service_ =
673 ProfileSyncServiceFactory::GetForProfile(profile); 637 ProfileSyncServiceFactory::GetForProfile(profile);
674 if (observed_sync_service_) 638 if (observed_sync_service_)
675 observed_sync_service_->AddObserver(this); 639 observed_sync_service_->AddObserver(this);
676 } 640 }
677 } 641 }
678 break; 642 break;
679 default: 643 default:
680 NOTREACHED(); 644 NOTREACHED();
681 } 645 }
682 } 646 }
683 647
684 void UserManagerImpl::OnStateChanged() { 648 void UserManagerImpl::OnStateChanged() {
685 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsStub()); 649 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest());
686 AuthError::State state = observed_sync_service_->GetAuthError().state(); 650 AuthError::State state = observed_sync_service_->GetAuthError().state();
687 if (state != AuthError::NONE && 651 if (state != AuthError::NONE &&
688 state != AuthError::CONNECTION_FAILED && 652 state != AuthError::CONNECTION_FAILED &&
689 state != AuthError::SERVICE_UNAVAILABLE && 653 state != AuthError::SERVICE_UNAVAILABLE &&
690 state != AuthError::REQUEST_CANCELED) { 654 state != AuthError::REQUEST_CANCELED) {
691 // Invalidate OAuth token to force Gaia sign-in flow. This is needed 655 // Invalidate OAuth token to force Gaia sign-in flow. This is needed
692 // because sign-out/sign-in solution is suggested to the user. 656 // because sign-out/sign-in solution is suggested to the user.
693 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is 657 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is
694 // implemented. 658 // implemented.
695 DVLOG(1) << "Invalidate OAuth token because of a sync error."; 659 DVLOG(1) << "Invalidate OAuth token because of a sync error.";
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 } 882 }
919 } 883 }
920 884
921 bool UserManagerImpl::AreEphemeralUsersEnabled() const { 885 bool UserManagerImpl::AreEphemeralUsersEnabled() const {
922 return ephemeral_users_enabled_ && 886 return ephemeral_users_enabled_ &&
923 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || 887 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ||
924 !owner_email_.empty()); 888 !owner_email_.empty());
925 } 889 }
926 890
927 bool UserManagerImpl::IsEphemeralUser(const std::string& email) const { 891 bool UserManagerImpl::IsEphemeralUser(const std::string& email) const {
928 // The guest user always is ephemeral. 892 // The guest and stub user always are ephemeral.
929 if (email == kGuestUser) 893 if (email == kGuestUser || email == kStubUser)
930 return true; 894 return true;
931 895
932 // The currently logged-in user is ephemeral iff logged in as ephemeral. 896 // The currently logged-in user is ephemeral iff logged in as ephemeral.
933 if (logged_in_user_ && (email == logged_in_user_->email())) 897 if (logged_in_user_ && (email == logged_in_user_->email()))
934 return is_current_user_ephemeral_; 898 return is_current_user_ephemeral_;
935 899
936 // The owner and any users found in the persistent list are never ephemeral. 900 // The owner and any users found in the persistent list are never ephemeral.
937 if (email == owner_email_ || FindUserInList(email)) 901 if (email == owner_email_ || FindUserInList(email))
938 return false; 902 return false;
939 903
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 } 1001 }
1038 } 1002 }
1039 } 1003 }
1040 } 1004 }
1041 1005
1042 void UserManagerImpl::GetLoggedInUserWallpaperProperties( 1006 void UserManagerImpl::GetLoggedInUserWallpaperProperties(
1043 User::WallpaperType* type, 1007 User::WallpaperType* type,
1044 int* index) { 1008 int* index) {
1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1046 DCHECK(logged_in_user_); 1010 DCHECK(logged_in_user_);
1047
1048 if (IsLoggedInAsStub()) {
1049 *type = current_user_wallpaper_type_ = User::DEFAULT;
1050 *index = current_user_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
1051 return;
1052 }
1053
1054 GetUserWallpaperProperties(GetLoggedInUser().email(), type, index); 1011 GetUserWallpaperProperties(GetLoggedInUser().email(), type, index);
1055 } 1012 }
1056 1013
1057 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( 1014 void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
1058 User::WallpaperType type, 1015 User::WallpaperType type,
1059 int index) { 1016 int index) {
1060 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); 1017 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index);
1061 } 1018 }
1062 1019
1063 void UserManagerImpl::SetUserImage(const std::string& username, 1020 void UserManagerImpl::SetUserImage(const std::string& username,
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 BrowserThread::PostTask( 1514 BrowserThread::PostTask(
1558 BrowserThread::FILE, 1515 BrowserThread::FILE,
1559 FROM_HERE, 1516 FROM_HERE,
1560 base::Bind(&UserManagerImpl::DeleteUserImage, 1517 base::Bind(&UserManagerImpl::DeleteUserImage,
1561 base::Unretained(this), 1518 base::Unretained(this),
1562 image_path)); 1519 image_path));
1563 } 1520 }
1564 } 1521 }
1565 1522
1566 } // namespace chromeos 1523 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698