Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h

Issue 2931063004: Extract colors from wallpaper and dynamically update login screen overlay (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "ash/public/interfaces/wallpaper.mojom.h" 12 #include "ash/public/interfaces/wallpaper.mojom.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/scoped_observer.h" 16 #include "base/scoped_observer.h"
17 #include "chrome/browser/chromeos/customization/customization_wallpaper_download er.h" 17 #include "chrome/browser/chromeos/customization/customization_wallpaper_download er.h"
18 #include "chrome/browser/chromeos/settings/cros_settings.h" 18 #include "chrome/browser/chromeos/settings/cros_settings.h"
19 #include "components/user_manager/user.h" 19 #include "components/user_manager/user.h"
20 #include "components/user_manager/user_image/user_image.h" 20 #include "components/user_manager/user_image/user_image.h"
21 #include "components/user_manager/user_manager.h" 21 #include "components/user_manager/user_manager.h"
22 #include "components/wallpaper/wallpaper_color_calculator.h"
23 #include "components/wallpaper/wallpaper_color_calculator_observer.h"
22 #include "components/wallpaper/wallpaper_layout.h" 24 #include "components/wallpaper/wallpaper_layout.h"
23 #include "components/wallpaper/wallpaper_manager_base.h" 25 #include "components/wallpaper/wallpaper_manager_base.h"
24 #include "content/public/browser/notification_observer.h" 26 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h" 27 #include "content/public/browser/notification_registrar.h"
26 #include "mojo/public/cpp/bindings/binding.h" 28 #include "mojo/public/cpp/bindings/binding.h"
27 #include "ui/aura/window_observer.h" 29 #include "ui/aura/window_observer.h"
28 #include "ui/gfx/image/image_skia.h" 30 #include "ui/gfx/image/image_skia.h"
29 #include "ui/wm/public/activation_change_observer.h" 31 #include "ui/wm/public/activation_change_observer.h"
30 #include "ui/wm/public/activation_client.h" 32 #include "ui/wm/public/activation_client.h"
31 33
32 namespace chromeos { 34 namespace chromeos {
33 35
34 class WallpaperManager 36 class WallpaperManager
35 : public wallpaper::WallpaperManagerBase, 37 : public wallpaper::WallpaperManagerBase,
36 public ash::mojom::WallpaperPicker, 38 public ash::mojom::WallpaperPicker,
37 public content::NotificationObserver, 39 public content::NotificationObserver,
38 public user_manager::UserManager::UserSessionStateObserver, 40 public user_manager::UserManager::UserSessionStateObserver,
39 public wm::ActivationChangeObserver, 41 public wm::ActivationChangeObserver,
40 public aura::WindowObserver { 42 public aura::WindowObserver,
43 public wallpaper::WallpaperColorCalculatorObserver {
41 public: 44 public:
42 class PendingWallpaper; 45 class PendingWallpaper;
43 46
44 ~WallpaperManager() override; 47 ~WallpaperManager() override;
45 48
46 // Creates an instance of Wallpaper Manager. If there is no instance, create 49 // Creates an instance of Wallpaper Manager. If there is no instance, create
47 // one. Otherwise, returns the existing instance. 50 // one. Otherwise, returns the existing instance.
48 static void Initialize(); 51 static void Initialize();
49 52
50 // Gets pointer to singleton WallpaperManager instance. 53 // Gets pointer to singleton WallpaperManager instance.
51 static WallpaperManager* Get(); 54 static WallpaperManager* Get();
52 55
53 // Deletes the existing instance of WallpaperManager. Allows the 56 // Deletes the existing instance of WallpaperManager. Allows the
54 // WallpaperManager to remove any observers it has registered. 57 // WallpaperManager to remove any observers it has registered.
55 static void Shutdown(); 58 static void Shutdown();
56 59
57 // Returns if the image is in the pending list. |image_id| can be obtained 60 // Returns if the image is in the pending list. |image_id| can be obtained
58 // from gfx::ImageSkia by using WallpaperResizer::GetImageId(). 61 // from gfx::ImageSkia by using WallpaperResizer::GetImageId().
59 bool IsPendingWallpaper(uint32_t image_id); 62 bool IsPendingWallpaper(uint32_t image_id);
60 63
64 // Calculates a prominent color based on the wallpaper image and notifies
65 // |observers_| of the value. An existing calculation in progress (if any)
66 // will be destroyed first.
67 void CalculateProminentColor(const gfx::ImageSkia& image);
68
69 SkColor prominent_color() const { return prominent_color_; }
70
61 // wallpaper::WallpaperManagerBase: 71 // wallpaper::WallpaperManagerBase:
62 WallpaperResolution GetAppropriateResolution() override; 72 WallpaperResolution GetAppropriateResolution() override;
63 void AddObservers() override; 73 void AddObservers() override;
64 void EnsureLoggedInUserWallpaperLoaded() override; 74 void EnsureLoggedInUserWallpaperLoaded() override;
65 void InitializeWallpaper() override; 75 void InitializeWallpaper() override;
66 void RemoveUserWallpaperInfo(const AccountId& account_id) override; 76 void RemoveUserWallpaperInfo(const AccountId& account_id) override;
67 void OnPolicyFetched(const std::string& policy, 77 void OnPolicyFetched(const std::string& policy,
68 const AccountId& account_id, 78 const AccountId& account_id,
69 std::unique_ptr<std::string> data) override; 79 std::unique_ptr<std::string> data) override;
70 void SetCustomWallpaper(const AccountId& account_id, 80 void SetCustomWallpaper(const AccountId& account_id,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void UserChangedChildStatus(user_manager::User* user) override; 116 void UserChangedChildStatus(user_manager::User* user) override;
107 117
108 // wm::ActivationChangeObserver: 118 // wm::ActivationChangeObserver:
109 void OnWindowActivated(ActivationReason reason, 119 void OnWindowActivated(ActivationReason reason,
110 aura::Window* gained_active, 120 aura::Window* gained_active,
111 aura::Window* lost_active) override; 121 aura::Window* lost_active) override;
112 122
113 // aura::WindowObserver: 123 // aura::WindowObserver:
114 void OnWindowDestroying(aura::Window* window) override; 124 void OnWindowDestroying(aura::Window* window) override;
115 125
126 // wallpaper::WallpaperColorCalculatorObserver:
127 void OnColorCalculationComplete() override;
128
116 private: 129 private:
117 friend class TestApi; 130 friend class TestApi;
118 friend class WallpaperManagerBrowserTest; 131 friend class WallpaperManagerBrowserTest;
119 friend class WallpaperManagerBrowserTestDefaultWallpaper; 132 friend class WallpaperManagerBrowserTestDefaultWallpaper;
120 friend class WallpaperManagerPolicyTest; 133 friend class WallpaperManagerPolicyTest;
121 134
122 WallpaperManager(); 135 WallpaperManager();
123 136
124 // Returns modifiable PendingWallpaper. 137 // Returns modifiable PendingWallpaper.
125 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. 138 // Returns pending_inactive_ or creates new PendingWallpaper if necessary.
(...skipping 26 matching lines...) Expand all
152 // device wallpaper policy setting. 165 // device wallpaper policy setting.
153 void OnCheckDeviceWallpaperMatchHash(const AccountId& account_id, 166 void OnCheckDeviceWallpaperMatchHash(const AccountId& account_id,
154 const std::string& url, 167 const std::string& url,
155 const std::string& hash, 168 const std::string& hash,
156 bool match); 169 bool match);
157 // This is called when the device wallpaper is decoded successfully. 170 // This is called when the device wallpaper is decoded successfully.
158 void OnDeviceWallpaperDecoded( 171 void OnDeviceWallpaperDecoded(
159 const AccountId& account_id, 172 const AccountId& account_id,
160 std::unique_ptr<user_manager::UserImage> user_image); 173 std::unique_ptr<user_manager::UserImage> user_image);
161 174
175 // Sets |prominent_color_| and notifies the observers if there is a change.
176 void SetProminentColor(SkColor color);
177
162 // wallpaper::WallpaperManagerBase: 178 // wallpaper::WallpaperManagerBase:
163 void InitializeRegisteredDeviceWallpaper() override; 179 void InitializeRegisteredDeviceWallpaper() override;
164 bool GetUserWallpaperInfo(const AccountId& account_id, 180 bool GetUserWallpaperInfo(const AccountId& account_id,
165 wallpaper::WallpaperInfo* info) const override; 181 wallpaper::WallpaperInfo* info) const override;
166 // Returns true if the device wallpaper should be set for the account. 182 // Returns true if the device wallpaper should be set for the account.
167 bool ShouldSetDeviceWallpaper(const AccountId& account_id, 183 bool ShouldSetDeviceWallpaper(const AccountId& account_id,
168 std::string* url, 184 std::string* url,
169 std::string* hash) override; 185 std::string* hash) override;
170 base::FilePath GetDeviceWallpaperDir() override; 186 base::FilePath GetDeviceWallpaperDir() override;
171 base::FilePath GetDeviceWallpaperFilePath() override; 187 base::FilePath GetDeviceWallpaperFilePath() override;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // All pending will be finally deleted on destroy. 247 // All pending will be finally deleted on destroy.
232 typedef std::vector<scoped_refptr<PendingWallpaper>> PendingList; 248 typedef std::vector<scoped_refptr<PendingWallpaper>> PendingList;
233 PendingList loading_; 249 PendingList loading_;
234 250
235 content::NotificationRegistrar registrar_; 251 content::NotificationRegistrar registrar_;
236 252
237 ScopedObserver<wm::ActivationClient, wm::ActivationChangeObserver> 253 ScopedObserver<wm::ActivationClient, wm::ActivationChangeObserver>
238 activation_client_observer_; 254 activation_client_observer_;
239 ScopedObserver<aura::Window, aura::WindowObserver> window_observer_; 255 ScopedObserver<aura::Window, aura::WindowObserver> window_observer_;
240 256
257 // The prominent color extracted from the current wallpaper.
258 // SK_ColorTRANSPARENT is used if color extraction fails.
jdufault 2017/06/12 21:37:28 Use base::Optional<>. Try to avoid using magic val
Wenzhao (Colin) Zang 2017/06/12 23:40:34 Done.
259 SkColor prominent_color_;
260
261 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_;
262
241 base::WeakPtrFactory<WallpaperManager> weak_factory_; 263 base::WeakPtrFactory<WallpaperManager> weak_factory_;
242 264
243 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); 265 DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
244 }; 266 };
245 267
246 } // namespace chromeos 268 } // namespace chromeos
247 269
248 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ 270 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698