1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_WALLPAPER_WALLPAPER_CONTROLLER_IMPL_H_ 6 #define ASH_WALLPAPER_WALLPAPER_CONTROLLER_IMPL_H_ 7 8 #include <map> 9 #include <memory> 10 #include <string> 11 #include <utility> 12 #include <vector> 13 14 #include "ash/ash_export.h" 15 #include "ash/display/window_tree_host_manager.h" 16 #include "ash/public/cpp/session/session_observer.h" 17 #include "ash/public/cpp/tablet_mode_observer.h" 18 #include "ash/public/cpp/wallpaper_controller.h" 19 #include "ash/public/cpp/wallpaper_info.h" 20 #include "ash/public/cpp/wallpaper_types.h" 21 #include "ash/shell_observer.h" 22 #include "ash/wallpaper/wallpaper_utils/wallpaper_color_calculator_observer.h" 23 #include "ash/wallpaper/wallpaper_utils/wallpaper_resizer_observer.h" 24 #include "ash/wm/overview/overview_observer.h" 25 #include "base/files/file_path.h" 26 #include "base/memory/ref_counted.h" 27 #include "base/observer_list.h" 28 #include "base/timer/timer.h" 29 #include "ui/compositor/compositor_lock.h" 30 #include "ui/gfx/image/image_skia.h" 31 32 class PrefRegistrySimple; 33 34 namespace base { 35 class SequencedTaskRunner; 36 } // namespace base 37 38 namespace color_utils { 39 struct ColorProfile; 40 } // namespace color_utils 41 42 namespace ash { 43 44 class WallpaperColorCalculator; 45 class WallpaperResizer; 46 class WallpaperWindowStateManager; 47 48 // The |CustomWallpaperElement| contains |first| the path of the image which 49 // is currently being loaded and or in progress of being loaded and |second| 50 // the image itself. 51 using CustomWallpaperElement = std::pair<base::FilePath, gfx::ImageSkia>; 52 using CustomWallpaperMap = std::map<AccountId, CustomWallpaperElement>; 53 54 using LoadedCallback = base::OnceCallback<void(const gfx::ImageSkia& image)>; 55 56 // Controls the desktop background wallpaper: 57 // - Sets a wallpaper image and layout; 58 // - Handles display change (add/remove display, configuration change etc); 59 // - Calculates prominent colors. 60 // - Move wallpaper to locked container(s) when session state is not ACTIVE to 61 // hide the user desktop and move it to unlocked container when session 62 // state is ACTIVE; 63 class ASH_EXPORT WallpaperControllerImpl 64 : public WallpaperController, 65 public WindowTreeHostManager::Observer, 66 public ShellObserver, 67 public WallpaperResizerObserver, 68 public WallpaperColorCalculatorObserver, 69 public SessionObserver, 70 public TabletModeObserver, 71 public OverviewObserver, 72 public ui::CompositorLockClient { 73 public: 74 enum WallpaperResolution { 75 WALLPAPER_RESOLUTION_LARGE, 76 WALLPAPER_RESOLUTION_SMALL 77 }; 78 79 // Directory names of custom wallpapers. 80 static const char kSmallWallpaperSubDir[]; 81 static const char kLargeWallpaperSubDir[]; 82 static const char kOriginalWallpaperSubDir[]; 83 84 explicit WallpaperControllerImpl(PrefService* local_state); 85 ~WallpaperControllerImpl() override; 86 87 static void RegisterLocalStatePrefs(PrefRegistrySimple* registry); 88 89 // Returns the maximum size of all displays combined in native 90 // resolutions. Note that this isn't the bounds of the display who 91 // has maximum resolutions. Instead, this returns the size of the 92 // maximum width of all displays, and the maximum height of all displays. 93 static gfx::Size GetMaxDisplaySizeInNative(); 94 95 // Returns custom wallpaper path. Appends |sub_dir|, |wallpaper_files_id| and 96 // |file_name| to custom wallpaper directory. 97 static base::FilePath GetCustomWallpaperPath( 98 const std::string& sub_dir, 99 const std::string& wallpaper_files_id, 100 const std::string& file_name); 101 102 // Returns custom wallpaper directory by appending corresponding |sub_dir|. 103 static base::FilePath GetCustomWallpaperDir(const std::string& sub_dir); 104 105 // Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back to the 106 // original custom wallpaper. When |show_wallpaper| is true, shows the 107 // wallpaper immediately. Must run on wallpaper sequenced worker thread. 108 static void SetWallpaperFromPath( 109 const AccountId& account_id, 110 const WallpaperInfo& info, 111 const base::FilePath& wallpaper_path, 112 bool show_wallpaper, 113 const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, 114 base::WeakPtr<WallpaperControllerImpl> weak_ptr); 115 116 // Returns the prominent color based on |color_profile|. 117 SkColor GetProminentColor(color_utils::ColorProfile color_profile) const; 118 119 // Returns current image on the wallpaper, or an empty image if there's no 120 // wallpaper. 121 gfx::ImageSkia GetWallpaper() const; 122 123 // Returns the layout of the current wallpaper, or an invalid value if there's 124 // no wallpaper. 125 WallpaperLayout GetWallpaperLayout() const; 126 127 // Returns the type of the current wallpaper, or an invalid value if there's 128 // no wallpaper. 129 WallpaperType GetWallpaperType() const; 130 animation_duration()131 base::TimeDelta animation_duration() const { return animation_duration_; } 132 133 // Returns true if the slower initial animation should be shown (as opposed to 134 // the faster animation that's used e.g. when switching between different 135 // wallpapers at login screen). 136 bool ShouldShowInitialAnimation(); 137 138 // Returns true if the active user is allowed to open the wallpaper picker. 139 bool CanOpenWallpaperPicker(); 140 141 // Returns whether any wallpaper has been shown. It returns false before the 142 // first wallpaper is set (which happens momentarily after startup), and will 143 // always return true thereafter. 144 bool HasShownAnyWallpaper() const; 145 146 // Ash cannot close the chrome side of the wallpaper preview so this function 147 // tells the chrome side to do so. Also Ash cannot tell whether or not the 148 // wallpaper picker is currently open so this will close the wallpaper preview 149 // if it is open and do nothing if it is not open. 150 void MaybeClosePreviewWallpaper(); 151 152 // Shows the wallpaper and alerts observers of changes. 153 // Does not show the image if: 154 // 1) |preview_mode| is false and the current wallpaper is still being 155 // previewed. See comments for |confirm_preview_wallpaper_callback_|. 156 // 2) |always_on_top| is false but the current wallpaper is always-on-top. 157 void ShowWallpaperImage(const gfx::ImageSkia& image, 158 WallpaperInfo info, 159 bool preview_mode, 160 bool always_on_top); 161 162 // Returns whether a wallpaper policy is enforced for |account_id| (not 163 // including device policy). 164 bool IsPolicyControlled(const AccountId& account_id) const; 165 166 // Update the blurred state of the current wallpaper for lock screen. Applies 167 // blur if |blur| is true and blur is allowed by the controller, otherwise any 168 // existing blur is removed. 169 void UpdateWallpaperBlurForLockState(bool blur); 170 171 // Restores the wallpaper blur from lock state. 172 void RestoreWallpaperBlurForLockState(float blur); 173 174 // A color filter should be applied on the wallpaper for overview, login, 175 // lock, OOBE and add user screens. 176 bool ShouldApplyColorFilter() const; 177 178 // Returns whether the current wallpaper is allowed to be blurred on 179 // lock/login screen. See https://crbug.com/775591. 180 bool IsBlurAllowedForLockState() const; 181 182 // True if the wallpaper is set. is_wallpaper_set()183 bool is_wallpaper_set() const { return !!current_wallpaper_.get(); } 184 185 // Sets wallpaper info for |account_id| and saves it to local state if the 186 // user is not ephemeral. Returns false if it fails (which happens if local 187 // state is not available). 188 bool SetUserWallpaperInfo(const AccountId& account_id, 189 const WallpaperInfo& info); 190 191 // Gets wallpaper info of |account_id| from local state, or memory if the user 192 // is ephemeral. Returns false if wallpaper info is not found. 193 bool GetUserWallpaperInfo(const AccountId& account_id, 194 WallpaperInfo* info) const; 195 196 // Gets encoded wallpaper from cache. Returns true if success. 197 bool GetWallpaperFromCache(const AccountId& account_id, 198 gfx::ImageSkia* image); 199 200 // Gets path of encoded wallpaper from cache. Returns true if success. 201 bool GetPathFromCache(const AccountId& account_id, base::FilePath* path); 202 203 // Runs |callback| upon the completion of the first wallpaper animation that's 204 // shown on |window|'s root window. 205 void AddFirstWallpaperAnimationEndCallback(base::OnceClosure callback, 206 aura::Window* window); 207 208 // A wrapper of |ReadAndDecodeWallpaper| used in |SetWallpaperFromPath|. 209 void StartDecodeFromPath(const AccountId& account_id, 210 const base::FilePath& wallpaper_path, 211 const WallpaperInfo& info, 212 bool show_wallpaper); 213 214 // WallpaperController: 215 void SetClient(WallpaperControllerClient* client) override; 216 void Init(const base::FilePath& user_data, 217 const base::FilePath& wallpapers, 218 const base::FilePath& custom_wallpapers, 219 const base::FilePath& device_policy_wallpaper) override; 220 void SetCustomWallpaper(const AccountId& account_id, 221 const std::string& wallpaper_files_id, 222 const std::string& file_name, 223 WallpaperLayout layout, 224 const gfx::ImageSkia& image, 225 bool preview_mode) override; 226 void SetOnlineWallpaperIfExists( 227 const AccountId& account_id, 228 const std::string& url, 229 WallpaperLayout layout, 230 bool preview_mode, 231 SetOnlineWallpaperIfExistsCallback callback) override; 232 void SetOnlineWallpaperFromData( 233 const AccountId& account_id, 234 const std::string& image_data, 235 const std::string& url, 236 WallpaperLayout layout, 237 bool preview_mode, 238 SetOnlineWallpaperFromDataCallback callback) override; 239 void SetDefaultWallpaper(const AccountId& account_id, 240 const std::string& wallpaper_files_id, 241 bool show_wallpaper) override; 242 void SetCustomizedDefaultWallpaperPaths( 243 const base::FilePath& customized_default_small_path, 244 const base::FilePath& customized_default_large_path) override; 245 void SetPolicyWallpaper(const AccountId& account_id, 246 const std::string& wallpaper_files_id, 247 const std::string& data) override; 248 void SetDevicePolicyWallpaperPath( 249 const base::FilePath& device_policy_wallpaper_path) override; 250 bool SetThirdPartyWallpaper(const AccountId& account_id, 251 const std::string& wallpaper_files_id, 252 const std::string& file_name, 253 WallpaperLayout layout, 254 const gfx::ImageSkia& image) override; 255 void ConfirmPreviewWallpaper() override; 256 void CancelPreviewWallpaper() override; 257 void UpdateCustomWallpaperLayout(const AccountId& account_id, 258 WallpaperLayout layout) override; 259 void ShowUserWallpaper(const AccountId& account_id) override; 260 void ShowSigninWallpaper() override; 261 void ShowOneShotWallpaper(const gfx::ImageSkia& image) override; 262 void ShowAlwaysOnTopWallpaper(const base::FilePath& image_path) override; 263 void RemoveAlwaysOnTopWallpaper() override; 264 void RemoveUserWallpaper(const AccountId& account_id, 265 const std::string& wallpaper_files_id) override; 266 void RemovePolicyWallpaper(const AccountId& account_id, 267 const std::string& wallpaper_files_id) override; 268 void GetOfflineWallpaperList( 269 GetOfflineWallpaperListCallback callback) override; 270 void SetAnimationDuration(base::TimeDelta animation_duration) override; 271 void OpenWallpaperPickerIfAllowed() override; 272 void MinimizeInactiveWindows(const std::string& user_id_hash) override; 273 void RestoreMinimizedWindows(const std::string& user_id_hash) override; 274 void AddObserver(WallpaperControllerObserver* observer) override; 275 void RemoveObserver(WallpaperControllerObserver* observer) override; 276 gfx::ImageSkia GetWallpaperImage() override; 277 const std::vector<SkColor>& GetWallpaperColors() override; 278 bool IsWallpaperBlurredForLockState() const override; 279 bool IsActiveUserWallpaperControlledByPolicy() override; 280 WallpaperInfo GetActiveUserWallpaperInfo() override; 281 bool ShouldShowWallpaperSetting() override; 282 283 // WindowTreeHostManager::Observer: 284 void OnDisplayConfigurationChanged() override; 285 286 // ShellObserver: 287 void OnRootWindowAdded(aura::Window* root_window) override; 288 void OnShellInitialized() override; 289 void OnShellDestroying() override; 290 291 // WallpaperResizerObserver: 292 void OnWallpaperResized() override; 293 294 // WallpaperColorCalculatorObserver: 295 void OnColorCalculationComplete() override; 296 297 // SessionObserver: 298 void OnSessionStateChanged(session_manager::SessionState state) override; 299 300 // TabletModeObserver: 301 void OnTabletModeStarted() override; 302 void OnTabletModeEnded() override; 303 304 // OverviewObserver: 305 void OnOverviewModeWillStart() override; 306 307 // CompositorLockClient: 308 void CompositorLockTimedOut() override; 309 310 // Shows a default wallpaper for testing, without changing users' wallpaper 311 // info. 312 void ShowDefaultWallpaperForTesting(); 313 314 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready 315 // when running. However, the wallpaper widgets are created asynchronously. If 316 // loading a real wallpaper, there are cases that these tests crash because 317 // the required widget is not ready. This function synchronously creates an 318 // empty widget for those tests to prevent crashes. 319 void CreateEmptyWallpaperForTesting(); 320 set_wallpaper_reload_no_delay_for_test()321 void set_wallpaper_reload_no_delay_for_test() { 322 wallpaper_reload_delay_ = base::TimeDelta::FromMilliseconds(0); 323 } 324 325 // Proxy to private ReloadWallpaper(). 326 void ReloadWallpaperForTesting(bool clear_cache); 327 set_bypass_decode_for_testing()328 void set_bypass_decode_for_testing() { bypass_decode_for_testing_ = true; } 329 330 private: 331 FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, BasicReparenting); 332 FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, 333 WallpaperMovementDuringUnlock); 334 friend class WallpaperControllerTest; 335 friend class WallpaperControllerTestApi; 336 337 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; 338 339 // Cached default wallpaper image and file path. The file path can be used to 340 // check if the image is outdated (i.e. when there's a new default wallpaper). 341 struct CachedDefaultWallpaper { 342 gfx::ImageSkia image; 343 base::FilePath file_path; 344 }; 345 346 struct OnlineWallpaperParams { 347 AccountId account_id; 348 std::string url; 349 WallpaperLayout layout; 350 bool preview_mode; 351 }; 352 353 // Update a Wallpaper for |root_window|. 354 void UpdateWallpaperForRootWindow(aura::Window* root_window, 355 bool lock_state_changed, 356 bool new_root); 357 358 // Update a Wallpaper for all root windows. 359 void UpdateWallpaperForAllRootWindows(bool lock_state_changed); 360 361 // Moves the wallpaper to the specified container across all root windows. 362 // Returns true if a wallpaper moved. 363 bool ReparentWallpaper(int container); 364 365 // Returns the wallpaper container id for unlocked and locked states. 366 int GetWallpaperContainerId(bool locked); 367 368 // Removes |account_id|'s wallpaper info and color cache if it exists. 369 void RemoveUserWallpaperInfo(const AccountId& account_id); 370 371 // Implementation of |RemoveUserWallpaper|, which deletes |account_id|'s 372 // custom wallpapers and directories. 373 void RemoveUserWallpaperImpl(const AccountId& account_id, 374 const std::string& wallpaper_files_id); 375 376 // Implementation of |SetDefaultWallpaper|. Sets wallpaper to default if 377 // |show_wallpaper| is true. Otherwise just save the defaut wallpaper to 378 // cache. 379 void SetDefaultWallpaperImpl(const AccountId& account_id, 380 bool show_wallpaper); 381 382 // When kiosk app is running or policy is enforced, setting a user wallpaper 383 // is not allowed. 384 bool CanSetUserWallpaper(const AccountId& account_id) const; 385 386 // Returns true if the specified wallpaper is already stored in 387 // |current_wallpaper_|. If |compare_layouts| is false, layout is ignored. 388 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image, 389 bool compare_layouts, 390 WallpaperLayout layout) const; 391 392 // Reads image from |file_path| on disk, and calls |OnWallpaperDataRead| 393 // with the result of |ReadFileToString|. 394 void ReadAndDecodeWallpaper( 395 LoadedCallback callback, 396 scoped_refptr<base::SequencedTaskRunner> task_runner, 397 const base::FilePath& file_path); 398 399 // Initializes wallpaper info for the user to default and saves it to local 400 // state the user is not ephemeral. Returns false if initialization fails. 401 bool InitializeUserWallpaperInfo(const AccountId& account_id); 402 403 // Used as the callback of checking ONLINE wallpaper existence in 404 // |SetOnlineWallpaperIfExists|. Initiates reading and decoding the wallpaper 405 // if |file_path| is not empty. 406 void SetOnlineWallpaperFromPath(SetOnlineWallpaperIfExistsCallback callback, 407 const OnlineWallpaperParams& params, 408 const base::FilePath& file_path); 409 410 // Used as the callback of decoding wallpapers of type ONLINE. Saves the image 411 // to local file if |save_file| is true, and shows the wallpaper immediately 412 // if |params.account_id| is the active user. 413 void OnOnlineWallpaperDecoded(const OnlineWallpaperParams& params, 414 bool save_file, 415 SetOnlineWallpaperFromDataCallback callback, 416 const gfx::ImageSkia& image); 417 418 // Implementation of |SetOnlineWallpaper|. Shows the wallpaper on screen if 419 // |show_wallpaper| is true. 420 void SetOnlineWallpaperImpl(const OnlineWallpaperParams& params, 421 const gfx::ImageSkia& image, 422 bool show_wallpaper); 423 424 // Decodes |account_id|'s wallpaper. Shows the decoded wallpaper if 425 // |show_wallpaper| is true. 426 void SetWallpaperFromInfo(const AccountId& account_id, 427 const WallpaperInfo& info, 428 bool show_wallpaper); 429 430 // Used as the callback of default wallpaper decoding. Sets default wallpaper 431 // to be the decoded image, and shows the wallpaper now if |show_wallpaper| 432 // is true. 433 void OnDefaultWallpaperDecoded(const base::FilePath& path, 434 WallpaperLayout layout, 435 bool show_wallpaper, 436 const gfx::ImageSkia& image); 437 438 // Saves |image| to disk if the user's data is not ephemeral, or if it is a 439 // policy wallpaper for public accounts. Shows the wallpaper immediately if 440 // |show_wallpaper| is true, otherwise only sets the wallpaper info and 441 // updates the cache. 442 void SaveAndSetWallpaper(const AccountId& account_id, 443 const std::string& wallpaper_files_id, 444 const std::string& file_name, 445 WallpaperType type, 446 WallpaperLayout layout, 447 bool show_wallpaper, 448 const gfx::ImageSkia& image); 449 450 // Used as the callback of wallpaper decoding. (Wallpapers of type ONLINE, 451 // DEFAULT and DEVICE should use their corresponding |*Decoded|, and all other 452 // types should use this.) Shows the wallpaper immediately if |show_wallpaper| 453 // is true. Otherwise, only updates the cache. 454 void OnWallpaperDecoded(const AccountId& account_id, 455 const base::FilePath& path, 456 const WallpaperInfo& info, 457 bool show_wallpaper, 458 const gfx::ImageSkia& image); 459 460 // Reloads the current wallpaper. It may change the wallpaper size based on 461 // the current display's resolution. If |clear_cache| is true, all wallpaper 462 // cache should be cleared. This is required when the display's native 463 // resolution changes to a larger resolution (e.g. when hooked up a large 464 // external display) and we need to load a larger resolution wallpaper for the 465 // display. All the previous small resolution wallpaper cache should be 466 // cleared. 467 void ReloadWallpaper(bool clear_cache); 468 469 // Sets |prominent_colors_| and notifies the observers if there is a change. 470 void SetProminentColors(const std::vector<SkColor>& prominent_colors); 471 472 // Sets all elements of |prominent_colors| to |kInvalidWallpaperColor| via 473 // SetProminentColors(). 474 void ResetProminentColors(); 475 476 // Calculates prominent colors based on the wallpaper image and notifies 477 // |observers_| of the value, either synchronously or asynchronously. In some 478 // cases the wallpaper image will not actually be processed (e.g. user isn't 479 // logged in, feature isn't enabled). 480 // If an existing calculation is in progress it is destroyed. 481 void CalculateWallpaperColors(); 482 483 // Returns false when the color extraction algorithm shouldn't be run based on 484 // system state (e.g. wallpaper image, SessionState, etc.). 485 bool ShouldCalculateColors() const; 486 487 // Caches color calculation results in the local state pref service. 488 void CacheProminentColors(const std::vector<SkColor>& colors, 489 const std::string& current_location); 490 491 // Gets prominent color cache from the local state pref service. Returns an 492 // empty value if the cache is not available. 493 base::Optional<std::vector<SkColor>> GetCachedColors( 494 const std::string& current_location) const; 495 496 // The callback when decoding of the always-on-top wallpaper completes. 497 void OnAlwaysOnTopWallpaperDecoded(const WallpaperInfo& info, 498 const gfx::ImageSkia& image); 499 500 // Returns whether the current wallpaper is set by device policy. 501 bool IsDevicePolicyWallpaper() const; 502 503 // Returns whether the current wallpaper has type of ONE_SHOT. 504 bool IsOneShotWallpaper() const; 505 506 // Returns true if device wallpaper policy is in effect and we are at the 507 // login screen right now. 508 bool ShouldSetDevicePolicyWallpaper() const; 509 510 // Reads the device wallpaper file and sets it as the current wallpaper. Note 511 // when it's called, it's guaranteed that ShouldSetDevicePolicyWallpaper() 512 // should be true. 513 void SetDevicePolicyWallpaper(); 514 515 // Called when the device policy controlled wallpaper has been decoded. 516 void OnDevicePolicyWallpaperDecoded(const gfx::ImageSkia& image); 517 518 // When wallpaper resizes, we can check which displays will be affected. For 519 // simplicity, we only lock the compositor for the internal display. 520 void GetInternalDisplayCompositorLock(); 521 522 // Schedules paint on all WallpaperViews owned by WallpaperWidgetControllers. 523 // This is used when we want to change wallpaper dimming. 524 void RepaintWallpaper(); 525 526 bool locked_ = false; 527 528 WallpaperMode wallpaper_mode_ = WALLPAPER_NONE; 529 530 // Client interface in chrome browser. 531 WallpaperControllerClient* wallpaper_controller_client_ = nullptr; 532 533 base::ObserverList<WallpaperControllerObserver>::Unchecked observers_; 534 535 std::unique_ptr<WallpaperResizer> current_wallpaper_; 536 537 // Asynchronous task to extract colors from the wallpaper. 538 std::unique_ptr<WallpaperColorCalculator> color_calculator_; 539 540 // Manages the states of the other windows when the wallpaper app window is 541 // active. 542 std::unique_ptr<WallpaperWindowStateManager> window_state_manager_; 543 544 // The prominent colors extracted from the current wallpaper. 545 // kInvalidWallpaperColor is used by default or if extracting colors fails. 546 std::vector<SkColor> prominent_colors_; 547 548 // Caches the color profiles that need to do wallpaper color extracting. 549 const std::vector<color_utils::ColorProfile> color_profiles_; 550 551 // The wallpaper info for ephemeral users, which is not stored to local state. 552 // See |UserInfo::is_ephemeral| for details. 553 std::map<AccountId, WallpaperInfo> ephemeral_users_wallpaper_info_; 554 555 // Account id of the current user. 556 AccountId current_user_; 557 558 // Cached wallpapers of users. 559 CustomWallpaperMap wallpaper_cache_map_; 560 561 // Cached default wallpaper. 562 CachedDefaultWallpaper cached_default_wallpaper_; 563 564 // The paths of the customized default wallpapers, if they exist. 565 base::FilePath customized_default_small_path_; 566 base::FilePath customized_default_large_path_; 567 568 gfx::Size current_max_display_size_; 569 570 base::OneShotTimer timer_; 571 572 base::TimeDelta wallpaper_reload_delay_; 573 574 bool is_wallpaper_blurred_for_lock_state_ = false; 575 576 // The wallpaper animation duration. An empty value disables the animation. 577 base::TimeDelta animation_duration_; 578 579 base::FilePath device_policy_wallpaper_path_; 580 581 // Whether the current wallpaper (if any) is the first wallpaper since the 582 // controller initialization. Empty wallpapers for testing don't count. 583 bool is_first_wallpaper_ = false; 584 585 // If true, the current wallpaper should always stay on top. 586 bool is_always_on_top_wallpaper_ = false; 587 588 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; 589 590 ScopedSessionObserver scoped_session_observer_{this}; 591 592 std::unique_ptr<ui::CompositorLock> compositor_lock_; 593 594 // A non-empty value indicates the current wallpaper is in preview mode, which 595 // expects either |ConfirmPreviewWallpaper| or |CancelPreviewWallpaper| to be 596 // called to exit preview. In preview mode, other types of wallpaper requests 597 // may still update wallpaper info for the user, but the preview wallpaper 598 // cannot be replaced, except by another preview wallpaper. 599 base::OnceClosure confirm_preview_wallpaper_callback_; 600 601 // Called when the preview wallpaper needs to be reloaded (e.g. display size 602 // change). Has the same lifetime with |confirm_preview_wallpaper_callback_|. 603 base::RepeatingClosure reload_preview_wallpaper_callback_; 604 605 // Called when the always-on-top wallpaper needs to be reloaded (e.g. display 606 // size change). Non-empty if and only if |is_always_on_top_wallpaper_| is 607 // true. 608 base::RepeatingClosure reload_always_on_top_wallpaper_callback_; 609 610 // If true, use a solid color wallpaper as if it is the decoded image. 611 bool bypass_decode_for_testing_ = false; 612 613 // Tracks how many wallpapers have been set. 614 int wallpaper_count_for_testing_ = 0; 615 616 // The file paths of decoding requests that have been initiated. Must be a 617 // list because more than one decoding requests may happen during a single 618 // 'set wallpaper' request. (e.g. when a custom wallpaper decoding fails, a 619 // default wallpaper decoding is initiated.) 620 std::vector<base::FilePath> decode_requests_for_testing_; 621 622 // PrefService provided by Shell when constructing this. 623 // Valid for the lifetime of ash::Shell which owns WallpaperControllerImpl. 624 // May be null in tests. 625 PrefService* local_state_ = nullptr; 626 627 base::WeakPtrFactory<WallpaperControllerImpl> weak_factory_{this}; 628 629 DISALLOW_COPY_AND_ASSIGN(WallpaperControllerImpl); 630 }; 631 632 } // namespace ash 633 634 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_IMPL_H_ 635