user_manager.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#ifndef COMPONENTS_USER_MANAGER_USER_MANAGER_H_
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define COMPONENTS_USER_MANAGER_USER_MANAGER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/user_manager/user.h"
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "components/user_manager/user_manager_export.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class ScopedUserManagerEnabler;
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace user_manager {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RemoveUserDelegate;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Interface for UserManagerBase - that provides base implementation for
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Chrome OS user management. Typical features:
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// * Get list of all know users (who have logged into this Chrome OS device)
246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// * Keep track for logged in/LRU users, active user in multi-user session.
256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// * Find/modify users, store user meta-data such as display name/email.
266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class USER_MANAGER_EXPORT UserManager {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Interface that observers of UserManager must implement in order
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to receive notification when local state preferences is changed
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Observer {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Called when the local state preferences is changed.
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    virtual void LocalStateChanged(UserManager* user_manager);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    virtual ~Observer();
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  };
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // TODO(nkostylev): Refactor and move this observer out of UserManager.
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Observer interface that defines methods used to notify on user session /
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // active user state changes. Default implementation is empty.
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  class UserSessionStateObserver {
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   public:
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    // Called when active user has changed.
456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    virtual void ActiveUserChanged(const User* active_user);
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // Called when another user got added to the existing session.
486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    virtual void UserAddedToSession(const User* added_user);
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Called right before notifying on user change so that those who rely
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // on user_id hash would be accessing up-to-date value.
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    virtual void ActiveUserHashChanged(const std::string& hash);
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   protected:
55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    virtual ~UserSessionStateObserver();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Data retrieved from user account.
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  class UserAccountData {
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)   public:
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    UserAccountData(const base::string16& display_name,
62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                    const base::string16& given_name,
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    const std::string& locale);
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ~UserAccountData();
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& display_name() const { return display_name_; }
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16& given_name() const { return given_name_; }
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& locale() const { return locale_; }
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)   private:
70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16 display_name_;
71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16 given_name_;
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string locale_;
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(UserAccountData);
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  };
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Initializes UserManager instance to this. Normally should be called right
786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // after creation so that user_manager::UserManager::Get() doesn't fail.
796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Tests could call this method if they are replacing existing UserManager
806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // instance with their own test instance.
816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void Initialize();
82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Checks whether the UserManager instance has been created already.
846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This method is not thread-safe and must be called from the main UI thread.
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static bool IsInitialized();
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Shuts down the UserManager. After this method has been called, the
88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // singleton has unregistered itself as an observer but remains available so
89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // that other classes can access it during their shutdown. This method is not
90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // thread-safe and must be called from the main UI thread.
91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void Shutdown() = 0;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Sets UserManager instance to NULL. Always call Shutdown() first.
946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This method is not thread-safe and must be called from the main UI thread.
956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void Destroy();
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Returns UserManager instance or will crash if it is |NULL| (has either not
986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // been created yet or is already destroyed). This method is not thread-safe
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // and must be called from the main UI thread.
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static UserManager* Get();
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~UserManager();
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a list of users who have logged into this device previously. This
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is sorted by last login date with the most recent user at the beginning.
1066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const UserList& GetUsers() const = 0;
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns list of users admitted for logging in into multi-profile session.
1096d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Users that have a policy that prevents them from being added to the
1106d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // multi-profile session will still be part of this list as long as they
1116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // are regular users (i.e. not a public session/supervised etc.).
1126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Returns an empty list in case when primary user is not a regular one or
1136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // has a policy that prohibids it to be part of multi-profile session.
1146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual UserList GetUsersAdmittedForMultiProfile() const = 0;
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns a list of users who are currently logged in.
1176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const UserList& GetLoggedInUsers() const = 0;
118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Returns a list of users who are currently logged in in the LRU order -
12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // so the active user is the first one in the list. If there is no user logged
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // in, the current user will be returned.
1226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const UserList& GetLRULoggedInUsers() const = 0;
12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns a list of users who can unlock the device.
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This list is based on policy and whether user is able to do unlock.
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Policy:
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * If user has primary-only policy then it is the only user in unlock users.
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * Otherwise all users with unrestricted policy are added to this list.
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All users that are unable to perform unlock are excluded from this list.
1306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual UserList GetUnlockUsers() const = 0;
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
13258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Returns the email of the owner user. Returns an empty string if there is
13358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // no owner for the device.
1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual const std::string& GetOwnerEmail() const = 0;
13558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Indicates that a user with the given |user_id| has just logged in. The
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // persistent list is updated accordingly if the user is not ephemeral.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |browser_restart| is true when reloading Chrome after crash to distinguish
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from normal sign in flow.
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // |username_hash| is used to identify homedir mount point.
1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void UserLoggedIn(const std::string& user_id,
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            const std::string& username_hash,
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            bool browser_restart) = 0;
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Switches to active user identified by |user_id|. User has to be logged in.
1468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SwitchActiveUser(const std::string& user_id) = 0;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when browser session is started i.e. after
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // browser_creator.LaunchBrowser(...) was called after user sign in.
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When user is at the image screen IsUserLoggedIn() will return true
151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // but IsSessionStarted() will return false. During the kiosk splash screen,
152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // we perform additional initialization after the user is logged in but
153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // before the session has been started.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Fires NOTIFICATION_SESSION_STARTED.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SessionStarted() = 0;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes the user from the device. Note, it will verify that the given user
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // isn't the owner, so calling this method for the owner will take no effect.
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note, |delegate| can be NULL.
1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void RemoveUser(const std::string& user_id,
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          RemoveUserDelegate* delegate) = 0;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes the user from the persistent list only. Also removes the user's
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // picture.
1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void RemoveUserFromList(const std::string& user_id) = 0;
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns true if a user with the given user id is found in the persistent
1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // list or currently logged in as ephemeral.
1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual bool IsKnownUser(const std::string& user_id) const = 0;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns the user with the given user id if found in the persistent
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // list or currently logged in as ephemeral. Returns |NULL| otherwise.
1736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const User* FindUser(const std::string& user_id) const = 0;
1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the user with the given user id if found in the persistent
176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // list or currently logged in as ephemeral. Returns |NULL| otherwise.
177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Same as FindUser but returns non-const pointer to User object.
1786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual User* FindUserAndModify(const std::string& user_id) = 0;
179f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the logged-in user.
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(nkostylev): Deprecate this call, move clients to GetActiveUser().
182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // http://crbug.com/230852
1836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const User* GetLoggedInUser() const = 0;
1846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual User* GetLoggedInUser() = 0;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the logged-in user that is currently active within this session.
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // There could be multiple users logged in at the the same but for now
188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // we support only one of them being active.
1896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const User* GetActiveUser() const = 0;
1906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual User* GetActiveUser() = 0;
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
192d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the primary user of the current session. It is recorded for the
193d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // first signed-in user and does not change thereafter.
1946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual const User* GetPrimaryUser() const = 0;
195d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Saves user's oauth token status in local state preferences.
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SaveUserOAuthStatus(
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const std::string& user_id,
1996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      User::OAuthTokenStatus oauth_token_status) = 0;
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Saves a flag indicating whether online authentication against GAIA should
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // be enforced during the user's next sign-in.
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SaveForceOnlineSignin(const std::string& user_id,
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                     bool force_online_signin) = 0;
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Saves user's displayed name in local state preferences.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ignored If there is no such user.
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SaveUserDisplayName(const std::string& user_id,
209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                   const base::string16& display_name) = 0;
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
21168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Updates data upon User Account download.
2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void UpdateUserAccountData(const std::string& user_id,
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                     const UserAccountData& account_data) = 0;
21468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns the display name for user |user_id| if it is known (was
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // previously set by a |SaveUserDisplayName| call).
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Otherwise, returns an empty string.
218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual base::string16 GetUserDisplayName(
2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const std::string& user_id) const = 0;
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Saves user's displayed (non-canonical) email in local state preferences.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ignored If there is no such user.
2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SaveUserDisplayEmail(const std::string& user_id,
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const std::string& display_email) = 0;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns the display email for user |user_id| if it is known (was
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // previously set by a |SaveUserDisplayEmail| call).
2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Otherwise, returns |user_id| itself.
2296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual std::string GetUserDisplayEmail(const std::string& user_id) const = 0;
2307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if current user is an owner.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsCurrentUserOwner() const = 0;
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if current user is not existing one (hasn't signed in before).
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsCurrentUserNew() const = 0;
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if data stored or cached for the current user outside that
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // user's cryptohome (wallpaper, avatar, OAuth token status, display name,
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // display email) is ephemeral.
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const = 0;
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the current user's session can be locked (i.e. the user has
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // a password with which to unlock the session).
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool CanCurrentUserLock() const = 0;
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if at least one user has signed in.
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsUserLoggedIn() const = 0;
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if we're logged in as a regular user.
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsLoggedInAsRegularUser() const = 0;
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we're logged in as a demo user.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsLoggedInAsDemoUser() const = 0;
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we're logged in as a public account.
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsLoggedInAsPublicAccount() const = 0;
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we're logged in as a Guest.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsLoggedInAsGuest() const = 0;
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns true if we're logged in as a supervised user.
2625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual bool IsLoggedInAsSupervisedUser() const = 0;
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if we're logged in as a kiosk app.
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsLoggedInAsKioskApp() const = 0;
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we're logged in as the stub user used for testing on Linux.
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsLoggedInAsStub() const = 0;
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we're logged in and browser has been started i.e.
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // browser_creator.LaunchBrowser(...) was called after sign in
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or restart after crash.
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsSessionStarted() const = 0;
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns true if data stored or cached for the user with the given user id
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // address outside that user's cryptohome (wallpaper, avatar, OAuth token
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // status, display name, display email) is to be treated as ephemeral.
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsUserNonCryptohomeDataEphemeral(
2798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const std::string& user_id) const = 0;
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AddObserver(Observer* obs) = 0;
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RemoveObserver(Observer* obs) = 0;
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void AddSessionStateObserver(UserSessionStateObserver* obs) = 0;
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void RemoveSessionStateObserver(UserSessionStateObserver* obs) = 0;
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void NotifyLocalStateChanged() = 0;
288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns true if supervised users allowed.
2905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual bool AreSupervisedUsersAllowed() const = 0;
291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) protected:
2936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Sets UserManager instance.
2946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  static void SetInstance(UserManager* user_manager);
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Pointer to the existing UserManager instance (if any).
2976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Usually is set by calling Initialize(), reset by calling Destroy().
2986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Not owned since specific implementation of UserManager should decide on its
2996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // own appropriate owner. For src/chrome implementation such place is
3006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // g_browser_process->platform_part().
3016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  static UserManager* instance;
302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private:
3046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  friend class chromeos::ScopedUserManagerEnabler;
305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Same as Get() but doesn't won't crash is current instance is NULL.
3076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  static UserManager* GetForTesting();
308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Sets UserManager instance to the given |user_manager|.
3106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Returns the previous value of the instance.
3116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  static UserManager* SetForTesting(UserManager* user_manager);
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}  // namespace user_manager
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif  // COMPONENTS_USER_MANAGER_USER_MANAGER_H_
317