OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
15 #include "chrome/browser/chromeos/login/user_image_loader.h" | 15 #include "chrome/browser/chromeos/login/user_image_loader.h" |
16 #include "chrome/common/notification_observer.h" | 16 #include "chrome/common/notification_observer.h" |
17 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 | 19 |
| 20 class FilePath; |
20 class PrefService; | 21 class PrefService; |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 // This class provides a mechanism for discovering users who have logged | 25 // This class provides a mechanism for discovering users who have logged |
25 // into this chromium os device before and updating that list. | 26 // into this chromium os device before and updating that list. |
26 class UserManager : public UserImageLoader::Delegate, | 27 class UserManager : public UserImageLoader::Delegate, |
27 public NotificationObserver { | 28 public NotificationObserver { |
28 public: | 29 public: |
29 // A class representing information about a previously logged in user. | 30 // A class representing information about a previously logged in user. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 virtual const User& logged_in_user() { | 77 virtual const User& logged_in_user() { |
77 return logged_in_user_; | 78 return logged_in_user_; |
78 } | 79 } |
79 | 80 |
80 // Sets image for logged-in user and sends LOGIN_USER_IMAGE_CHANGED | 81 // Sets image for logged-in user and sends LOGIN_USER_IMAGE_CHANGED |
81 // notification about the image changed via NotificationService. | 82 // notification about the image changed via NotificationService. |
82 void SetLoggedInUserImage(const SkBitmap& image); | 83 void SetLoggedInUserImage(const SkBitmap& image); |
83 | 84 |
84 // Saves image to file and saves image path in local state preferences. | 85 // Saves image to file and saves image path in local state preferences. |
85 void SaveUserImage(const std::string& username, | 86 void SaveUserImage(const std::string& username, |
86 const SkBitmap& image); | 87 const SkBitmap& image); |
87 | 88 |
88 // Sets one of the default images to the specified user and saves this | 89 // Sets one of the default images to the specified user and saves this |
89 // setting in local state. | 90 // setting in local state. |
90 void SetDefaultUserImage(const std::string& username); | 91 void SetDefaultUserImage(const std::string& username); |
91 | 92 |
92 // chromeos::UserImageLoader::Delegate implementation. | 93 // chromeos::UserImageLoader::Delegate implementation. |
93 virtual void OnImageLoaded(const std::string& username, | 94 virtual void OnImageLoaded(const std::string& username, |
94 const SkBitmap& image); | 95 const SkBitmap& image); |
95 | 96 |
96 // NotificationObserver implementation. | 97 // NotificationObserver implementation. |
97 virtual void Observe(NotificationType type, | 98 virtual void Observe(NotificationType type, |
98 const NotificationSource& source, | 99 const NotificationSource& source, |
99 const NotificationDetails& details); | 100 const NotificationDetails& details); |
100 | 101 |
101 // Accessor for current_user_is_owner_ | 102 // Accessor for current_user_is_owner_ |
102 virtual bool current_user_is_owner() const { | 103 virtual bool current_user_is_owner() const { |
103 return current_user_is_owner_; | 104 return current_user_is_owner_; |
104 } | 105 } |
105 virtual void set_current_user_is_owner(bool current_user_is_owner) { | 106 virtual void set_current_user_is_owner(bool current_user_is_owner) { |
106 current_user_is_owner_ = current_user_is_owner; | 107 current_user_is_owner_ = current_user_is_owner; |
107 } | 108 } |
108 | 109 |
109 protected: | 110 protected: |
110 UserManager(); | 111 UserManager(); |
111 virtual ~UserManager(); | 112 virtual ~UserManager(); |
112 | 113 |
| 114 // Returns image filepath for the given user. |
| 115 FilePath GetImagePathForUser(const std::string& username); |
| 116 |
113 private: | 117 private: |
114 // Notifies on new user session. | 118 // Notifies on new user session. |
115 void NotifyOnLogin(); | 119 void NotifyOnLogin(); |
116 | 120 |
117 // Loads user image from its file. | 121 // Loads user image from its file. |
118 scoped_refptr<UserImageLoader> image_loader_; | 122 scoped_refptr<UserImageLoader> image_loader_; |
119 | 123 |
120 // Cache for user images. Stores image for each username. | 124 // Cache for user images. Stores image for each username. |
121 typedef base::hash_map<std::string, SkBitmap> UserImages; | 125 typedef base::hash_map<std::string, SkBitmap> UserImages; |
122 mutable UserImages user_images_; | 126 mutable UserImages user_images_; |
123 | 127 |
124 // The logged-in user. | 128 // The logged-in user. |
125 User logged_in_user_; | 129 User logged_in_user_; |
126 | 130 |
127 // Cached flag of whether currently logged-in user is owner or not. | 131 // Cached flag of whether currently logged-in user is owner or not. |
128 bool current_user_is_owner_; | 132 bool current_user_is_owner_; |
129 | 133 |
130 NotificationRegistrar registrar_; | 134 NotificationRegistrar registrar_; |
131 | 135 |
132 DISALLOW_COPY_AND_ASSIGN(UserManager); | 136 DISALLOW_COPY_AND_ASSIGN(UserManager); |
133 }; | 137 }; |
134 | 138 |
135 } // namespace chromeos | 139 } // namespace chromeos |
136 | 140 |
137 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ | 141 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_MANAGER_H_ |
OLD | NEW |