summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/user_manager.h
blob: fe3f53977e3766ceff71d60a56adee3d2f2985a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// 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_USER_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_
#pragma once

#include <string>

#include "ash/desktop_background/desktop_background_resources.h"
#include "base/memory/singleton.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h"

class SkBitmap;
class FilePath;
class PrefService;

namespace chromeos {

class RemoveUserDelegate;
class UserImage;

// Base class for UserManagerImpl - provides a mechanism for discovering users
// who have logged into this Chrome OS device before and updating that list.
class UserManager {
 public:
  // Interface that observers of UserManager must implement in order
  // to receive notification when local state preferences is changed
  class Observer {
   public:
    // Called when the local state preferences is changed
    virtual void LocalStateChanged(UserManager* user_manager) = 0;

   protected:
    virtual ~Observer() {}
  };

  // A vector pref of the users who have logged into the device.
  static const char kLoggedInUsers[];

  // A dictionary that maps usernames to file paths to their wallpapers.
  // Deprecated. Will remove this const char after done migration.
  static const char kUserWallpapers[];

  // A dictionary that maps usernames to wallpaper properties.
  static const char kUserWallpapersProperties[];

  // A dictionary that maps usernames to file paths to their images.
  static const char kUserImages[];

  // A dictionary that maps usernames to the displayed name.
  static const char kUserDisplayName[];

  // A dictionary that maps usernames to the displayed (non-canonical) emails.
  static const char kUserDisplayEmail[];

  // A dictionary that maps usernames to OAuth token presence flag.
  static const char kUserOAuthTokenStatus[];

  // Returns a shared instance of a UserManager. Not thread-safe, should only be
  // called from the main UI thread.
  static UserManager* Get();

  // Set UserManager singleton object for test purpose only! Returns the
  // previous singleton object and releases it from the singleton memory
  // management. It is the responsibility of the test writer to restore the
  // original object or delete it if needed.
  //
  // The intended usage is meant to be something like this:
  //   virtual void SetUp() {
  //     mock_user_manager_.reset(new MockUserManager());
  //     old_user_manager_ = UserManager::Set(mock_user_manager_.get());
  //     EXPECT_CALL...
  //     ...
  //   }
  //   virtual void TearDown() {
  //     ...
  //     UserManager::Set(old_user_manager_);
  //   }
  //   scoped_ptr<MockUserManager> mock_user_manager_;
  //   UserManager* old_user_manager_;
  static UserManager* Set(UserManager* mock);

  // Registers user manager preferences.
  static void RegisterPrefs(PrefService* local_state);

  virtual ~UserManager();

  // Returns a list of users who have logged into this device previously. This
  // is sorted by last login date with the most recent user at the beginning.
  virtual const UserList& GetUsers() const = 0;

  // Indicates that a user with the given email has just logged in. The
  // persistent list is updated accordingly if the user is not ephemeral.
  // |browser_restart| is true when reloading Chrome after crash to distinguish
  // from normal sign in flow.
  virtual void UserLoggedIn(const std::string& email, bool browser_restart) = 0;

  // Indicates that user just logged on as the demo user.
  virtual void DemoUserLoggedIn() = 0;

  // Indicates that user just started incognito session.
  virtual void GuestUserLoggedIn() = 0;

  // Indicates that a user just logged in as ephemeral.
  virtual void EphemeralUserLoggedIn(const std::string& email) = 0;

  // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
  // in, uses a solid color wallpaper. If logged in as a stub user, uses an
  // empty wallpaper.
  virtual void InitializeWallpaper() = 0;

  // Called when user pod with |email| is selected.
  virtual void UserSelected(const std::string& email) = 0;

  // Called when browser session is started i.e. after
  // browser_creator.LaunchBrowser(...) was called after user sign in.
  // When user is at the image screen IsUserLoggedIn() will return true
  // but SessionStarted() will return false.
  // Fires NOTIFICATION_SESSION_STARTED.
  virtual void SessionStarted() = 0;

  // Removes the user from the device. Note, it will verify that the given user
  // isn't the owner, so calling this method for the owner will take no effect.
  // Note, |delegate| can be NULL.
  virtual void RemoveUser(const std::string& email,
                          RemoveUserDelegate* delegate) = 0;

  // Removes the user from the persistent list only. Also removes the user's
  // picture.
  virtual void RemoveUserFromList(const std::string& email) = 0;

  // Returns true if a user with the given email address is found in the
  // persistent list or currently logged in as ephemeral.
  virtual bool IsKnownUser(const std::string& email) const = 0;

  // Returns the user with the given email address if found in the persistent
  // list or currently logged in as ephemeral. Returns |NULL| otherwise.
  virtual const User* FindUser(const std::string& email) const = 0;

  // Returns the logged-in user.
  virtual const User& GetLoggedInUser() const = 0;
  virtual User& GetLoggedInUser() = 0;

  // Saves user's oauth token status in local state preferences.
  virtual void SaveUserOAuthStatus(
      const std::string& username,
      User::OAuthTokenStatus oauth_token_status) = 0;

  // Saves user's displayed name in local state preferences.
  // Ignored If there is no such user.
  virtual void SaveUserDisplayName(const std::string& username,
                                   const string16& display_name) = 0;

  // Returns the display name for user |username| if it is known (was
  // previously set by a |SaveUserDisplayName| call).
  // Otherwise, returns an empty string.
  virtual string16 GetUserDisplayName(
      const std::string& username) const = 0;

  // Saves user's displayed (non-canonical) email in local state preferences.
  // Ignored If there is no such user.
  virtual void SaveUserDisplayEmail(const std::string& username,
                                    const std::string& display_email) = 0;

  // Returns the display email for user |username| if it is known (was
  // previously set by a |SaveUserDisplayEmail| call).
  // Otherwise, returns |username| itself.
  virtual std::string GetUserDisplayEmail(
      const std::string& username) const = 0;

  // Sets |type| and |index| to the value saved in local state for logged in
  // user.
  virtual void GetLoggedInUserWallpaperProperties(User::WallpaperType* type,
                                                  int* index) = 0;

  // Saves |type| and |index| chose by logged in user to Local State.
  virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type,
                                                   int index) = 0;

  // Sets user image to the default image with index |image_index|, sends
  // LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
  virtual void SaveUserDefaultImageIndex(const std::string& username,
                                         int image_index) = 0;

  // Saves image to file, sends LOGIN_USER_IMAGE_CHANGED notification and
  // updates Local State.
  virtual void SaveUserImage(const std::string& username,
                             const UserImage& user_image) = 0;

  // Updates custom wallpaper to selected layout and saves layout to Local
  // State.
  virtual void SetLoggedInUserCustomWallpaperLayout(
      ash::WallpaperLayout layout) = 0;

  // Tries to load user image from disk; if successful, sets it for the user,
  // sends LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
  virtual void SaveUserImageFromFile(const std::string& username,
                                     const FilePath& path) = 0;

  // Tries to load user image from disk; if successful, sets it for the user,
  // and updates Local State.
  virtual void SaveUserWallpaperFromFile(
      const std::string& username,
      const FilePath& path,
      ash::WallpaperLayout layout,
      base::WeakPtr<WallpaperDelegate> delegate) = 0;

  // Sets profile image as user image for |username|, sends
  // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If the user
  // is not logged-in or the last |DownloadProfileImage| call has failed, a
  // default grey avatar will be used until the user logs in and profile image
  // is downloaded successfully.
  virtual void SaveUserImageFromProfileImage(const std::string& username) = 0;

  // Starts downloading the profile image for the logged-in user.
  // If user's image index is |kProfileImageIndex|, newly downloaded image
  // is immediately set as user's current picture.
  // |reason| is an arbitrary string (used to report UMA histograms with
  // download times).
  virtual void DownloadProfileImage(const std::string& reason) = 0;

  // Returns true if current user is an owner.
  virtual bool IsCurrentUserOwner() const = 0;

  // Returns true if current user is not existing one (hasn't signed in before).
  virtual bool IsCurrentUserNew() const = 0;

  // Returns true if the current user is ephemeral.
  virtual bool IsCurrentUserEphemeral() const = 0;

  // Returns true if user is signed in.
  virtual bool IsUserLoggedIn() const = 0;

  // Returns true if we're logged in as a demo user.
  virtual bool IsLoggedInAsDemoUser() const = 0;

  // Returns true if we're logged in as a Guest.
  virtual bool IsLoggedInAsGuest() const = 0;

  // Returns true if we're logged in as the stub user used for testing on Linux.
  virtual bool IsLoggedInAsStub() const = 0;

  // Returns true if we're logged in and browser has been started i.e.
  // browser_creator.LaunchBrowser(...) was called after sign in
  // or restart after crash.
  virtual bool IsSessionStarted() const = 0;

  virtual void AddObserver(Observer* obs) = 0;
  virtual void RemoveObserver(Observer* obs) = 0;

  virtual void NotifyLocalStateChanged() = 0;

  // Returns the result of the last successful profile image download, if any.
  // Otherwise, returns an empty bitmap.
  virtual const SkBitmap& DownloadedProfileImage() const = 0;
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_