OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/chromeos/login/profile_image_downloader.h" | |
18 #include "chrome/browser/chromeos/login/user.h" | 17 #include "chrome/browser/chromeos/login/user.h" |
19 #include "chrome/browser/chromeos/login/user_image_loader.h" | 18 #include "chrome/browser/chromeos/login/user_image_loader.h" |
| 19 #include "chrome/browser/gaia_userinfo/profile_downloader_delegate.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
23 | 23 |
24 class FilePath; | 24 class FilePath; |
25 class PrefService; | 25 class PrefService; |
| 26 class ProfileDownloader; |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 template<typename> struct DefaultLazyInstanceTraits; | 29 template<typename> struct DefaultLazyInstanceTraits; |
29 } | 30 } |
30 | 31 |
31 namespace chromeos { | 32 namespace chromeos { |
32 | 33 |
33 class RemoveUserDelegate; | 34 class RemoveUserDelegate; |
34 | 35 |
35 // This class provides a mechanism for discovering users who have logged | 36 // This class provides a mechanism for discovering users who have logged |
36 // into this chromium os device before and updating that list. | 37 // into this chromium os device before and updating that list. |
37 class UserManager : public ProfileImageDownloader::Delegate, | 38 class UserManager : public ProfileDownloaderDelegate, |
38 public content::NotificationObserver { | 39 public content::NotificationObserver { |
39 public: | 40 public: |
40 // Returns a shared instance of a UserManager. Not thread-safe, should only be | 41 // Returns a shared instance of a UserManager. Not thread-safe, should only be |
41 // called from the main UI thread. | 42 // called from the main UI thread. |
42 static UserManager* Get(); | 43 static UserManager* Get(); |
43 | 44 |
44 // Registers user manager preferences. | 45 // Registers user manager preferences. |
45 static void RegisterPrefs(PrefService* local_state); | 46 static void RegisterPrefs(PrefService* local_state); |
46 | 47 |
47 // Returns a list of the users who have logged into this device previously. | 48 // Returns a list of the users who have logged into this device previously. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 207 |
207 // Deletes user's image file. Runs on FILE thread. | 208 // Deletes user's image file. Runs on FILE thread. |
208 void DeleteUserImage(const FilePath& image_path); | 209 void DeleteUserImage(const FilePath& image_path); |
209 | 210 |
210 // Updates current user ownership on UI thread. | 211 // Updates current user ownership on UI thread. |
211 void UpdateOwnership(bool is_owner); | 212 void UpdateOwnership(bool is_owner); |
212 | 213 |
213 // Checks current user's ownership on file thread. | 214 // Checks current user's ownership on file thread. |
214 void CheckOwnership(); | 215 void CheckOwnership(); |
215 | 216 |
216 // ProfileImageDownloader::Delegate implementation. | 217 // ProfileDownloaderDelegate implementation. |
217 virtual void OnDownloadSuccess(const SkBitmap& image) OVERRIDE; | 218 virtual int GetDesiredImageSize() OVERRIDE; |
| 219 virtual std::string GetProfileUserName() OVERRIDE; |
| 220 virtual Profile* GetBrowserProfile() OVERRIDE; |
| 221 virtual void OnDownloadSuccess(const string16& full_name, |
| 222 const SkBitmap& image) OVERRIDE; |
218 virtual void OnDownloadFailure() OVERRIDE; | 223 virtual void OnDownloadFailure() OVERRIDE; |
219 virtual void OnDownloadDefaultImage() OVERRIDE; | 224 virtual void OnDownloadDefaultImage(const string16& full_name) OVERRIDE; |
220 | 225 |
221 // Creates a new User instance. | 226 // Creates a new User instance. |
222 User* CreateUser(const std::string& email) const; | 227 User* CreateUser(const std::string& email) const; |
223 | 228 |
224 // Loads user image from its file. | 229 // Loads user image from its file. |
225 scoped_refptr<UserImageLoader> image_loader_; | 230 scoped_refptr<UserImageLoader> image_loader_; |
226 | 231 |
227 // List of all known users. User instances are owned by |this| and deleted | 232 // List of all known users. User instances are owned by |this| and deleted |
228 // when a user is removed with |RemoveUser|. | 233 // when a user is removed with |RemoveUser|. |
229 mutable UserList users_; | 234 mutable UserList users_; |
(...skipping 28 matching lines...) Expand all Loading... |
258 // Cached flag of whether any user is logged in at the moment. | 263 // Cached flag of whether any user is logged in at the moment. |
259 bool user_is_logged_in_; | 264 bool user_is_logged_in_; |
260 | 265 |
261 content::NotificationRegistrar registrar_; | 266 content::NotificationRegistrar registrar_; |
262 | 267 |
263 friend struct base::DefaultLazyInstanceTraits<UserManager>; | 268 friend struct base::DefaultLazyInstanceTraits<UserManager>; |
264 | 269 |
265 ObserverList<Observer> observer_list_; | 270 ObserverList<Observer> observer_list_; |
266 | 271 |
267 // Download user profile image on login to update it if it's changed. | 272 // Download user profile image on login to update it if it's changed. |
268 scoped_ptr<ProfileImageDownloader> profile_image_downloader_; | 273 scoped_ptr<ProfileDownloader> profile_image_downloader_; |
269 | 274 |
270 // Time when the profile image download has started. | 275 // Time when the profile image download has started. |
271 base::Time profile_image_load_start_time_; | 276 base::Time profile_image_load_start_time_; |
272 | 277 |
273 // True if the last user image required async save operation (which may not | 278 // True if the last user image required async save operation (which may not |
274 // have been completed yet). This flag is used to avoid races when user image | 279 // have been completed yet). This flag is used to avoid races when user image |
275 // is first set with |SaveUserImage| and then with |SaveUserImagePath|. | 280 // is first set with |SaveUserImage| and then with |SaveUserImagePath|. |
276 bool last_image_set_async_; | 281 bool last_image_set_async_; |
277 | 282 |
278 // Result of the last successful profile image download, if any. | 283 // Result of the last successful profile image download, if any. |
279 SkBitmap downloaded_profile_image_; | 284 SkBitmap downloaded_profile_image_; |
280 | 285 |
281 // Data URL for |downloaded_profile_image_|. | 286 // Data URL for |downloaded_profile_image_|. |
282 std::string downloaded_profile_image_data_url_; | 287 std::string downloaded_profile_image_data_url_; |
283 | 288 |
284 DISALLOW_COPY_AND_ASSIGN(UserManager); | 289 DISALLOW_COPY_AND_ASSIGN(UserManager); |
285 }; | 290 }; |
286 | 291 |
287 } // namespace chromeos | 292 } // namespace chromeos |
288 | 293 |
289 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 294 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
OLD | NEW |