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 COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ | 5 #ifndef COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ |
6 #define COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ | 6 #define COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <map> | 11 #include <map> |
| 12 #include <memory> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
18 #include "base/memory/scoped_ptr.h" | |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "base/threading/thread_checker.h" | 23 #include "base/threading/thread_checker.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "base/timer/timer.h" | 25 #include "base/timer/timer.h" |
26 #include "components/signin/core/account_id/account_id.h" | 26 #include "components/signin/core/account_id/account_id.h" |
27 #include "components/user_manager/user.h" | 27 #include "components/user_manager/user.h" |
28 #include "components/user_manager/user_image/user_image.h" | 28 #include "components/user_manager/user_image/user_image.h" |
(...skipping 21 matching lines...) Expand all Loading... |
50 class WALLPAPER_EXPORT MovableOnDestroyCallback { | 50 class WALLPAPER_EXPORT MovableOnDestroyCallback { |
51 public: | 51 public: |
52 explicit MovableOnDestroyCallback(const base::Closure& callback); | 52 explicit MovableOnDestroyCallback(const base::Closure& callback); |
53 | 53 |
54 ~MovableOnDestroyCallback(); | 54 ~MovableOnDestroyCallback(); |
55 | 55 |
56 private: | 56 private: |
57 base::Closure callback_; | 57 base::Closure callback_; |
58 }; | 58 }; |
59 | 59 |
60 typedef scoped_ptr<MovableOnDestroyCallback> MovableOnDestroyCallbackHolder; | 60 using MovableOnDestroyCallbackHolder = |
| 61 std::unique_ptr<MovableOnDestroyCallback>; |
61 | 62 |
62 struct WALLPAPER_EXPORT WallpaperInfo { | 63 struct WALLPAPER_EXPORT WallpaperInfo { |
63 WallpaperInfo(); | 64 WallpaperInfo(); |
64 WallpaperInfo(const std::string& in_location, | 65 WallpaperInfo(const std::string& in_location, |
65 WallpaperLayout in_layout, | 66 WallpaperLayout in_layout, |
66 user_manager::User::WallpaperType in_type, | 67 user_manager::User::WallpaperType in_type, |
67 const base::Time& in_date); | 68 const base::Time& in_date); |
68 ~WallpaperInfo(); | 69 ~WallpaperInfo(); |
69 | 70 |
70 // Either file name of migrated wallpaper including first directory level | 71 // Either file name of migrated wallpaper including first directory level |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 const gfx::ImageSkia& image, | 272 const gfx::ImageSkia& image, |
272 bool update_wallpaper) = 0; | 273 bool update_wallpaper) = 0; |
273 | 274 |
274 // Use given files as new default wallpaper. | 275 // Use given files as new default wallpaper. |
275 // Reloads current wallpaper, if old default was loaded. | 276 // Reloads current wallpaper, if old default was loaded. |
276 // Current value of default_wallpaper_image_ is destroyed. | 277 // Current value of default_wallpaper_image_ is destroyed. |
277 // Sets default_wallpaper_image_ either to |small_wallpaper_image| or | 278 // Sets default_wallpaper_image_ either to |small_wallpaper_image| or |
278 // |large_wallpaper_image| depending on GetAppropriateResolution(). | 279 // |large_wallpaper_image| depending on GetAppropriateResolution(). |
279 virtual void SetDefaultWallpaperPath( | 280 virtual void SetDefaultWallpaperPath( |
280 const base::FilePath& customized_default_wallpaper_file_small, | 281 const base::FilePath& customized_default_wallpaper_file_small, |
281 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 282 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
282 const base::FilePath& customized_default_wallpaper_file_large, | 283 const base::FilePath& customized_default_wallpaper_file_large, |
283 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) = 0; | 284 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) = 0; |
284 | 285 |
285 // Sets wallpaper to default wallpaper (asynchronously with zero delay). | 286 // Sets wallpaper to default wallpaper (asynchronously with zero delay). |
286 virtual void SetDefaultWallpaperNow(const AccountId& account_id) = 0; | 287 virtual void SetDefaultWallpaperNow(const AccountId& account_id) = 0; |
287 | 288 |
288 // Sets wallpaper to default wallpaper (asynchronously with default delay). | 289 // Sets wallpaper to default wallpaper (asynchronously with default delay). |
289 virtual void SetDefaultWallpaperDelayed(const AccountId& account_id) = 0; | 290 virtual void SetDefaultWallpaperDelayed(const AccountId& account_id) = 0; |
290 | 291 |
291 // Sets selected wallpaper information for |account_id| and saves it to Local | 292 // Sets selected wallpaper information for |account_id| and saves it to Local |
292 // State if |is_persistent| is true. | 293 // State if |is_persistent| is true. |
293 virtual void SetUserWallpaperInfo(const AccountId& account_id, | 294 virtual void SetUserWallpaperInfo(const AccountId& account_id, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 const AccountId& account_id); | 327 const AccountId& account_id); |
327 | 328 |
328 // Called when the wallpaper policy has been cleared for |account_id|. | 329 // Called when the wallpaper policy has been cleared for |account_id|. |
329 virtual void OnPolicyCleared(const std::string& policy, | 330 virtual void OnPolicyCleared(const std::string& policy, |
330 const AccountId& account_id); | 331 const AccountId& account_id); |
331 | 332 |
332 // Called when the policy-set wallpaper has been fetched. Initiates decoding | 333 // Called when the policy-set wallpaper has been fetched. Initiates decoding |
333 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | 334 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). |
334 virtual void OnPolicyFetched(const std::string& policy, | 335 virtual void OnPolicyFetched(const std::string& policy, |
335 const AccountId& account_id, | 336 const AccountId& account_id, |
336 scoped_ptr<std::string> data) = 0; | 337 std::unique_ptr<std::string> data) = 0; |
337 | 338 |
338 // This is called from CustomizationDocument. | 339 // This is called from CustomizationDocument. |
339 // |resized_directory| is the directory where resized versions are stored and | 340 // |resized_directory| is the directory where resized versions are stored and |
340 // must be writable. | 341 // must be writable. |
341 virtual void SetCustomizedDefaultWallpaper( | 342 virtual void SetCustomizedDefaultWallpaper( |
342 const GURL& wallpaper_url, | 343 const GURL& wallpaper_url, |
343 const base::FilePath& downloaded_file, | 344 const base::FilePath& downloaded_file, |
344 const base::FilePath& resized_directory); | 345 const base::FilePath& resized_directory); |
345 | 346 |
346 // Returns queue size. | 347 // Returns queue size. |
(...skipping 12 matching lines...) Expand all Loading... |
359 // is currently being loaded and or in progress of being loaded and |second| | 360 // is currently being loaded and or in progress of being loaded and |second| |
360 // the image itself. | 361 // the image itself. |
361 typedef std::pair<base::FilePath, gfx::ImageSkia> CustomWallpaperElement; | 362 typedef std::pair<base::FilePath, gfx::ImageSkia> CustomWallpaperElement; |
362 typedef std::map<AccountId, CustomWallpaperElement> CustomWallpaperMap; | 363 typedef std::map<AccountId, CustomWallpaperElement> CustomWallpaperMap; |
363 | 364 |
364 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 365 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
365 // and starts resizing operation of the custom wallpaper if necessary. | 366 // and starts resizing operation of the custom wallpaper if necessary. |
366 static void SaveCustomWallpaper(const WallpaperFilesId& wallpaper_files_id, | 367 static void SaveCustomWallpaper(const WallpaperFilesId& wallpaper_files_id, |
367 const base::FilePath& path, | 368 const base::FilePath& path, |
368 WallpaperLayout layout, | 369 WallpaperLayout layout, |
369 scoped_ptr<gfx::ImageSkia> image); | 370 std::unique_ptr<gfx::ImageSkia> image); |
370 | 371 |
371 // Moves custom wallpapers from user email directory to | 372 // Moves custom wallpapers from user email directory to |
372 // |wallpaper_files_id| directory. | 373 // |wallpaper_files_id| directory. |
373 static void MoveCustomWallpapersOnWorker( | 374 static void MoveCustomWallpapersOnWorker( |
374 const AccountId& account_id, | 375 const AccountId& account_id, |
375 const WallpaperFilesId& wallpaper_files_id, | 376 const WallpaperFilesId& wallpaper_files_id, |
376 const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, | 377 const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, |
377 base::WeakPtr<WallpaperManagerBase> weak_ptr); | 378 base::WeakPtr<WallpaperManagerBase> weak_ptr); |
378 | 379 |
379 // Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back on | 380 // Gets |account_id|'s custom wallpaper at |wallpaper_path|. Falls back on |
380 // original custom wallpaper. When |update_wallpaper| is true, sets wallpaper | 381 // original custom wallpaper. When |update_wallpaper| is true, sets wallpaper |
381 // to the loaded wallpaper. Must run on wallpaper sequenced worker thread. | 382 // to the loaded wallpaper. Must run on wallpaper sequenced worker thread. |
382 static void GetCustomWallpaperInternal( | 383 static void GetCustomWallpaperInternal( |
383 const AccountId& account_id, | 384 const AccountId& account_id, |
384 const WallpaperInfo& info, | 385 const WallpaperInfo& info, |
385 const base::FilePath& wallpaper_path, | 386 const base::FilePath& wallpaper_path, |
386 bool update_wallpaper, | 387 bool update_wallpaper, |
387 const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, | 388 const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner, |
388 MovableOnDestroyCallbackHolder on_finish, | 389 MovableOnDestroyCallbackHolder on_finish, |
389 base::WeakPtr<WallpaperManagerBase> weak_ptr); | 390 base::WeakPtr<WallpaperManagerBase> weak_ptr); |
390 | 391 |
391 // Resize and save customized default wallpaper. | 392 // Resize and save customized default wallpaper. |
392 static void ResizeCustomizedDefaultWallpaper( | 393 static void ResizeCustomizedDefaultWallpaper( |
393 scoped_ptr<gfx::ImageSkia> image, | 394 std::unique_ptr<gfx::ImageSkia> image, |
394 const CustomizedWallpaperRescaledFiles* rescaled_files, | 395 const CustomizedWallpaperRescaledFiles* rescaled_files, |
395 bool* success, | 396 bool* success, |
396 gfx::ImageSkia* small_wallpaper_image, | 397 gfx::ImageSkia* small_wallpaper_image, |
397 gfx::ImageSkia* large_wallpaper_image); | 398 gfx::ImageSkia* large_wallpaper_image); |
398 | 399 |
399 // Initialize wallpaper for the specified user to default and saves this | 400 // Initialize wallpaper for the specified user to default and saves this |
400 // settings in local state. | 401 // settings in local state. |
401 virtual void InitInitialUserWallpaper(const AccountId& account_id, | 402 virtual void InitInitialUserWallpaper(const AccountId& account_id, |
402 bool is_persistent); | 403 bool is_persistent); |
403 | 404 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 WallpaperInfo* info) const = 0; | 469 WallpaperInfo* info) const = 0; |
469 | 470 |
470 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 471 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
471 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage | 472 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage |
472 // because that's the callback interface provided by UserImageLoader.) | 473 // because that's the callback interface provided by UserImageLoader.) |
473 virtual void OnWallpaperDecoded( | 474 virtual void OnWallpaperDecoded( |
474 const AccountId& account_id, | 475 const AccountId& account_id, |
475 WallpaperLayout layout, | 476 WallpaperLayout layout, |
476 bool update_wallpaper, | 477 bool update_wallpaper, |
477 MovableOnDestroyCallbackHolder on_finish, | 478 MovableOnDestroyCallbackHolder on_finish, |
478 scoped_ptr<user_manager::UserImage> user_image) = 0; | 479 std::unique_ptr<user_manager::UserImage> user_image) = 0; |
479 | 480 |
480 // Creates new PendingWallpaper request (or updates currently pending). | 481 // Creates new PendingWallpaper request (or updates currently pending). |
481 virtual void ScheduleSetUserWallpaper(const AccountId& account_id, | 482 virtual void ScheduleSetUserWallpaper(const AccountId& account_id, |
482 bool delayed) = 0; | 483 bool delayed) = 0; |
483 | 484 |
484 // Sets wallpaper to default. | 485 // Sets wallpaper to default. |
485 virtual void DoSetDefaultWallpaper( | 486 virtual void DoSetDefaultWallpaper( |
486 const AccountId& account_id, | 487 const AccountId& account_id, |
487 MovableOnDestroyCallbackHolder on_finish) = 0; | 488 MovableOnDestroyCallbackHolder on_finish) = 0; |
488 | 489 |
(...skipping 15 matching lines...) Expand all Loading... |
504 // It is usually average wallpaper load time. | 505 // It is usually average wallpaper load time. |
505 // If last wallpaper load happened long ago, timeout should be reduced by | 506 // If last wallpaper load happened long ago, timeout should be reduced by |
506 // the time passed after last wallpaper load. So usual user experience results | 507 // the time passed after last wallpaper load. So usual user experience results |
507 // in zero delay. | 508 // in zero delay. |
508 virtual base::TimeDelta GetWallpaperLoadDelay() const; | 509 virtual base::TimeDelta GetWallpaperLoadDelay() const; |
509 | 510 |
510 // This is called after we check that supplied default wallpaper files exist. | 511 // This is called after we check that supplied default wallpaper files exist. |
511 virtual void SetCustomizedDefaultWallpaperAfterCheck( | 512 virtual void SetCustomizedDefaultWallpaperAfterCheck( |
512 const GURL& wallpaper_url, | 513 const GURL& wallpaper_url, |
513 const base::FilePath& downloaded_file, | 514 const base::FilePath& downloaded_file, |
514 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) = 0; | 515 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) = 0; |
515 | 516 |
516 // Starts rescaling of customized wallpaper. | 517 // Starts rescaling of customized wallpaper. |
517 virtual void OnCustomizedDefaultWallpaperDecoded( | 518 virtual void OnCustomizedDefaultWallpaperDecoded( |
518 const GURL& wallpaper_url, | 519 const GURL& wallpaper_url, |
519 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 520 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
520 scoped_ptr<user_manager::UserImage> user_image); | 521 std::unique_ptr<user_manager::UserImage> user_image); |
521 | 522 |
522 // Check the result of ResizeCustomizedDefaultWallpaper and finally | 523 // Check the result of ResizeCustomizedDefaultWallpaper and finally |
523 // apply Customized Default Wallpaper. | 524 // apply Customized Default Wallpaper. |
524 virtual void OnCustomizedDefaultWallpaperResized( | 525 virtual void OnCustomizedDefaultWallpaperResized( |
525 const GURL& wallpaper_url, | 526 const GURL& wallpaper_url, |
526 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 527 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
527 scoped_ptr<bool> success, | 528 std::unique_ptr<bool> success, |
528 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 529 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
529 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) = 0; | 530 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) = 0; |
530 | 531 |
531 // Init |*default_*_wallpaper_file_| from given command line and | 532 // Init |*default_*_wallpaper_file_| from given command line and |
532 // clear |default_wallpaper_image_|. | 533 // clear |default_wallpaper_image_|. |
533 virtual void SetDefaultWallpaperPathsFromCommandLine( | 534 virtual void SetDefaultWallpaperPathsFromCommandLine( |
534 base::CommandLine* command_line) = 0; | 535 base::CommandLine* command_line) = 0; |
535 | 536 |
536 // Sets wallpaper to decoded default. | 537 // Sets wallpaper to decoded default. |
537 virtual void OnDefaultWallpaperDecoded( | 538 virtual void OnDefaultWallpaperDecoded( |
538 const base::FilePath& path, | 539 const base::FilePath& path, |
539 const WallpaperLayout layout, | 540 const WallpaperLayout layout, |
540 scoped_ptr<user_manager::UserImage>* result, | 541 std::unique_ptr<user_manager::UserImage>* result, |
541 MovableOnDestroyCallbackHolder on_finish, | 542 MovableOnDestroyCallbackHolder on_finish, |
542 scoped_ptr<user_manager::UserImage> user_image) = 0; | 543 std::unique_ptr<user_manager::UserImage> user_image) = 0; |
543 | 544 |
544 // Start decoding given default wallpaper. | 545 // Start decoding given default wallpaper. |
545 virtual void StartLoadAndSetDefaultWallpaper( | 546 virtual void StartLoadAndSetDefaultWallpaper( |
546 const base::FilePath& path, | 547 const base::FilePath& path, |
547 const WallpaperLayout layout, | 548 const WallpaperLayout layout, |
548 MovableOnDestroyCallbackHolder on_finish, | 549 MovableOnDestroyCallbackHolder on_finish, |
549 scoped_ptr<user_manager::UserImage>* result_out) = 0; | 550 std::unique_ptr<user_manager::UserImage>* result_out) = 0; |
550 | 551 |
551 // Returns wallpaper subdirectory name for current resolution. | 552 // Returns wallpaper subdirectory name for current resolution. |
552 virtual const char* GetCustomWallpaperSubdirForCurrentResolution(); | 553 virtual const char* GetCustomWallpaperSubdirForCurrentResolution(); |
553 | 554 |
554 // Init default_wallpaper_image_ with 1x1 image of default color. | 555 // Init default_wallpaper_image_ with 1x1 image of default color. |
555 virtual void CreateSolidDefaultWallpaper(); | 556 virtual void CreateSolidDefaultWallpaper(); |
556 | 557 |
557 // The number of loaded wallpapers. | 558 // The number of loaded wallpapers. |
558 int loaded_wallpapers_for_test_; | 559 int loaded_wallpapers_for_test_; |
559 | 560 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 base::FilePath default_small_wallpaper_file_; | 593 base::FilePath default_small_wallpaper_file_; |
593 base::FilePath default_large_wallpaper_file_; | 594 base::FilePath default_large_wallpaper_file_; |
594 | 595 |
595 base::FilePath guest_small_wallpaper_file_; | 596 base::FilePath guest_small_wallpaper_file_; |
596 base::FilePath guest_large_wallpaper_file_; | 597 base::FilePath guest_large_wallpaper_file_; |
597 | 598 |
598 base::FilePath child_small_wallpaper_file_; | 599 base::FilePath child_small_wallpaper_file_; |
599 base::FilePath child_large_wallpaper_file_; | 600 base::FilePath child_large_wallpaper_file_; |
600 | 601 |
601 // Current decoded default image is stored in cache. | 602 // Current decoded default image is stored in cache. |
602 scoped_ptr<user_manager::UserImage> default_wallpaper_image_; | 603 std::unique_ptr<user_manager::UserImage> default_wallpaper_image_; |
603 | 604 |
604 base::WeakPtrFactory<WallpaperManagerBase> weak_factory_; | 605 base::WeakPtrFactory<WallpaperManagerBase> weak_factory_; |
605 | 606 |
606 private: | 607 private: |
607 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBase); | 608 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBase); |
608 }; | 609 }; |
609 | 610 |
610 } // namespace wallpaper | 611 } // namespace wallpaper |
611 | 612 |
612 #endif // COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ | 613 #endif // COMPONENTS_WALLPAPER_WALLPAPER_MANAGER_BASE_H_ |
OLD | NEW |