Home | History | Annotate | Download | only in wallpaper
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_
      7 
      8 #include <deque>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "ash/desktop_background/desktop_background_controller.h"
     13 #include "base/files/file_path.h"
     14 #include "base/memory/ref_counted_memory.h"
     15 #include "base/memory/scoped_ptr.h"
     16 #include "base/memory/weak_ptr.h"
     17 #include "base/observer_list.h"
     18 #include "base/threading/sequenced_worker_pool.h"
     19 #include "base/time/time.h"
     20 #include "chrome/browser/chromeos/login/users/avatar/user_image.h"
     21 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h"
     22 #include "chrome/browser/chromeos/login/users/user.h"
     23 #include "chrome/browser/chromeos/settings/cros_settings.h"
     24 #include "content/public/browser/notification_observer.h"
     25 #include "content/public/browser/notification_registrar.h"
     26 #include "third_party/icu/source/i18n/unicode/timezone.h"
     27 #include "ui/gfx/image/image_skia.h"
     28 
     29 class PrefRegistrySimple;
     30 
     31 namespace base {
     32 class CommandLine;
     33 class SequencedTaskRunner;
     34 }
     35 
     36 namespace chromeos {
     37 
     38 struct WallpaperInfo {
     39   // Online wallpaper URL or file name of migrated wallpaper.
     40   std::string file;
     41   ash::WallpaperLayout layout;
     42   User::WallpaperType type;
     43   base::Time date;
     44   bool operator==(const WallpaperInfo& other) {
     45     return (file == other.file) && (layout == other.layout) &&
     46         (type == other.type);
     47   }
     48 };
     49 
     50 class MovableOnDestroyCallback;
     51 typedef scoped_ptr<MovableOnDestroyCallback> MovableOnDestroyCallbackHolder;
     52 
     53 class WallpaperManagerBrowserTest;
     54 class UserImage;
     55 
     56 // Name of wallpaper sequence token.
     57 extern const char kWallpaperSequenceTokenName[];
     58 
     59 // File path suffices of resized small or large wallpaper.
     60 // TODO(bshe): Use the same sub folder system as custom wallpapers use.
     61 // crbug.com/174928
     62 extern const char kSmallWallpaperSuffix[];
     63 extern const char kLargeWallpaperSuffix[];
     64 
     65 // Directory names of custom wallpapers.
     66 extern const char kSmallWallpaperSubDir[];
     67 extern const char kLargeWallpaperSubDir[];
     68 extern const char kOriginalWallpaperSubDir[];
     69 extern const char kThumbnailWallpaperSubDir[];
     70 
     71 // The width and height of small/large resolution wallpaper. When screen size is
     72 // smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the
     73 // small resolution wallpaper should be used. Otherwise, use the large
     74 // resolution wallpaper.
     75 extern const int kSmallWallpaperMaxWidth;
     76 extern const int kSmallWallpaperMaxHeight;
     77 extern const int kLargeWallpaperMaxWidth;
     78 extern const int kLargeWallpaperMaxHeight;
     79 
     80 // The width and height of wallpaper thumbnails.
     81 extern const int kWallpaperThumbnailWidth;
     82 extern const int kWallpaperThumbnailHeight;
     83 
     84 // This singleton class maintains wallpapers for users who have logged into this
     85 // Chrome OS device.
     86 class WallpaperManager: public content::NotificationObserver {
     87  public:
     88   enum WallpaperResolution {
     89     WALLPAPER_RESOLUTION_LARGE,
     90     WALLPAPER_RESOLUTION_SMALL
     91   };
     92 
     93   // For testing.
     94   class TestApi {
     95    public:
     96     explicit TestApi(WallpaperManager* wallpaper_manager);
     97     virtual ~TestApi();
     98 
     99     base::FilePath current_wallpaper_path();
    100 
    101     bool GetWallpaperFromCache(const std::string& user_id,
    102                                gfx::ImageSkia* image);
    103 
    104     void SetWallpaperCache(const std::string& user_id,
    105                            const gfx::ImageSkia& image);
    106 
    107     void ClearDisposableWallpaperCache();
    108 
    109    private:
    110     WallpaperManager* wallpaper_manager_;  // not owned
    111 
    112     DISALLOW_COPY_AND_ASSIGN(TestApi);
    113   };
    114 
    115   // This should be public to allow access from functions in anonymous
    116   // namespace.
    117   class CustomizedWallpaperRescaledFiles;
    118 
    119   class Observer {
    120    public:
    121     virtual ~Observer() {}
    122     virtual void OnWallpaperAnimationFinished(const std::string& user_id) = 0;
    123     virtual void OnUpdateWallpaperForTesting() {}
    124     virtual void OnPendingListEmptyForTesting() {}
    125   };
    126 
    127   // This is "wallpaper either scheduled to load, or loading right now".
    128   //
    129   // While enqueued, it defines moment in the future, when it will be loaded.
    130   // Enqueued but not started request might be updated by subsequent load
    131   // request. Therefore it's created empty, and updated being enqueued.
    132   //
    133   // PendingWallpaper is owned by WallpaperManager, but reference to this object
    134   // is passed to other threads by PostTask() calls, therefore it is
    135   // RefCountedThreadSafe.
    136   class PendingWallpaper : public base::RefCountedThreadSafe<PendingWallpaper> {
    137    public:
    138     // Do LoadWallpaper() - image not found in cache.
    139     PendingWallpaper(const base::TimeDelta delay, const std::string& user_id);
    140 
    141     // There are 4 cases in SetUserWallpaper:
    142     // 1) gfx::ImageSkia is found in cache.
    143     //    - Schedule task to (probably) resize it and install:
    144     //    call ash::Shell::GetInstance()->desktop_background_controller()->
    145     //          SetCustomWallpaper(user_wallpaper, layout);
    146     // 2) WallpaperInfo is found in cache
    147     //    - need to LoadWallpaper(), resize and install.
    148     // 3) wallpaper path is not NULL, load image URL, then resize, etc...
    149     // 4) SetDefaultWallpaper (either on some error, or when user is new).
    150     void ResetSetWallpaperImage(const gfx::ImageSkia& image,
    151                                 const WallpaperInfo& info);
    152     void ResetLoadWallpaper(const WallpaperInfo& info);
    153     void ResetSetCustomWallpaper(const WallpaperInfo& info,
    154                                  const base::FilePath& wallpaper_path);
    155     void ResetSetDefaultWallpaper();
    156 
    157    private:
    158     friend class base::RefCountedThreadSafe<PendingWallpaper>;
    159 
    160     ~PendingWallpaper();
    161 
    162     // All Reset*() methods use SetMode() to set object to new state.
    163     void SetMode(const gfx::ImageSkia& image,
    164                  const WallpaperInfo& info,
    165                  const base::FilePath& wallpaper_path,
    166                  const bool is_default);
    167 
    168     // This method is usually triggered by timer to actually load request.
    169     void ProcessRequest();
    170 
    171     // This method is called by callback, when load request is finished.
    172     void OnWallpaperSet();
    173 
    174     std::string user_id_;
    175     WallpaperInfo info_;
    176     gfx::ImageSkia user_wallpaper_;
    177     base::FilePath wallpaper_path_;
    178 
    179     // Load default wallpaper instead of user image.
    180     bool default_;
    181 
    182     // This is "on destroy" callback that will call OnWallpaperSet() when
    183     // image will be loaded.
    184     MovableOnDestroyCallbackHolder on_finish_;
    185     base::OneShotTimer<WallpaperManager::PendingWallpaper> timer;
    186 
    187     // Load start time to calculate duration.
    188     base::Time started_load_at_;
    189 
    190     DISALLOW_COPY_AND_ASSIGN(PendingWallpaper);
    191   };
    192 
    193   WallpaperManager();
    194   virtual ~WallpaperManager();
    195 
    196   // Get pointer to singleton WallpaperManager instance, create it if necessary.
    197   static WallpaperManager* Get();
    198 
    199   // Registers wallpaper manager preferences.
    200   static void RegisterPrefs(PrefRegistrySimple* registry);
    201 
    202   // Resizes |image| to a resolution which is nearest to |preferred_width| and
    203   // |preferred_height| while respecting the |layout| choice. |output_skia| is
    204   // optional (may be NULL). Returns true on success.
    205   static bool ResizeImage(const gfx::ImageSkia& image,
    206                           ash::WallpaperLayout layout,
    207                           int preferred_width,
    208                           int preferred_height,
    209                           scoped_refptr<base::RefCountedBytes>* output,
    210                           gfx::ImageSkia* output_skia);
    211 
    212   // Resizes |image| to a resolution which is nearest to |preferred_width| and
    213   // |preferred_height| while respecting the |layout| choice and saves the
    214   // resized wallpaper to |path|. |output_skia| is optional (may be
    215   // NULL). Returns true on success.
    216   static bool ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
    217                                      const base::FilePath& path,
    218                                      ash::WallpaperLayout layout,
    219                                      int preferred_width,
    220                                      int preferred_height,
    221                                      gfx::ImageSkia* output_skia);
    222 
    223   // Returns the appropriate wallpaper resolution for all root windows.
    224   static WallpaperResolution GetAppropriateResolution();
    225 
    226   // Returns custom wallpaper path. Append |sub_dir|, |user_id_hash| and |file|
    227   // to custom wallpaper directory.
    228   static base::FilePath GetCustomWallpaperPath(const char* sub_dir,
    229                                                const std::string& user_id_hash,
    230                                                const std::string& file);
    231 
    232   void SetCommandLineForTesting(base::CommandLine* command_line);
    233 
    234   // Indicates imminent shutdown, allowing the WallpaperManager to remove any
    235   // observers it has registered.
    236   void Shutdown();
    237 
    238   // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers.
    239   void AddObservers();
    240 
    241   // Loads wallpaper asynchronously if the current wallpaper is not the
    242   // wallpaper of logged in user.
    243   void EnsureLoggedInUserWallpaperLoaded();
    244 
    245   // Gets wallpaper information of logged in user.
    246   bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info);
    247 
    248   // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged
    249   // in, uses a solid color wallpaper. If logged in as a stub user, uses an
    250   // empty wallpaper.
    251   void InitializeWallpaper();
    252 
    253   // NotificationObserver overrides:
    254   virtual void Observe(int type,
    255                        const content::NotificationSource& source,
    256                        const content::NotificationDetails& details) OVERRIDE;
    257 
    258   // Removes all |user_id| related wallpaper info and saved wallpapers.
    259   void RemoveUserWallpaperInfo(const std::string& user_id);
    260 
    261   // Saves custom wallpaper to file, post task to generate thumbnail and updates
    262   // local state preferences. If |update_wallpaper| is false, don't change
    263   // wallpaper but only update cache.
    264   void SetCustomWallpaper(const std::string& user_id,
    265                           const std::string& user_id_hash,
    266                           const std::string& file,
    267                           ash::WallpaperLayout layout,
    268                           User::WallpaperType type,
    269                           const gfx::ImageSkia& image,
    270                           bool update_wallpaper);
    271 
    272   // Use given files as new default wallpaper.
    273   // Reloads current wallpaper, if old default was loaded.
    274   // Current value of default_wallpaper_image_ is destroyed.
    275   // Sets default_wallpaper_image_ either to |small_wallpaper_image| or
    276   // |large_wallpaper_image| depending on GetAppropriateResolution().
    277   void SetDefaultWallpaperPath(
    278       const base::FilePath& customized_default_wallpaper_file_small,
    279       scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
    280       const base::FilePath& customized_default_wallpaper_file_large,
    281       scoped_ptr<gfx::ImageSkia> large_wallpaper_image);
    282 
    283   // Sets wallpaper to default wallpaper (asynchronously with zero delay).
    284   void SetDefaultWallpaperNow(const std::string& user_id);
    285 
    286   // Sets wallpaper to default wallpaper (asynchronously with default delay).
    287   void SetDefaultWallpaperDelayed(const std::string& user_id);
    288 
    289   // Sets selected wallpaper information for |user_id| and saves it to Local
    290   // State if |is_persistent| is true.
    291   void SetUserWallpaperInfo(const std::string& user_id,
    292                             const WallpaperInfo& info,
    293                             bool is_persistent);
    294 
    295   // Sets |user_id|'s wallpaper (asynchronously with zero delay).
    296   void SetUserWallpaperNow(const std::string& user_id);
    297 
    298   // Sets |user_id|'s wallpaper (asynchronously with default delay).
    299   void SetUserWallpaperDelayed(const std::string& user_id);
    300 
    301   // Sets wallpaper to |image| (asynchronously with zero delay). If
    302   // |update_wallpaper| is false, skip change wallpaper but only update cache.
    303   void SetWallpaperFromImageSkia(const std::string& user_id,
    304                                  const gfx::ImageSkia& image,
    305                                  ash::WallpaperLayout layout,
    306                                  bool update_wallpaper);
    307 
    308   // Updates current wallpaper. It may switch the size of wallpaper based on the
    309   // current display's resolution. (asynchronously with zero delay)
    310   void UpdateWallpaper(bool clear_cache);
    311 
    312   // Adds given observer to the list.
    313   void AddObserver(Observer* observer);
    314 
    315   // Removes given observer from the list.
    316   void RemoveObserver(Observer* observer);
    317 
    318   // Returns whether a wallpaper policy is enforced for |user_id|.
    319   bool IsPolicyControlled(const std::string& user_id) const;
    320 
    321   // Called when a wallpaper policy has been set for |user_id|.  Blocks user
    322   // from changing the wallpaper.
    323   void OnPolicySet(const std::string& policy, const std::string& user_id);
    324 
    325   // Called when the wallpaper policy has been cleared for |user_id|.
    326   void OnPolicyCleared(const std::string& policy, const std::string& user_id);
    327 
    328   // Called when the policy-set wallpaper has been fetched.  Initiates decoding
    329   // of the JPEG |data| with a callback to SetPolicyControlledWallpaper().
    330   void OnPolicyFetched(const std::string& policy,
    331                        const std::string& user_id,
    332                        scoped_ptr<std::string> data);
    333 
    334   // This is called from CustomizationDocument.
    335   // |resized_directory| is the directory where resized versions are stored and
    336   // must be writable.
    337   void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url,
    338                                      const base::FilePath& downloaded_file,
    339                                      const base::FilePath& resized_directory);
    340 
    341   // Returns queue size.
    342   size_t GetPendingListSizeForTesting() const;
    343 
    344  private:
    345   friend class TestApi;
    346   friend class PendingWallpaper;
    347   friend class WallpaperManagerBrowserTest;
    348   friend class WallpaperManagerBrowserTestDefaultWallpaper;
    349   friend class WallpaperManagerPolicyTest;
    350 
    351   typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
    352 
    353 
    354   // Record data for User Metrics Analysis.
    355   static void RecordUma(User::WallpaperType type, int index);
    356 
    357   // Saves original custom wallpaper to |path| (absolute path) on filesystem
    358   // and starts resizing operation of the custom wallpaper if necessary.
    359   static void SaveCustomWallpaper(const std::string& user_id_hash,
    360                                   const base::FilePath& path,
    361                                   ash::WallpaperLayout layout,
    362                                   scoped_ptr<gfx::ImageSkia> image);
    363 
    364   // Moves custom wallpapers from |user_id| directory to |user_id_hash|
    365   // directory.
    366   static void MoveCustomWallpapersOnWorker(
    367       const std::string& user_id,
    368       const std::string& user_id_hash,
    369       base::WeakPtr<WallpaperManager> weak_ptr);
    370 
    371   // Gets |user_id|'s custom wallpaper at |wallpaper_path|. Falls back on
    372   // original custom wallpaper. When |update_wallpaper| is true, sets wallpaper
    373   // to the loaded wallpaper. Must run on wallpaper sequenced worker thread.
    374   static void GetCustomWallpaperInternal(
    375       const std::string& user_id,
    376       const WallpaperInfo& info,
    377       const base::FilePath& wallpaper_path,
    378       bool update_wallpaper,
    379       MovableOnDestroyCallbackHolder on_finish,
    380       base::WeakPtr<WallpaperManager> weak_ptr);
    381 
    382   // Resize and save customized default wallpaper.
    383   static void ResizeCustomizedDefaultWallpaper(
    384       scoped_ptr<gfx::ImageSkia> image,
    385       const UserImage::RawImage& raw_image,
    386       const CustomizedWallpaperRescaledFiles* rescaled_files,
    387       bool* success,
    388       gfx::ImageSkia* small_wallpaper_image,
    389       gfx::ImageSkia* large_wallpaper_image);
    390 
    391   // Initialize wallpaper for the specified user to default and saves this
    392   // settings in local state.
    393   void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent);
    394 
    395   // Set wallpaper to |user_image| controlled by policy.  (Takes a UserImage
    396   // because that's the callback interface provided by UserImageLoader.)
    397   void SetPolicyControlledWallpaper(const std::string& user_id,
    398                                     const UserImage& user_image);
    399 
    400   // Gets encoded wallpaper from cache. Returns true if success.
    401   bool GetWallpaperFromCache(const std::string& user_id, gfx::ImageSkia* image);
    402 
    403   // The number of wallpapers have loaded. For test only.
    404   int loaded_wallpapers() const { return loaded_wallpapers_; }
    405 
    406   // Cache some (or all) logged in users' wallpapers to memory at login
    407   // screen. It should not compete with first wallpaper loading when boot
    408   // up/initialize login WebUI page.
    409   // There are two ways the first wallpaper might be loaded:
    410   // 1. Loaded on boot. Login WebUI waits for it.
    411   // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded
    412   // right away and in 500ms after. Wallpaper started to load.
    413   // For case 2, should_cache_wallpaper_ is used to indicate if we need to
    414   // cache wallpapers on wallpaper animation finished. The cache operation
    415   // should be only executed once.
    416   void CacheUsersWallpapers();
    417 
    418   // Caches |user_id|'s wallpaper to memory.
    419   void CacheUserWallpaper(const std::string& user_id);
    420 
    421   // Clears disposable ONLINE and CUSTOM wallpaper cache. At multi profile
    422   // world, logged in users' wallpaper cache is not disposable.
    423   void ClearDisposableWallpaperCache();
    424 
    425   // Clears all obsolete wallpaper prefs from old version wallpaper pickers.
    426   void ClearObsoleteWallpaperPrefs();
    427 
    428   // Deletes all |user_id| related custom wallpapers and directories.
    429   void DeleteUserWallpapers(const std::string& user_id,
    430                             const std::string& path_to_file);
    431 
    432   // Gets the CommandLine representing the current process's command line.
    433   base::CommandLine* GetCommandLine();
    434 
    435   // Initialize wallpaper of registered device after device policy is trusted.
    436   // Note that before device is enrolled, it proceeds with untrusted setting.
    437   void InitializeRegisteredDeviceWallpaper();
    438 
    439   // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets
    440   // wallpaper to the loaded wallpaper.
    441   void LoadWallpaper(const std::string& user_id,
    442                      const WallpaperInfo& info,
    443                      bool update_wallpaper,
    444                      MovableOnDestroyCallbackHolder on_finish);
    445 
    446   // Called when the original custom wallpaper is moved to the new place.
    447   // Updates the corresponding user wallpaper info.
    448   void MoveCustomWallpapersSuccess(const std::string& user_id,
    449                                    const std::string& user_id_hash);
    450 
    451   // Moves custom wallpaper to a new place. Email address was used as directory
    452   // name in the old system, this is not safe. New directory system uses
    453   // user_id_hash instead of user_id. This must be called after user_id_hash is
    454   // ready.
    455   void MoveLoggedInUserCustomWallpaper();
    456 
    457   // Gets wallpaper information of |user_id| from Local State or memory. Returns
    458   // false if wallpaper information is not found.
    459   bool GetUserWallpaperInfo(const std::string& user_id,
    460                             WallpaperInfo* info) const;
    461 
    462   // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true.
    463   // Otherwise, cache wallpaper to memory if not logged in.  (Takes a UserImage
    464   // because that's the callback interface provided by UserImageLoader.)
    465   void OnWallpaperDecoded(const std::string& user_id,
    466                           ash::WallpaperLayout layout,
    467                           bool update_wallpaper,
    468                           MovableOnDestroyCallbackHolder on_finish,
    469                           const UserImage& user_image);
    470 
    471   // Creates new PendingWallpaper request (or updates currently pending).
    472   void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed);
    473 
    474   // Sets wallpaper to default.
    475   void DoSetDefaultWallpaper(
    476       const std::string& user_id,
    477       MovableOnDestroyCallbackHolder on_finish);
    478 
    479   // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the
    480   // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread.
    481   void StartLoad(const std::string& user_id,
    482                  const WallpaperInfo& info,
    483                  bool update_wallpaper,
    484                  const base::FilePath& wallpaper_path,
    485                  MovableOnDestroyCallbackHolder on_finish);
    486 
    487   // After completed load operation, update average load time.
    488   void SaveLastLoadTime(const base::TimeDelta elapsed);
    489 
    490   // Notify all registered observers.
    491   void NotifyAnimationFinished();
    492 
    493   // Returns modifiable PendingWallpaper.
    494   // Returns pending_inactive_ or creates new PendingWallpaper if necessary.
    495   PendingWallpaper* GetPendingWallpaper(const std::string& user_id,
    496                                         bool delayed);
    497 
    498   // This is called by PendingWallpaper when load is finished.
    499   void RemovePendingWallpaperFromList(PendingWallpaper* pending);
    500 
    501   // Calculate delay for next wallpaper load.
    502   // It is usually average wallpaper load time.
    503   // If last wallpaper load happened long ago, timeout should be reduced by
    504   // the time passed after last wallpaper load. So usual user experience results
    505   // in zero delay.
    506   base::TimeDelta GetWallpaperLoadDelay() const;
    507 
    508   // This is called after we check that supplied default wallpaper files exist.
    509   void SetCustomizedDefaultWallpaperAfterCheck(
    510       const GURL& wallpaper_url,
    511       const base::FilePath& downloaded_file,
    512       scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files);
    513 
    514   // Starts rescaling of customized wallpaper.
    515   void OnCustomizedDefaultWallpaperDecoded(
    516       const GURL& wallpaper_url,
    517       scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
    518       const UserImage& user_image);
    519 
    520   // Check the result of ResizeCustomizedDefaultWallpaper and finally
    521   // apply Customized Default Wallpaper.
    522   void OnCustomizedDefaultWallpaperResized(
    523       const GURL& wallpaper_url,
    524       scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
    525       scoped_ptr<bool> success,
    526       scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
    527       scoped_ptr<gfx::ImageSkia> large_wallpaper_image);
    528 
    529   // Init |*default_*_wallpaper_file_| from given command line and
    530   // clear |default_wallpaper_image_|.
    531   void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line);
    532 
    533   // Sets wallpaper to decoded default.
    534   void OnDefaultWallpaperDecoded(const base::FilePath& path,
    535                                  const ash::WallpaperLayout layout,
    536                                  scoped_ptr<UserImage>* result,
    537                                  MovableOnDestroyCallbackHolder on_finish,
    538                                  const UserImage& user_image);
    539 
    540   // Start decoding given default wallpaper.
    541   void StartLoadAndSetDefaultWallpaper(const base::FilePath& path,
    542                                        const ash::WallpaperLayout layout,
    543                                        MovableOnDestroyCallbackHolder on_finish,
    544                                        scoped_ptr<UserImage>* result_out);
    545 
    546   // Returns wallpaper subdirectory name for current resolution.
    547   const char* GetCustomWallpaperSubdirForCurrentResolution();
    548 
    549   // Init default_wallpaper_image_ with 1x1 image of default color.
    550   void CreateSolidDefaultWallpaper();
    551 
    552   // The number of loaded wallpapers.
    553   int loaded_wallpapers_;
    554 
    555   // Sequence token associated with wallpaper operations.
    556   base::SequencedWorkerPool::SequenceToken sequence_token_;
    557 
    558   // Wallpaper sequenced task runner.
    559   scoped_refptr<base::SequencedTaskRunner> task_runner_;
    560 
    561   // The file path of current loaded/loading custom/online wallpaper.
    562   base::FilePath current_wallpaper_path_;
    563 
    564   // Loads user wallpaper from its file.
    565   scoped_refptr<UserImageLoader> wallpaper_loader_;
    566 
    567   // Logged-in user wallpaper information.
    568   WallpaperInfo current_user_wallpaper_info_;
    569 
    570   // If non-NULL, used in place of the real command line.
    571   base::CommandLine* command_line_for_testing_;
    572 
    573   // Caches wallpapers of users. Accessed only on UI thread.
    574   CustomWallpaperMap wallpaper_cache_;
    575 
    576   // The last selected user on user pod row.
    577   std::string last_selected_user_;
    578 
    579   bool should_cache_wallpaper_;
    580 
    581   scoped_ptr<CrosSettings::ObserverSubscription>
    582       show_user_name_on_signin_subscription_;
    583 
    584   base::WeakPtrFactory<WallpaperManager> weak_factory_;
    585 
    586   content::NotificationRegistrar registrar_;
    587 
    588   ObserverList<Observer> observers_;
    589 
    590   // These members are for the scheduler:
    591 
    592   // When last load attempt finished.
    593   base::Time last_load_finished_at_;
    594 
    595   // last N wallpaper loads times.
    596   std::deque<base::TimeDelta> last_load_times_;
    597 
    598   // Pointer to last inactive (waiting) entry of 'loading_' list.
    599   // NULL when there is no inactive request.
    600   PendingWallpaper* pending_inactive_;
    601 
    602   // Owns PendingWallpaper.
    603   // PendingWallpaper deletes itself from here on load complete.
    604   // All pending will be finally deleted on destroy.
    605   typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList;
    606   PendingList loading_;
    607 
    608   base::FilePath default_small_wallpaper_file_;
    609   base::FilePath default_large_wallpaper_file_;
    610 
    611   base::FilePath guest_small_wallpaper_file_;
    612   base::FilePath guest_large_wallpaper_file_;
    613 
    614   // Current decoded default image is stored in cache.
    615   scoped_ptr<UserImage> default_wallpaper_image_;
    616 
    617   DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
    618 };
    619 
    620 }  // namespace chromeos
    621 
    622 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_
    623