OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | |
9 | |
10 #include <deque> | |
11 #include <memory> | 8 #include <memory> |
12 #include <string> | 9 #include <string> |
13 #include <vector> | 10 #include <vector> |
14 | 11 |
15 #include "base/files/file_path.h" | 12 #include "ash/public/interfaces/wallpaper.mojom.h" |
16 #include "base/macros.h" | 13 #include "base/macros.h" |
17 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
18 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | |
20 #include "base/threading/sequenced_worker_pool.h" | |
21 #include "base/time/time.h" | |
22 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" | |
23 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
24 #include "components/user_manager/user.h" | 17 #include "components/user_manager/user.h" |
25 #include "components/user_manager/user_image/user_image.h" | 18 #include "components/user_manager/user_image/user_image.h" |
26 #include "components/user_manager/user_manager.h" | 19 #include "components/user_manager/user_manager.h" |
27 #include "components/wallpaper/wallpaper_layout.h" | 20 #include "components/wallpaper/wallpaper_layout.h" |
28 #include "components/wallpaper/wallpaper_manager_base.h" | 21 #include "components/wallpaper/wallpaper_manager_base.h" |
29 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
30 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "mojo/public/cpp/bindings/binding_set.h" |
31 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
32 | 26 |
33 namespace chromeos { | 27 namespace chromeos { |
34 | 28 |
35 class WallpaperManager | 29 class WallpaperManager |
36 : public wallpaper::WallpaperManagerBase, | 30 : public wallpaper::WallpaperManagerBase, |
| 31 public ash::mojom::WallpaperManager, |
37 public content::NotificationObserver, | 32 public content::NotificationObserver, |
38 public user_manager::UserManager::UserSessionStateObserver { | 33 public user_manager::UserManager::UserSessionStateObserver { |
39 public: | 34 public: |
40 class PendingWallpaper; | 35 class PendingWallpaper; |
41 | 36 |
42 ~WallpaperManager() override; | 37 ~WallpaperManager() override; |
43 | 38 |
44 // Creates an instance of Wallpaper Manager. If there is no instance, create | 39 // Creates an instance of Wallpaper Manager. If there is no instance, create |
45 // one. Otherwise, returns the existing instance. | 40 // one. Otherwise, returns the existing instance. |
46 static void Initialize(); | 41 static void Initialize(); |
47 | 42 |
48 // Gets pointer to singleton WallpaperManager instance. | 43 // Gets pointer to singleton WallpaperManager instance. |
49 static WallpaperManager* Get(); | 44 static WallpaperManager* Get(); |
50 | 45 |
51 // Deletes the existing instance of WallpaperManager. Allows the | 46 // Deletes the existing instance of WallpaperManager. Allows the |
52 // WallpaperManager to remove any observers it has registered. | 47 // WallpaperManager to remove any observers it has registered. |
53 static void Shutdown(); | 48 static void Shutdown(); |
54 | 49 |
55 // Returns the appropriate wallpaper resolution for all root windows. | 50 // Binds the mojom::WallpaperManager interface request to this object. |
| 51 void BindRequest(ash::mojom::WallpaperManagerRequest request); |
| 52 |
| 53 // wallpaper::WallpaperManagerBase: |
56 WallpaperResolution GetAppropriateResolution() override; | 54 WallpaperResolution GetAppropriateResolution() override; |
57 | |
58 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | |
59 void AddObservers() override; | 55 void AddObservers() override; |
60 | |
61 // Loads wallpaper asynchronously if the current wallpaper is not the | |
62 // wallpaper of logged in user. | |
63 void EnsureLoggedInUserWallpaperLoaded() override; | 56 void EnsureLoggedInUserWallpaperLoaded() override; |
64 | |
65 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged | |
66 // in, uses a solid color wallpaper. If logged in as a stub user, uses an | |
67 // empty wallpaper. | |
68 void InitializeWallpaper() override; | 57 void InitializeWallpaper() override; |
69 | |
70 // NotificationObserver overrides: | |
71 void Observe(int type, | |
72 const content::NotificationSource& source, | |
73 const content::NotificationDetails& details) override; | |
74 | |
75 // Removes all |account_id| related wallpaper info and saved wallpapers. | |
76 void RemoveUserWallpaperInfo(const AccountId& account_id) override; | 58 void RemoveUserWallpaperInfo(const AccountId& account_id) override; |
77 | |
78 // Called when the policy-set wallpaper has been fetched. Initiates decoding | |
79 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | |
80 void OnPolicyFetched(const std::string& policy, | 59 void OnPolicyFetched(const std::string& policy, |
81 const AccountId& account_id, | 60 const AccountId& account_id, |
82 std::unique_ptr<std::string> data) override; | 61 std::unique_ptr<std::string> data) override; |
83 | |
84 // Saves custom wallpaper to file, post task to generate thumbnail and updates | |
85 // local state preferences. If |update_wallpaper| is false, don't change | |
86 // wallpaper but only update cache. | |
87 void SetCustomWallpaper(const AccountId& account_id, | 62 void SetCustomWallpaper(const AccountId& account_id, |
88 const wallpaper::WallpaperFilesId& wallpaper_files_id, | 63 const wallpaper::WallpaperFilesId& wallpaper_files_id, |
89 const std::string& file, | 64 const std::string& file, |
90 wallpaper::WallpaperLayout layout, | 65 wallpaper::WallpaperLayout layout, |
91 user_manager::User::WallpaperType type, | 66 user_manager::User::WallpaperType type, |
92 const gfx::ImageSkia& image, | 67 const gfx::ImageSkia& image, |
93 bool update_wallpaper) override; | 68 bool update_wallpaper) override; |
94 | |
95 // Sets wallpaper to default wallpaper (asynchronously with zero delay). | |
96 void SetDefaultWallpaperNow(const AccountId& account_id) override; | 69 void SetDefaultWallpaperNow(const AccountId& account_id) override; |
97 | |
98 // Sets wallpaper to default wallpaper (asynchronously with default delay). | |
99 void SetDefaultWallpaperDelayed(const AccountId& account_id) override; | 70 void SetDefaultWallpaperDelayed(const AccountId& account_id) override; |
100 | |
101 // Sets wallpaper to default. | |
102 void DoSetDefaultWallpaper( | 71 void DoSetDefaultWallpaper( |
103 const AccountId& account_id, | 72 const AccountId& account_id, |
104 wallpaper::MovableOnDestroyCallbackHolder on_finish) override; | 73 wallpaper::MovableOnDestroyCallbackHolder on_finish) override; |
105 | |
106 // Sets selected wallpaper information for |account_id| and saves it to Local | |
107 // State if |is_persistent| is true. | |
108 void SetUserWallpaperInfo(const AccountId& account_id, | 74 void SetUserWallpaperInfo(const AccountId& account_id, |
109 const wallpaper::WallpaperInfo& info, | 75 const wallpaper::WallpaperInfo& info, |
110 bool is_persistent) override; | 76 bool is_persistent) override; |
111 | |
112 // Creates new PendingWallpaper request (or updates currently pending). | |
113 void ScheduleSetUserWallpaper(const AccountId& account_id, | 77 void ScheduleSetUserWallpaper(const AccountId& account_id, |
114 bool delayed) override; | 78 bool delayed) override; |
115 | |
116 // Sets wallpaper to |image| (asynchronously with zero delay). If | |
117 // |update_wallpaper| is false, skip change wallpaper but only update cache. | |
118 void SetWallpaperFromImageSkia(const AccountId& account_id, | 79 void SetWallpaperFromImageSkia(const AccountId& account_id, |
119 const gfx::ImageSkia& image, | 80 const gfx::ImageSkia& image, |
120 wallpaper::WallpaperLayout layout, | 81 wallpaper::WallpaperLayout layout, |
121 bool update_wallpaper) override; | 82 bool update_wallpaper) override; |
122 | |
123 // Updates current wallpaper. It may switch the size of wallpaper based on the | |
124 // current display's resolution. (asynchronously with zero delay) | |
125 void UpdateWallpaper(bool clear_cache) override; | 83 void UpdateWallpaper(bool clear_cache) override; |
126 | |
127 // Returns queue size. | |
128 size_t GetPendingListSizeForTesting() const override; | 84 size_t GetPendingListSizeForTesting() const override; |
129 | |
130 // Returns wallpaper files id for the |account_id|. | |
131 wallpaper::WallpaperFilesId GetFilesId( | 85 wallpaper::WallpaperFilesId GetFilesId( |
132 const AccountId& account_id) const override; | 86 const AccountId& account_id) const override; |
133 | 87 |
134 // Overridden from user_manager::UserManager::UserSessionStateObserver: | 88 // ash::mojom::WallpaperManager: |
| 89 void Open() override; |
| 90 |
| 91 // content::NotificationObserver: |
| 92 void Observe(int type, |
| 93 const content::NotificationSource& source, |
| 94 const content::NotificationDetails& details) override; |
| 95 |
| 96 // user_manager::UserManager::UserSessionStateObserver: |
135 void UserChangedChildStatus(user_manager::User* user) override; | 97 void UserChangedChildStatus(user_manager::User* user) override; |
136 | 98 |
137 private: | 99 private: |
138 friend class TestApi; | 100 friend class TestApi; |
139 friend class WallpaperManagerBrowserTest; | 101 friend class WallpaperManagerBrowserTest; |
140 friend class WallpaperManagerBrowserTestDefaultWallpaper; | 102 friend class WallpaperManagerBrowserTestDefaultWallpaper; |
141 friend class WallpaperManagerPolicyTest; | 103 friend class WallpaperManagerPolicyTest; |
142 | 104 |
143 WallpaperManager(); | 105 WallpaperManager(); |
144 | 106 |
145 // Returns modifiable PendingWallpaper. | 107 // Returns modifiable PendingWallpaper. |
146 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. | 108 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. |
147 PendingWallpaper* GetPendingWallpaper(const AccountId& account_id, | 109 PendingWallpaper* GetPendingWallpaper(const AccountId& account_id, |
148 bool delayed); | 110 bool delayed); |
149 | 111 |
150 // This is called by PendingWallpaper when load is finished. | 112 // This is called by PendingWallpaper when load is finished. |
151 void RemovePendingWallpaperFromList(PendingWallpaper* pending); | 113 void RemovePendingWallpaperFromList(PendingWallpaper* pending); |
152 | 114 |
153 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage | 115 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage |
154 // because that's the callback interface provided by UserImageLoader.) | 116 // because that's the callback interface provided by UserImageLoader.) |
155 void SetPolicyControlledWallpaper( | 117 void SetPolicyControlledWallpaper( |
156 const AccountId& account_id, | 118 const AccountId& account_id, |
157 std::unique_ptr<user_manager::UserImage> user_image); | 119 std::unique_ptr<user_manager::UserImage> user_image); |
158 | 120 |
159 // WallpaperManagerBase overrides: | 121 // wallpaper::WallpaperManagerBase: |
160 void InitializeRegisteredDeviceWallpaper() override; | 122 void InitializeRegisteredDeviceWallpaper() override; |
161 bool GetUserWallpaperInfo(const AccountId& account_id, | 123 bool GetUserWallpaperInfo(const AccountId& account_id, |
162 wallpaper::WallpaperInfo* info) const override; | 124 wallpaper::WallpaperInfo* info) const override; |
163 void OnWallpaperDecoded( | 125 void OnWallpaperDecoded( |
164 const AccountId& account_id, | 126 const AccountId& account_id, |
165 wallpaper::WallpaperLayout layout, | 127 wallpaper::WallpaperLayout layout, |
166 bool update_wallpaper, | 128 bool update_wallpaper, |
167 wallpaper::MovableOnDestroyCallbackHolder on_finish, | 129 wallpaper::MovableOnDestroyCallbackHolder on_finish, |
168 std::unique_ptr<user_manager::UserImage> user_image) override; | 130 std::unique_ptr<user_manager::UserImage> user_image) override; |
169 void StartLoad(const AccountId& account_id, | 131 void StartLoad(const AccountId& account_id, |
(...skipping 24 matching lines...) Expand all Loading... |
194 const base::FilePath& path, | 156 const base::FilePath& path, |
195 const wallpaper::WallpaperLayout layout, | 157 const wallpaper::WallpaperLayout layout, |
196 wallpaper::MovableOnDestroyCallbackHolder on_finish, | 158 wallpaper::MovableOnDestroyCallbackHolder on_finish, |
197 std::unique_ptr<user_manager::UserImage>* result_out) override; | 159 std::unique_ptr<user_manager::UserImage>* result_out) override; |
198 void SetDefaultWallpaperPath( | 160 void SetDefaultWallpaperPath( |
199 const base::FilePath& customized_default_wallpaper_file_small, | 161 const base::FilePath& customized_default_wallpaper_file_small, |
200 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, | 162 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
201 const base::FilePath& customized_default_wallpaper_file_large, | 163 const base::FilePath& customized_default_wallpaper_file_large, |
202 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) override; | 164 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) override; |
203 | 165 |
| 166 mojo::BindingSet<ash::mojom::WallpaperManager> bindings_; |
| 167 |
204 std::unique_ptr<CrosSettings::ObserverSubscription> | 168 std::unique_ptr<CrosSettings::ObserverSubscription> |
205 show_user_name_on_signin_subscription_; | 169 show_user_name_on_signin_subscription_; |
206 | 170 |
207 // Pointer to last inactive (waiting) entry of 'loading_' list. | 171 // Pointer to last inactive (waiting) entry of 'loading_' list. |
208 // NULL when there is no inactive request. | 172 // NULL when there is no inactive request. |
209 PendingWallpaper* pending_inactive_; | 173 PendingWallpaper* pending_inactive_; |
210 | 174 |
211 // Owns PendingWallpaper. | 175 // Owns PendingWallpaper. |
212 // PendingWallpaper deletes itself from here on load complete. | 176 // PendingWallpaper deletes itself from here on load complete. |
213 // All pending will be finally deleted on destroy. | 177 // All pending will be finally deleted on destroy. |
214 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 178 typedef std::vector<scoped_refptr<PendingWallpaper>> PendingList; |
215 PendingList loading_; | 179 PendingList loading_; |
216 | 180 |
217 content::NotificationRegistrar registrar_; | 181 content::NotificationRegistrar registrar_; |
218 | 182 |
219 base::WeakPtrFactory<WallpaperManager> weak_factory_; | 183 base::WeakPtrFactory<WallpaperManager> weak_factory_; |
| 184 |
220 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 185 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
221 }; | 186 }; |
222 | 187 |
223 } // namespace chromeos | 188 } // namespace chromeos |
224 | 189 |
225 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 190 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
OLD | NEW |