OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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_WALLPAPER_MANAGER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_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/user.h" | |
21 #include "chrome/browser/chromeos/login/user_image.h" | |
22 #include "chrome/browser/chromeos/login/user_image_loader.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 void SetCommandLineForTesting(base::CommandLine* command_line); | |
227 | |
228 // Indicates imminent shutdown, allowing the WallpaperManager to remove any | |
229 // observers it has registered. | |
230 void Shutdown(); | |
231 | |
232 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | |
233 void AddObservers(); | |
234 | |
235 // Loads wallpaper asynchronously if the current wallpaper is not the | |
236 // wallpaper of logged in user. | |
237 void EnsureLoggedInUserWallpaperLoaded(); | |
238 | |
239 // Returns custom wallpaper path. Append |sub_dir|, |user_id_hash| and |file| | |
240 // to custom wallpaper directory. | |
241 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | |
242 const std::string& user_id_hash, | |
243 const std::string& file) const; | |
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 WallpaperManagerBrowserTest; | |
347 friend class WallpaperManagerBrowserTestDefaultWallpaper; | |
348 friend class WallpaperManagerPolicyTest; | |
349 | |
350 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | |
351 | |
352 // Initialize wallpaper for the specified user to default and saves this | |
353 // settings in local state. | |
354 void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent); | |
355 | |
356 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage | |
357 // because that's the callback interface provided by UserImageLoader.) | |
358 void SetPolicyControlledWallpaper(const std::string& user_id, | |
359 const UserImage& user_image); | |
360 | |
361 // Gets encoded wallpaper from cache. Returns true if success. | |
362 bool GetWallpaperFromCache(const std::string& user_id, gfx::ImageSkia* image); | |
363 | |
364 // The number of wallpapers have loaded. For test only. | |
365 int loaded_wallpapers() const { return loaded_wallpapers_; } | |
366 | |
367 // Cache some (or all) logged in users' wallpapers to memory at login | |
368 // screen. It should not compete with first wallpaper loading when boot | |
369 // up/initialize login WebUI page. | |
370 // There are two ways the first wallpaper might be loaded: | |
371 // 1. Loaded on boot. Login WebUI waits for it. | |
372 // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded | |
373 // right away and in 500ms after. Wallpaper started to load. | |
374 // For case 2, should_cache_wallpaper_ is used to indicate if we need to | |
375 // cache wallpapers on wallpaper animation finished. The cache operation | |
376 // should be only executed once. | |
377 void CacheUsersWallpapers(); | |
378 | |
379 // Caches |user_id|'s wallpaper to memory. | |
380 void CacheUserWallpaper(const std::string& user_id); | |
381 | |
382 // Clears disposable ONLINE and CUSTOM wallpaper cache. At multi profile | |
383 // world, logged in users' wallpaper cache is not disposable. | |
384 void ClearDisposableWallpaperCache(); | |
385 | |
386 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. | |
387 void ClearObsoleteWallpaperPrefs(); | |
388 | |
389 // Deletes all |user_id| related custom wallpapers and directories. | |
390 void DeleteUserWallpapers(const std::string& user_id, | |
391 const std::string& path_to_file); | |
392 | |
393 // Gets the CommandLine representing the current process's command line. | |
394 base::CommandLine* GetCommandLine(); | |
395 | |
396 // Initialize wallpaper of registered device after device policy is trusted. | |
397 // Note that before device is enrolled, it proceeds with untrusted setting. | |
398 void InitializeRegisteredDeviceWallpaper(); | |
399 | |
400 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets | |
401 // wallpaper to the loaded wallpaper. | |
402 void LoadWallpaper(const std::string& user_id, | |
403 const WallpaperInfo& info, | |
404 bool update_wallpaper, | |
405 MovableOnDestroyCallbackHolder on_finish); | |
406 | |
407 // Moves custom wallpapers from |user_id| directory to |user_id_hash| | |
408 // directory. | |
409 void MoveCustomWallpapersOnWorker(const std::string& user_id, | |
410 const std::string& user_id_hash); | |
411 | |
412 // Called when the original custom wallpaper is moved to the new place. | |
413 // Updates the corresponding user wallpaper info. | |
414 void MoveCustomWallpapersSuccess(const std::string& user_id, | |
415 const std::string& user_id_hash); | |
416 | |
417 // Moves custom wallpaper to a new place. Email address was used as directory | |
418 // name in the old system, this is not safe. New directory system uses | |
419 // user_id_hash instead of user_id. This must be called after user_id_hash is | |
420 // ready. | |
421 void MoveLoggedInUserCustomWallpaper(); | |
422 | |
423 // Gets |user_id|'s custom wallpaper at |wallpaper_path|. Falls back on | |
424 // original custom wallpaper. When |update_wallpaper| is true, sets wallpaper | |
425 // to the loaded wallpaper. Must run on wallpaper sequenced worker thread. | |
426 void GetCustomWallpaperInternal(const std::string& user_id, | |
427 const WallpaperInfo& info, | |
428 const base::FilePath& wallpaper_path, | |
429 bool update_wallpaper, | |
430 MovableOnDestroyCallbackHolder on_finish); | |
431 | |
432 // Gets wallpaper information of |user_id| from Local State or memory. Returns | |
433 // false if wallpaper information is not found. | |
434 bool GetUserWallpaperInfo(const std::string& user_id, | |
435 WallpaperInfo* info) const; | |
436 | |
437 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | |
438 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage | |
439 // because that's the callback interface provided by UserImageLoader.) | |
440 void OnWallpaperDecoded(const std::string& user_id, | |
441 ash::WallpaperLayout layout, | |
442 bool update_wallpaper, | |
443 MovableOnDestroyCallbackHolder on_finish, | |
444 const UserImage& user_image); | |
445 | |
446 // Record data for User Metrics Analysis. | |
447 void RecordUma(User::WallpaperType type, int index) const; | |
448 | |
449 // Saves original custom wallpaper to |path| (absolute path) on filesystem | |
450 // and starts resizing operation of the custom wallpaper if necessary. | |
451 void SaveCustomWallpaper(const std::string& user_id_hash, | |
452 const base::FilePath& path, | |
453 ash::WallpaperLayout layout, | |
454 scoped_ptr<gfx::ImageSkia> image) const; | |
455 | |
456 // Creates new PendingWallpaper request (or updates currently pending). | |
457 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | |
458 | |
459 // Sets wallpaper to default. | |
460 void DoSetDefaultWallpaper( | |
461 const std::string& user_id, | |
462 MovableOnDestroyCallbackHolder on_finish); | |
463 | |
464 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the | |
465 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. | |
466 void StartLoad(const std::string& user_id, | |
467 const WallpaperInfo& info, | |
468 bool update_wallpaper, | |
469 const base::FilePath& wallpaper_path, | |
470 MovableOnDestroyCallbackHolder on_finish); | |
471 | |
472 // After completed load operation, update average load time. | |
473 void SaveLastLoadTime(const base::TimeDelta elapsed); | |
474 | |
475 // Notify all registered observers. | |
476 void NotifyAnimationFinished(); | |
477 | |
478 // Returns modifiable PendingWallpaper. | |
479 // Returns pending_inactive_ or creates new PendingWallpaper if necessary. | |
480 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | |
481 bool delayed); | |
482 | |
483 // This is called by PendingWallpaper when load is finished. | |
484 void RemovePendingWallpaperFromList(PendingWallpaper* pending); | |
485 | |
486 // Calculate delay for next wallpaper load. | |
487 // It is usually average wallpaper load time. | |
488 // If last wallpaper load happened long ago, timeout should be reduced by | |
489 // the time passed after last wallpaper load. So usual user experience results | |
490 // in zero delay. | |
491 base::TimeDelta GetWallpaperLoadDelay() const; | |
492 | |
493 // This is called after we check that supplied default wallpaper files exist. | |
494 void SetCustomizedDefaultWallpaperAfterCheck( | |
495 const GURL& wallpaper_url, | |
496 const base::FilePath& downloaded_file, | |
497 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files); | |
498 | |
499 // Starts rescaling of customized wallpaper. | |
500 void OnCustomizedDefaultWallpaperDecoded( | |
501 const GURL& wallpaper_url, | |
502 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
503 const UserImage& user_image); | |
504 | |
505 // Resize and save customized default wallpaper. | |
506 void ResizeCustomizedDefaultWallpaper( | |
507 scoped_ptr<gfx::ImageSkia> image, | |
508 const UserImage::RawImage& raw_image, | |
509 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
510 bool* success, | |
511 gfx::ImageSkia* small_wallpaper_image, | |
512 gfx::ImageSkia* large_wallpaper_image); | |
513 | |
514 // Check the result of ResizeCustomizedDefaultWallpaper and finally | |
515 // apply Customized Default Wallpaper. | |
516 void OnCustomizedDefaultWallpaperResized( | |
517 const GURL& wallpaper_url, | |
518 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
519 scoped_ptr<bool> success, | |
520 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | |
521 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); | |
522 | |
523 // Init |*default_*_wallpaper_file_| from given command line and | |
524 // clear |default_wallpaper_image_|. | |
525 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); | |
526 | |
527 // Sets wallpaper to decoded default. | |
528 void OnDefaultWallpaperDecoded(const base::FilePath& path, | |
529 const ash::WallpaperLayout layout, | |
530 scoped_ptr<UserImage>* result, | |
531 MovableOnDestroyCallbackHolder on_finish, | |
532 const UserImage& user_image); | |
533 | |
534 // Start decoding given default wallpaper. | |
535 void StartLoadAndSetDefaultWallpaper(const base::FilePath& path, | |
536 const ash::WallpaperLayout layout, | |
537 MovableOnDestroyCallbackHolder on_finish, | |
538 scoped_ptr<UserImage>* result_out); | |
539 | |
540 // Returns wallpaper subdirectory name for current resolution. | |
541 const char* GetCustomWallpaperSubdirForCurrentResolution(); | |
542 | |
543 // Init default_wallpaper_image_ with 1x1 image of default color. | |
544 void CreateSolidDefaultWallpaper(); | |
545 | |
546 // The number of loaded wallpapers. | |
547 int loaded_wallpapers_; | |
548 | |
549 // Sequence token associated with wallpaper operations. | |
550 base::SequencedWorkerPool::SequenceToken sequence_token_; | |
551 | |
552 // Wallpaper sequenced task runner. | |
553 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
554 | |
555 // The file path of current loaded/loading custom/online wallpaper. | |
556 base::FilePath current_wallpaper_path_; | |
557 | |
558 // Loads user wallpaper from its file. | |
559 scoped_refptr<UserImageLoader> wallpaper_loader_; | |
560 | |
561 // Logged-in user wallpaper information. | |
562 WallpaperInfo current_user_wallpaper_info_; | |
563 | |
564 // If non-NULL, used in place of the real command line. | |
565 base::CommandLine* command_line_for_testing_; | |
566 | |
567 // Caches wallpapers of users. Accessed only on UI thread. | |
568 CustomWallpaperMap wallpaper_cache_; | |
569 | |
570 // The last selected user on user pod row. | |
571 std::string last_selected_user_; | |
572 | |
573 bool should_cache_wallpaper_; | |
574 | |
575 scoped_ptr<CrosSettings::ObserverSubscription> | |
576 show_user_name_on_signin_subscription_; | |
577 | |
578 base::WeakPtrFactory<WallpaperManager> weak_factory_; | |
579 | |
580 content::NotificationRegistrar registrar_; | |
581 | |
582 ObserverList<Observer> observers_; | |
583 | |
584 // These members are for the scheduler: | |
585 | |
586 // When last load attempt finished. | |
587 base::Time last_load_finished_at_; | |
588 | |
589 // last N wallpaper loads times. | |
590 std::deque<base::TimeDelta> last_load_times_; | |
591 | |
592 // Pointer to last inactive (waiting) entry of 'loading_' list. | |
593 // NULL when there is no inactive request. | |
594 PendingWallpaper* pending_inactive_; | |
595 | |
596 // Owns PendingWallpaper. | |
597 // PendingWallpaper deletes itself from here on load complete. | |
598 // All pending will be finally deleted on destroy. | |
599 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | |
600 PendingList loading_; | |
601 | |
602 base::FilePath default_small_wallpaper_file_; | |
603 base::FilePath default_large_wallpaper_file_; | |
604 | |
605 base::FilePath guest_small_wallpaper_file_; | |
606 base::FilePath guest_large_wallpaper_file_; | |
607 | |
608 // Current decoded default image is stored in cache. | |
609 scoped_ptr<UserImage> default_wallpaper_image_; | |
610 | |
611 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | |
612 }; | |
613 | |
614 } // namespace chromeos | |
615 | |
616 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | |
OLD | NEW |