Index: chrome/browser/chromeos/login/users/user_manager_base.h |
diff --git a/chrome/browser/chromeos/login/users/user_manager_impl.h b/chrome/browser/chromeos/login/users/user_manager_base.h |
similarity index 58% |
rename from chrome/browser/chromeos/login/users/user_manager_impl.h |
rename to chrome/browser/chromeos/login/users/user_manager_base.h |
index 46ed7c9d01414155e32c6912e6dedefa1ccd2ecf..db63e21d4e4e1d9c4e227b781ed9a8d4ca1b4177 100644 |
--- a/chrome/browser/chromeos/login/users/user_manager_impl.h |
+++ b/chrome/browser/chromeos/login/users/user_manager_base.h |
@@ -2,69 +2,41 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
-#define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_BASE_H_ |
+#define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_BASE_H_ |
-#include <map> |
+#include <set> |
#include <string> |
#include <vector> |
#include "base/basictypes.h" |
-#include "base/containers/hash_tables.h" |
-#include "base/memory/linked_ptr.h" |
-#include "base/memory/scoped_ptr.h" |
#include "base/observer_list.h" |
#include "base/synchronization/lock.h" |
#include "base/time/time.h" |
-#include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
-#include "chrome/browser/chromeos/login/users/multi_profile_user_controller_delegate.h" |
#include "chrome/browser/chromeos/login/users/user_manager.h" |
-#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
-#include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" |
-#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
-#include "chrome/browser/chromeos/settings/cros_settings.h" |
-#include "chrome/browser/chromeos/settings/device_settings_service.h" |
#include "components/user_manager/user.h" |
-#include "content/public/browser/notification_observer.h" |
-#include "content/public/browser/notification_registrar.h" |
class PrefService; |
-class ProfileSyncService; |
- |
-namespace policy { |
-struct DeviceLocalAccount; |
-} |
+class PrefRegistrySimple; |
namespace chromeos { |
-class MultiProfileUserController; |
class RemoveUserDelegate; |
-class SupervisedUserManagerImpl; |
-class SessionLengthLimiter; |
- |
-// Implementation of the UserManager. |
-class UserManagerImpl |
- : public UserManager, |
- public content::NotificationObserver, |
- public policy::CloudExternalDataPolicyObserver::Delegate, |
- public policy::DeviceLocalAccountPolicyService::Observer, |
- public MultiProfileUserControllerDelegate { |
+ |
+// Base implementation of the UserManager interface. |
+class UserManagerBase : public UserManager { |
public: |
- virtual ~UserManagerImpl(); |
+ virtual ~UserManagerBase(); |
+ |
+ // Registers UserManagerBase preferences. |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
// UserManager implementation: |
virtual void Shutdown() OVERRIDE; |
- virtual MultiProfileUserController* GetMultiProfileUserController() OVERRIDE; |
- virtual UserImageManager* GetUserImageManager( |
- const std::string& user_id) OVERRIDE; |
- virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE; |
virtual const user_manager::UserList& GetUsers() const OVERRIDE; |
- virtual user_manager::UserList GetUsersAdmittedForMultiProfile() |
- const OVERRIDE; |
virtual const user_manager::UserList& GetLoggedInUsers() const OVERRIDE; |
virtual const user_manager::UserList& GetLRULoggedInUsers() OVERRIDE; |
Dmitry Polukhin
2014/07/28 09:32:39
const?
Nikita (slow)
2014/07/29 09:27:28
Done.
|
- virtual user_manager::UserList GetUnlockUsers() const OVERRIDE; |
- virtual const std::string& GetOwnerEmail() OVERRIDE; |
+ virtual const std::string& GetOwnerEmail() const OVERRIDE; |
virtual void UserLoggedIn(const std::string& user_id, |
const std::string& user_id_hash, |
bool browser_restart) OVERRIDE; |
@@ -122,156 +94,190 @@ class UserManagerImpl |
UserManager::UserSessionStateObserver* obs) OVERRIDE; |
virtual void NotifyLocalStateChanged() OVERRIDE; |
- virtual UserFlow* GetCurrentUserFlow() const OVERRIDE; |
- virtual UserFlow* GetUserFlow(const std::string& user_id) const OVERRIDE; |
- virtual void SetUserFlow(const std::string& user_id, UserFlow* flow) OVERRIDE; |
- virtual void ResetUserFlow(const std::string& user_id) OVERRIDE; |
- virtual bool AreSupervisedUsersAllowed() const OVERRIDE; |
- |
- // content::NotificationObserver implementation. |
- virtual void Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) OVERRIDE; |
+ // Helper function that copies users from |users_list| to |users_vector| and |
+ // |users_set|. Duplicates and users already present in |existing_users| are |
+ // skipped. |
+ static void ParseUserList(const base::ListValue& users_list, |
+ const std::set<std::string>& existing_users, |
+ std::vector<std::string>* users_vector, |
+ std::set<std::string>* users_set); |
- // policy::CloudExternalDataPolicyObserver::Delegate: |
- virtual void OnExternalDataSet(const std::string& policy, |
- const std::string& user_id) OVERRIDE; |
- virtual void OnExternalDataCleared(const std::string& policy, |
- const std::string& user_id) OVERRIDE; |
- virtual void OnExternalDataFetched(const std::string& policy, |
- const std::string& user_id, |
- scoped_ptr<std::string> data) OVERRIDE; |
+ protected: |
+ UserManagerBase(); |
- // policy::DeviceLocalAccountPolicyService::Observer implementation. |
- virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; |
- virtual void OnDeviceLocalAccountsChanged() OVERRIDE; |
+ // Adds |user| to users list, and adds it to front of LRU list. It is assumed |
+ // that there is no user with same id. |
+ virtual void AddUserRecord(user_manager::User* user); |
- void StopPolicyObserverForTesting(); |
+ // Returns true if trusted device policies have successfully been retrieved |
+ // and ephemeral users are enabled. |
+ virtual bool AreEphemeralUsersEnabled() const = 0; |
- private: |
- friend class SupervisedUserManagerImpl; |
- friend class UserManager; |
- friend class WallpaperManager; |
- friend class UserManagerTest; |
- friend class WallpaperManagerTest; |
+ // Returns true if user may be removed. |
+ virtual bool CanUserBeRemoved(const user_manager::User* user) const; |
- typedef base::hash_map<std::string, |
- linked_ptr<UserImageManager> > UserImageManagerMap; |
+ // A wrapper around C++ delete operator. Deletes |user|, and when |user| |
+ // equals to active_user_, active_user_ is reset to NULL. |
+ virtual void DeleteUser(user_manager::User* user); |
- // Stages of loading user list from preferences. Some methods can have |
- // different behavior depending on stage. |
- enum UserLoadStage { |
- STAGE_NOT_LOADED = 0, |
- STAGE_LOADING, |
- STAGE_LOADED |
- }; |
+ // Returns the locale used by the application. |
+ virtual const std::string& GetApplicationLocale() const = 0; |
- UserManagerImpl(); |
+ // Returns "Local State" PrefService instance. |
+ virtual PrefService* GetLocalState() const = 0; |
// Loads |users_| from Local State if the list has not been loaded yet. |
// Subsequent calls have no effect. Must be called on the UI thread. |
void EnsureUsersLoaded(); |
- // Retrieves trusted device policies and removes users from the persistent |
- // list if ephemeral users are enabled. Schedules a callback to itself if |
- // trusted device policies are not yet available. |
- void RetrieveTrustedDevicePolicies(); |
+ // Returns true if device is enterprise managed. |
+ virtual bool IsEnterpriseManaged() const = 0; |
- // Returns true if trusted device policies have successfully been retrieved |
- // and ephemeral users are enabled. |
- bool AreEphemeralUsersEnabled() const; |
+ // Helper function that copies users from |users_list| to |users_vector| and |
+ // |users_set|. Duplicates and users already present in |existing_users| are |
+ // skipped. |
+ // Loads public accounts from the Local state and fills in |
+ // |public_sessions_set|. |
+ virtual void LoadPublicAccounts( |
+ std::set<std::string>* public_sessions_set) = 0; |
- // Returns a list of users who have logged into this device previously. |
- // Same as GetUsers but used if you need to modify User from that list. |
- user_manager::UserList& GetUsersAndModify(); |
+ // Notifies that user has logged in. |
+ virtual void NotifyOnLogin(); |
- // Returns the user with the given email address if found in the persistent |
- // list. Returns |NULL| otherwise. |
- const user_manager::User* FindUserInList(const std::string& user_id) const; |
+ // Notifies observers that another user was added to the session. |
+ // If |user_switch_pending| is true this means that user has not been fully |
+ // initialized yet like waiting for profile to be loaded. |
+ virtual void NotifyUserAddedToSession(const user_manager::User* added_user, |
+ bool user_switch_pending); |
- // Returns |true| if user with the given id is found in the persistent list. |
- // Returns |false| otherwise. Does not trigger user loading. |
- const bool UserExistsInList(const std::string& user_id) const; |
+ // Performs any additional actions before user list is loaded. |
+ virtual void PerformPreUserListLoadingActions() = 0; |
- // Same as FindUserInList but returns non-const pointer to User object. |
- user_manager::User* FindUserInListAndModify(const std::string& user_id); |
+ // Performs any additional actions after user list is loaded. |
+ virtual void PerformPostUserListLoadingActions() = 0; |
+ |
+ // Performs any additional actions after UserLoggedIn() execution has been |
+ // completed. |
+ // |browser_restart| is true when reloading Chrome after crash to distinguish |
+ // from normal sign in flow. |
+ virtual void PerformPostUserLoggedInActions(bool browser_restart) = 0; |
+ |
+ // Implementation for RemoveUser method. It is synchronous. It is called from |
+ // RemoveUserInternal after owner check. |
+ virtual void RemoveNonOwnerUserInternal(const std::string& user_email, |
+ RemoveUserDelegate* delegate); |
+ |
+ // Removes a regular or supervised user from the user list. |
+ // Returns the user if found or NULL otherwise. |
+ // Also removes the user from the persistent user list. |
+ user_manager::User* RemoveRegularOrSupervisedUserFromList( |
+ const std::string& user_id); |
+ |
+ // Implementation for RemoveUser method. This is an asynchronous part of the |
+ // method, that verifies that owner will not get deleted, and calls |
+ // |RemoveNonOwnerUserInternal|. |
+ virtual void RemoveUserInternal(const std::string& user_email, |
+ RemoveUserDelegate* delegate); |
+ |
+ // Removes data stored or cached outside the user's cryptohome (wallpaper, |
+ // avatar, OAuth token status, display name, display email). |
+ virtual void RemoveNonCryptohomeData(const std::string& user_id); |
+ |
+ // Check for a particular user type. |
+ |
+ // Returns true if |user_id| represents demo app. |
+ virtual bool IsDemoApp(const std::string& user_id) const = 0; |
+ |
+ // Returns true if |user_id| represents kiosk app. |
+ virtual bool IsKioskApp(const std::string& user_id) const = 0; |
+ |
+ // Returns true if |user_id| represents public account that has been marked |
+ // for deletion. |
+ virtual bool IsPublicAccountMarkedForRemoval( |
+ const std::string& user_id) const = 0; |
+ |
+ // These methods are called when corresponding user type has signed in. |
+ |
+ // Indicates that the demo account has just logged in. |
+ virtual void DemoAccountLoggedIn() = 0; |
// Indicates that a user just logged in as guest. |
- void GuestUserLoggedIn(); |
+ virtual void GuestUserLoggedIn(); |
+ |
+ // Indicates that a kiosk app robot just logged in. |
+ virtual void KioskAppLoggedIn(const std::string& app_id) = 0; |
+ |
+ // Indicates that a user just logged into a public session. |
+ virtual void PublicAccountUserLoggedIn(user_manager::User* user) = 0; |
// Indicates that a regular user just logged in. |
- void RegularUserLoggedIn(const std::string& user_id); |
+ virtual void RegularUserLoggedIn(const std::string& user_id); |
// Indicates that a regular user just logged in as ephemeral. |
- void RegularUserLoggedInAsEphemeral(const std::string& user_id); |
+ virtual void RegularUserLoggedInAsEphemeral(const std::string& user_id); |
+ |
+ // Indicates that a user just logged into a retail mode session. |
+ virtual void RetailModeUserLoggedIn() = 0; |
// Indicates that a supervised user just logged in. |
- void SupervisedUserLoggedIn(const std::string& user_id); |
+ virtual void SupervisedUserLoggedIn(const std::string& user_id) = 0; |
- // Indicates that a user just logged into a public session. |
- void PublicAccountUserLoggedIn(user_manager::User* user); |
+ // Getters/setters for private members. |
- // Indicates that a kiosk app robot just logged in. |
- void KioskAppLoggedIn(const std::string& app_id); |
+ virtual void SetCurrentUserIsOwner(bool is_current_user_owner); |
- // Indicates that the demo account has just logged in. |
- void DemoAccountLoggedIn(); |
+ virtual bool GetEphemeralUsersEnabled() const; |
+ virtual void SetEphemeralUsersEnabled(bool enabled); |
- // Indicates that a user just logged into a retail mode session. |
- void RetailModeUserLoggedIn(); |
+ virtual void SetIsCurrentUserNew(bool is_new); |
- // Notifies that user has logged in. |
- // Sends NOTIFICATION_LOGIN_USER_CHANGED notification. |
- void NotifyOnLogin(); |
+ virtual void SetOwnerEmail(std::string owner_user_id); |
- // Reads user's oauth token status from local state preferences. |
- user_manager::User::OAuthTokenStatus LoadUserOAuthStatus( |
- const std::string& user_id) const; |
+ virtual const std::string& GetPendingUserSwitchID() const; |
+ virtual void SetPendingUserSwitchID(std::string user_id); |
- // Read a flag indicating whether online authentication against GAIA should |
- // be enforced during the user's next sign-in from local state preferences. |
- bool LoadForceOnlineSignin(const std::string& user_id) const; |
+ // The logged-in user that is currently active in current session. |
+ // NULL until a user has logged in, then points to one |
+ // of the User instances in |users_|, the |guest_user_| instance or an |
+ // ephemeral user instance. |
+ user_manager::User* active_user_; |
- void SetCurrentUserIsOwner(bool is_current_user_owner); |
+ // The primary user of the current session. It is recorded for the first |
+ // signed-in user and does not change thereafter. |
+ user_manager::User* primary_user_; |
- // Updates current user ownership on UI thread. |
- void UpdateOwnership(); |
+ // List of all known users. User instances are owned by |this|. Regular users |
+ // are removed by |RemoveUserFromList|, public accounts by |
+ // |UpdateAndCleanUpPublicAccounts|. |
+ user_manager::UserList users_; |
- // Removes data stored or cached outside the user's cryptohome (wallpaper, |
- // avatar, OAuth token status, display name, display email). |
- void RemoveNonCryptohomeData(const std::string& user_id); |
+ private: |
+ // Stages of loading user list from preferences. Some methods can have |
+ // different behavior depending on stage. |
+ enum UserLoadStage { STAGE_NOT_LOADED = 0, STAGE_LOADING, STAGE_LOADED }; |
- // Removes a regular or supervised user from the user list. |
- // Returns the user if found or NULL otherwise. |
- // Also removes the user from the persistent user list. |
- user_manager::User* RemoveRegularOrSupervisedUserFromList( |
- const std::string& user_id); |
+ // Returns a list of users who have logged into this device previously. |
+ // Same as GetUsers but used if you need to modify User from that list. |
+ user_manager::UserList& GetUsersAndModify(); |
- // If data for a public account is marked as pending removal and the user is |
- // no longer logged into that account, removes the data. |
- void CleanUpPublicAccountNonCryptohomeDataPendingRemoval(); |
+ // Returns the user with the given email address if found in the persistent |
+ // list. Returns |NULL| otherwise. |
+ const user_manager::User* FindUserInList(const std::string& user_id) const; |
- // Removes data belonging to public accounts that are no longer found on the |
- // user list. If the user is currently logged into one of these accounts, the |
- // data for that account is not removed immediately but marked as pending |
- // removal after logout. |
- void CleanUpPublicAccountNonCryptohomeData( |
- const std::vector<std::string>& old_public_accounts); |
+ // Returns |true| if user with the given id is found in the persistent list. |
+ // Returns |false| otherwise. Does not trigger user loading. |
+ const bool UserExistsInList(const std::string& user_id) const; |
- // Replaces the list of public accounts with those found in |
- // |device_local_accounts|. Ensures that data belonging to accounts no longer |
- // on the list is removed. Returns |true| if the list has changed. |
- // Public accounts are defined by policy. This method is called whenever an |
- // updated list of public accounts is received from policy. |
- bool UpdateAndCleanUpPublicAccounts( |
- const std::vector<policy::DeviceLocalAccount>& device_local_accounts); |
+ // Same as FindUserInList but returns non-const pointer to User object. |
+ user_manager::User* FindUserInListAndModify(const std::string& user_id); |
- // Updates the display name for public account |username| from policy settings |
- // associated with that username. |
- void UpdatePublicAccountDisplayName(const std::string& user_id); |
+ // Reads user's oauth token status from local state preferences. |
+ user_manager::User::OAuthTokenStatus LoadUserOAuthStatus( |
+ const std::string& user_id) const; |
- // Notifies the UI about a change to the user list. |
- void NotifyUserListChanged(); |
+ // Read a flag indicating whether online authentication against GAIA should |
+ // be enforced during the user's next sign-in from local state preferences. |
+ bool LoadForceOnlineSignin(const std::string& user_id) const; |
// Notifies observers that merge session state had changed. |
void NotifyMergeSessionStateChanged(); |
@@ -279,42 +285,18 @@ class UserManagerImpl |
// Notifies observers that active user has changed. |
void NotifyActiveUserChanged(const user_manager::User* active_user); |
- // Notifies observers that another user was added to the session. |
- void NotifyUserAddedToSession(const user_manager::User* added_user); |
- |
// Notifies observers that active user_id hash has changed. |
void NotifyActiveUserHashChanged(const std::string& hash); |
- // Lazily creates default user flow. |
- UserFlow* GetDefaultUserFlow() const; |
- |
// Update the global LoginState. |
void UpdateLoginState(); |
// Insert |user| at the front of the LRU user list. |
void SetLRUUser(user_manager::User* user); |
- // Adds |user| to users list, and adds it to front of LRU list. It is assumed |
- // that there is no user with same id. |
- void AddUserRecord(user_manager::User* user); |
- |
// Sends metrics in response to a regular user logging in. |
void SendRegularUserLoginMetrics(const std::string& user_id); |
- // Implementation for RemoveUser method. This is an asynchronous part of the |
- // method, that verifies that owner will not get deleted, and calls |
- // |RemoveNonOwnerUserInternal|. |
- void RemoveUserInternal(const std::string& user_email, |
- RemoveUserDelegate* delegate); |
- |
- // Implementation for RemoveUser method. It is synchronous. It is called from |
- // RemoveUserInternal after owner check. |
- void RemoveNonOwnerUserInternal(const std::string& user_email, |
- RemoveUserDelegate* delegate); |
- |
- // MultiProfileUserControllerDelegate implementation: |
- virtual void OnUserNotAllowed(const std::string& user_email) OVERRIDE; |
- |
// Sets account locale for user with id |user_id|. |
virtual void UpdateUserAccountLocale(const std::string& user_id, |
const std::string& locale); |
@@ -323,27 +305,9 @@ class UserManagerImpl |
void DoUpdateAccountLocale(const std::string& user_id, |
const std::string& resolved_locale); |
- // Update the number of users. |
- void UpdateNumberOfUsers(); |
- |
- // A wrapper around C++ delete operator. Deletes |user|, and when |user| |
- // equals to active_user_, active_user_ is reset to NULL. |
- void DeleteUser(user_manager::User* user); |
- |
- // Interface to the signed settings store. |
- CrosSettings* cros_settings_; |
- |
- // Interface to device-local account definitions and associated policy. |
- policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_; |
- |
// Indicates stage of loading user from prefs. |
UserLoadStage user_loading_stage_; |
- // List of all known users. User instances are owned by |this|. Regular users |
- // are removed by |RemoveUserFromList|, public accounts by |
- // |UpdateAndCleanUpPublicAccounts|. |
- user_manager::UserList users_; |
- |
// List of all users that are logged in current session. These point to User |
// instances in |users_|. Only one of them could be marked as active. |
user_manager::UserList logged_in_users_; |
@@ -356,16 +320,6 @@ class UserManagerImpl |
// The list which gets reported when the |lru_logged_in_users_| list is empty. |
user_manager::UserList temp_single_logged_in_users_; |
- // The logged-in user that is currently active in current session. |
- // NULL until a user has logged in, then points to one |
- // of the User instances in |users_|, the |guest_user_| instance or an |
- // ephemeral user instance. |
- user_manager::User* active_user_; |
- |
- // The primary user of the current session. It is recorded for the first |
- // signed-in user and does not change thereafter. |
- user_manager::User* primary_user_; |
- |
// True if SessionStarted() has been called. |
bool session_started_; |
@@ -394,54 +348,22 @@ class UserManagerImpl |
// been read from trusted device policy yet. |
std::string owner_email_; |
- content::NotificationRegistrar registrar_; |
- |
ObserverList<UserManager::Observer> observer_list_; |
// TODO(nkostylev): Merge with session state refactoring CL. |
ObserverList<UserManager::UserSessionStateObserver> |
session_state_observer_list_; |
- // User avatar managers. |
- UserImageManagerMap user_image_managers_; |
- |
- // Supervised user manager. |
- scoped_ptr<SupervisedUserManagerImpl> supervised_user_manager_; |
- |
- // Session length limiter. |
- scoped_ptr<SessionLengthLimiter> session_length_limiter_; |
- |
- typedef std::map<std::string, UserFlow*> FlowMap; |
- |
- // Lazy-initialized default flow. |
- mutable scoped_ptr<UserFlow> default_flow_; |
- |
- // Specific flows by user e-mail. Keys should be canonicalized before |
- // access. |
- FlowMap specific_flows_; |
- |
// Time at which this object was created. |
base::TimeTicks manager_creation_time_; |
- scoped_ptr<CrosSettings::ObserverSubscription> |
- local_accounts_subscription_; |
- |
- scoped_ptr<MultiProfileUserController> multi_profile_user_controller_; |
- |
- // Observer for the policy that can be used to manage user images. |
- scoped_ptr<policy::CloudExternalDataPolicyObserver> avatar_policy_observer_; |
- |
- // Observer for the policy that can be used to manage wallpapers. |
- scoped_ptr<policy::CloudExternalDataPolicyObserver> |
- wallpaper_policy_observer_; |
- |
// ID of the user just added to the session that needs to be activated |
// as soon as user's profile is loaded. |
std::string pending_user_switch_; |
- DISALLOW_COPY_AND_ASSIGN(UserManagerImpl); |
+ DISALLOW_COPY_AND_ASSIGN(UserManagerBase); |
}; |
} // namespace chromeos |
-#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_IMPL_H_ |
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_USER_MANAGER_BASE_H_ |