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

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

Issue 271533004: Turning on MultiProfile by default for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "ash/multi_profile_uma.h" 10 #include "ash/multi_profile_uma.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 45 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
46 #include "chrome/browser/chromeos/policy/device_local_account.h" 46 #include "chrome/browser/chromeos/policy/device_local_account.h"
47 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog. h" 47 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog. h"
48 #include "chrome/browser/chromeos/profiles/profile_helper.h" 48 #include "chrome/browser/chromeos/profiles/profile_helper.h"
49 #include "chrome/browser/chromeos/session_length_limiter.h" 49 #include "chrome/browser/chromeos/session_length_limiter.h"
50 #include "chrome/browser/managed_mode/chromeos/managed_user_password_service_fac tory.h" 50 #include "chrome/browser/managed_mode/chromeos/managed_user_password_service_fac tory.h"
51 #include "chrome/browser/managed_mode/chromeos/manager_password_service_factory. h" 51 #include "chrome/browser/managed_mode/chromeos/manager_password_service_factory. h"
52 #include "chrome/browser/net/nss_context.h" 52 #include "chrome/browser/net/nss_context.h"
53 #include "chrome/browser/profiles/profile.h" 53 #include "chrome/browser/profiles/profile.h"
54 #include "chrome/browser/profiles/profile_manager.h" 54 #include "chrome/browser/profiles/profile_manager.h"
55 #include "chrome/browser/profiles/profiles_state.h"
55 #include "chrome/browser/sync/profile_sync_service.h" 56 #include "chrome/browser/sync/profile_sync_service.h"
56 #include "chrome/browser/sync/profile_sync_service_factory.h" 57 #include "chrome/browser/sync/profile_sync_service_factory.h"
57 #include "chrome/common/chrome_constants.h" 58 #include "chrome/common/chrome_constants.h"
58 #include "chrome/common/chrome_switches.h" 59 #include "chrome/common/chrome_switches.h"
59 #include "chrome/common/crash_keys.h" 60 #include "chrome/common/crash_keys.h"
60 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
61 #include "chromeos/cert_loader.h" 62 #include "chromeos/cert_loader.h"
62 #include "chromeos/chromeos_switches.h" 63 #include "chromeos/chromeos_switches.h"
63 #include "chromeos/cryptohome/async_method_caller.h" 64 #include "chromeos/cryptohome/async_method_caller.h"
64 #include "chromeos/dbus/dbus_thread_manager.h" 65 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 device_local_account_policy_service_->RemoveObserver(this); 282 device_local_account_policy_service_->RemoveObserver(this);
282 283
283 for (UserImageManagerMap::iterator it = user_image_managers_.begin(), 284 for (UserImageManagerMap::iterator it = user_image_managers_.begin(),
284 ie = user_image_managers_.end(); 285 ie = user_image_managers_.end();
285 it != ie; ++it) { 286 it != ie; ++it) {
286 it->second->Shutdown(); 287 it->second->Shutdown();
287 } 288 }
288 multi_profile_user_controller_.reset(); 289 multi_profile_user_controller_.reset();
289 avatar_policy_observer_.reset(); 290 avatar_policy_observer_.reset();
290 wallpaper_policy_observer_.reset(); 291 wallpaper_policy_observer_.reset();
292 registrar_.RemoveAll();
291 } 293 }
292 294
293 MultiProfileUserController* UserManagerImpl::GetMultiProfileUserController() { 295 MultiProfileUserController* UserManagerImpl::GetMultiProfileUserController() {
294 return multi_profile_user_controller_.get(); 296 return multi_profile_user_controller_.get();
295 } 297 }
296 298
297 UserImageManager* UserManagerImpl::GetUserImageManager( 299 UserImageManager* UserManagerImpl::GetUserImageManager(
298 const std::string& user_id) { 300 const std::string& user_id) {
299 UserImageManagerMap::iterator ui = user_image_managers_.find(user_id); 301 UserImageManagerMap::iterator ui = user_image_managers_.find(user_id);
300 if (ui != user_image_managers_.end()) 302 if (ui != user_image_managers_.end())
301 return ui->second.get(); 303 return ui->second.get();
302 linked_ptr<UserImageManagerImpl> mgr(new UserImageManagerImpl(user_id, this)); 304 linked_ptr<UserImageManagerImpl> mgr(new UserImageManagerImpl(user_id, this));
303 user_image_managers_[user_id] = mgr; 305 user_image_managers_[user_id] = mgr;
304 return mgr.get(); 306 return mgr.get();
305 } 307 }
306 308
307 SupervisedUserManager* UserManagerImpl::GetSupervisedUserManager() { 309 SupervisedUserManager* UserManagerImpl::GetSupervisedUserManager() {
308 return supervised_user_manager_.get(); 310 return supervised_user_manager_.get();
309 } 311 }
310 312
311 const UserList& UserManagerImpl::GetUsers() const { 313 const UserList& UserManagerImpl::GetUsers() const {
312 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 314 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
313 return users_; 315 return users_;
314 } 316 }
315 317
316 UserList UserManagerImpl::GetUsersAdmittedForMultiProfile() const { 318 UserList UserManagerImpl::GetUsersAdmittedForMultiProfile() const {
317 if (!UserManager::IsMultipleProfilesAllowed())
318 return UserList();
319
320 // Supervised users are not allowed to use multi profile. 319 // Supervised users are not allowed to use multi profile.
321 if (logged_in_users_.size() == 1 && 320 if (logged_in_users_.size() == 1 &&
322 GetPrimaryUser()->GetType() != User::USER_TYPE_REGULAR) 321 GetPrimaryUser()->GetType() != User::USER_TYPE_REGULAR)
323 return UserList(); 322 return UserList();
324 323
325 UserList result; 324 UserList result;
326 int num_users_allowed = 0; 325 int num_users_allowed = 0;
327 const UserList& users = GetUsers(); 326 const UserList& users = GetUsers();
328 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 327 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
329 if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in()) { 328 if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in()) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 407
409 const std::string& UserManagerImpl::GetOwnerEmail() { 408 const std::string& UserManagerImpl::GetOwnerEmail() {
410 return owner_email_; 409 return owner_email_;
411 } 410 }
412 411
413 void UserManagerImpl::UserLoggedIn(const std::string& user_id, 412 void UserManagerImpl::UserLoggedIn(const std::string& user_id,
414 const std::string& username_hash, 413 const std::string& username_hash,
415 bool browser_restart) { 414 bool browser_restart) {
416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
417 416
418 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
419 DCHECK(!IsUserLoggedIn());
420
421 User* user = FindUserInListAndModify(user_id); 417 User* user = FindUserInListAndModify(user_id);
422 if (active_user_ && user) { 418 if (active_user_ && user) {
423 user->set_is_logged_in(true); 419 user->set_is_logged_in(true);
424 user->set_username_hash(username_hash); 420 user->set_username_hash(username_hash);
425 logged_in_users_.push_back(user); 421 logged_in_users_.push_back(user);
426 lru_logged_in_users_.push_back(user); 422 lru_logged_in_users_.push_back(user);
427 // Reset the new user flag if the user already exists. 423 // Reset the new user flag if the user already exists.
428 is_current_user_new_ = false; 424 is_current_user_new_ = false;
429 NotifyUserAddedToSession(user); 425 NotifyUserAddedToSession(user);
430 // Remember that we need to switch to this user as soon as profile ready. 426 // Remember that we need to switch to this user as soon as profile ready.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 UMA_HISTOGRAM_ENUMERATION("UserManager.LoginUserType", 482 UMA_HISTOGRAM_ENUMERATION("UserManager.LoginUserType",
487 active_user_->GetType(), User::NUM_USER_TYPES); 483 active_user_->GetType(), User::NUM_USER_TYPES);
488 484
489 g_browser_process->local_state()->SetString(kLastLoggedInRegularUser, 485 g_browser_process->local_state()->SetString(kLastLoggedInRegularUser,
490 (active_user_->GetType() == User::USER_TYPE_REGULAR) ? user_id : ""); 486 (active_user_->GetType() == User::USER_TYPE_REGULAR) ? user_id : "");
491 487
492 NotifyOnLogin(); 488 NotifyOnLogin();
493 } 489 }
494 490
495 void UserManagerImpl::SwitchActiveUser(const std::string& user_id) { 491 void UserManagerImpl::SwitchActiveUser(const std::string& user_id) {
496 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
497 return;
498
499 User* user = FindUserAndModify(user_id); 492 User* user = FindUserAndModify(user_id);
500 if (!user) { 493 if (!user) {
501 NOTREACHED() << "Switching to a non-existing user"; 494 NOTREACHED() << "Switching to a non-existing user";
502 return; 495 return;
503 } 496 }
504 if (user == active_user_) { 497 if (user == active_user_) {
505 NOTREACHED() << "Switching to a user who is already active"; 498 NOTREACHED() << "Switching to a user who is already active";
506 return; 499 return;
507 } 500 }
508 if (!user->is_logged_in()) { 501 if (!user->is_logged_in()) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 const User* UserManagerImpl::GetPrimaryUser() const { 670 const User* UserManagerImpl::GetPrimaryUser() const {
678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
679 return primary_user_; 672 return primary_user_;
680 } 673 }
681 674
682 User* UserManagerImpl::GetUserByProfile(Profile* profile) const { 675 User* UserManagerImpl::GetUserByProfile(Profile* profile) const {
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
684 if (ProfileHelper::IsSigninProfile(profile)) 677 if (ProfileHelper::IsSigninProfile(profile))
685 return NULL; 678 return NULL;
686 679
687 if (IsMultipleProfilesAllowed()) { 680 // Special case for non-CrOS tests that do create several profiles
688 const std::string username_hash = 681 // and don't really care about mapping to the real user.
689 ProfileHelper::GetUserIdHashFromProfile(profile); 682 // Without multi-profiles on Chrome OS such tests always got active_user_.
690 const UserList& users = GetUsers(); 683 // Now these tests will specify special flag to continue working.
691 const UserList::const_iterator pos = std::find_if( 684 // In future those tests can get a proper CrOS configuration i.e. register
692 users.begin(), users.end(), UserHashMatcher(username_hash)); 685 // and login several users if they want to work with an additional profile.
Mr4D (OOO till 08-26) 2014/05/14 16:32:40 It feels rather odd since why should e.g. android/
zel 2014/05/14 17:48:39 Yeah, this flag is not an ideal solution. We shoul
693 if (pos != users.end()) 686 if (CommandLine::ForCurrentProcess()->HasSwitch(
694 return *pos; 687 switches::kIgnoreUserProfileMappingForTests)) {
688 return active_user_;
689 }
695 690
696 // Many tests do not have their users registered with UserManager and 691 const std::string username_hash =
697 // runs here. If |active_user_| matches |profile|, returns it. 692 ProfileHelper::GetUserIdHashFromProfile(profile);
698 return active_user_ && 693 const UserList& users = GetUsers();
699 ProfileHelper::GetProfilePathByUserIdHash( 694 const UserList::const_iterator pos = std::find_if(
700 active_user_->username_hash()) == profile->GetPath() 695 users.begin(), users.end(), UserHashMatcher(username_hash));
701 ? active_user_ 696 if (pos != users.end())
702 : NULL; 697 return *pos;
703 } 698
704 return active_user_; 699 // Many tests do not have their users registered with UserManager and
700 // runs here. If |active_user_| matches |profile|, returns it.
701 return active_user_ &&
702 ProfileHelper::GetProfilePathByUserIdHash(
703 active_user_->username_hash()) == profile->GetPath()
704 ? active_user_
705 : NULL;
705 } 706 }
706 707
707 Profile* UserManagerImpl::GetProfileByUser(const User* user) const { 708 Profile* UserManagerImpl::GetProfileByUser(const User* user) const {
708 Profile* profile = NULL; 709 Profile* profile = NULL;
709 if (IsMultipleProfilesAllowed() && user->is_profile_created()) 710 if (user->is_profile_created())
710 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); 711 profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash());
711 else 712 else
712 profile = ProfileManager::GetActiveUserProfile(); 713 profile = ProfileManager::GetActiveUserProfile();
713 714
714 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance 715 // GetActiveUserProfile() or GetProfileByUserIdHash() returns a new instance
715 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used. 716 // of ProfileImpl(), but actually its OffTheRecordProfile() should be used.
716 if (profile && IsLoggedInAsGuest()) 717 if (profile && IsLoggedInAsGuest())
717 profile = profile->GetOffTheRecordProfile(); 718 profile = profile->GetOffTheRecordProfile();
718 return profile; 719 return profile;
719 } 720 }
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 1861 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1861 return locally_managed_users_allowed || !connector->IsEnterpriseManaged(); 1862 return locally_managed_users_allowed || !connector->IsEnterpriseManaged();
1862 } 1863 }
1863 1864
1864 base::FilePath UserManagerImpl::GetUserProfileDir( 1865 base::FilePath UserManagerImpl::GetUserProfileDir(
1865 const std::string& user_id) const { 1866 const std::string& user_id) const {
1866 // TODO(dpolukhin): Remove Chrome OS specific profile path logic from 1867 // TODO(dpolukhin): Remove Chrome OS specific profile path logic from
1867 // ProfileManager and use only this function to construct profile path. 1868 // ProfileManager and use only this function to construct profile path.
1868 // TODO(nkostylev): Cleanup profile dir related code paths crbug.com/294233 1869 // TODO(nkostylev): Cleanup profile dir related code paths crbug.com/294233
1869 base::FilePath profile_dir; 1870 base::FilePath profile_dir;
1870 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1871 const User* user = FindUser(user_id);
1871 if (command_line.HasSwitch(::switches::kMultiProfiles)) { 1872 if (user && !user->username_hash().empty())
1872 const User* user = FindUser(user_id); 1873 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash());
1873 if (user && !user->username_hash().empty())
1874 profile_dir = ProfileHelper::GetUserProfileDir(user->username_hash());
1875 } else if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) {
1876 profile_dir = ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch();
1877 } else {
1878 // We should never be logged in with no profile dir unless
1879 // multi-profiles are enabled.
1880 NOTREACHED();
1881 profile_dir = base::FilePath();
1882 }
1883 1874
1884 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1875 ProfileManager* profile_manager = g_browser_process->profile_manager();
1885 profile_dir = profile_manager->user_data_dir().Append(profile_dir); 1876 profile_dir = profile_manager->user_data_dir().Append(profile_dir);
1886 1877
1887 return profile_dir; 1878 return profile_dir;
1888 } 1879 }
1889 1880
1890 UserFlow* UserManagerImpl::GetDefaultUserFlow() const { 1881 UserFlow* UserManagerImpl::GetDefaultUserFlow() const {
1891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1892 if (!default_flow_.get()) 1883 if (!default_flow_.get())
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 } 2088 }
2098 2089
2099 void UserManagerImpl::DeleteUser(User* user) { 2090 void UserManagerImpl::DeleteUser(User* user) {
2100 const bool is_active_user = (user == active_user_); 2091 const bool is_active_user = (user == active_user_);
2101 delete user; 2092 delete user;
2102 if (is_active_user) 2093 if (is_active_user)
2103 active_user_ = NULL; 2094 active_user_ = NULL;
2104 } 2095 }
2105 2096
2106 } // namespace chromeos 2097 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698