OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // crbug.com/174928 | 61 // crbug.com/174928 |
62 extern const char kSmallWallpaperSuffix[]; | 62 extern const char kSmallWallpaperSuffix[]; |
63 extern const char kLargeWallpaperSuffix[]; | 63 extern const char kLargeWallpaperSuffix[]; |
64 | 64 |
65 // Directory names of custom wallpapers. | 65 // Directory names of custom wallpapers. |
66 extern const char kSmallWallpaperSubDir[]; | 66 extern const char kSmallWallpaperSubDir[]; |
67 extern const char kLargeWallpaperSubDir[]; | 67 extern const char kLargeWallpaperSubDir[]; |
68 extern const char kOriginalWallpaperSubDir[]; | 68 extern const char kOriginalWallpaperSubDir[]; |
69 extern const char kThumbnailWallpaperSubDir[]; | 69 extern const char kThumbnailWallpaperSubDir[]; |
70 | 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 |
71 // This class maintains wallpapers for users who have logged into this Chrome | 84 // This class maintains wallpapers for users who have logged into this Chrome |
72 // OS device. | 85 // OS device. |
73 class WallpaperManager: public content::NotificationObserver { | 86 class WallpaperManager: public content::NotificationObserver { |
74 public: | 87 public: |
| 88 enum WallpaperResolution { |
| 89 WALLPAPER_RESOLUTION_LARGE, |
| 90 WALLPAPER_RESOLUTION_SMALL |
| 91 }; |
| 92 |
75 // For testing. | 93 // For testing. |
76 class TestApi { | 94 class TestApi { |
77 public: | 95 public: |
78 explicit TestApi(WallpaperManager* wallpaper_manager); | 96 explicit TestApi(WallpaperManager* wallpaper_manager); |
79 virtual ~TestApi(); | 97 virtual ~TestApi(); |
80 | 98 |
81 base::FilePath current_wallpaper_path(); | 99 base::FilePath current_wallpaper_path(); |
82 | 100 |
83 bool GetWallpaperFromCache(const std::string& user_id, | 101 bool GetWallpaperFromCache(const std::string& user_id, |
84 gfx::ImageSkia* image); | 102 gfx::ImageSkia* image); |
85 | 103 |
86 void SetWallpaperCache(const std::string& user_id, | 104 void SetWallpaperCache(const std::string& user_id, |
87 const gfx::ImageSkia& image); | 105 const gfx::ImageSkia& image); |
88 | 106 |
89 void ClearDisposableWallpaperCache(); | 107 void ClearDisposableWallpaperCache(); |
90 | 108 |
91 private: | 109 private: |
92 WallpaperManager* wallpaper_manager_; // not owned | 110 WallpaperManager* wallpaper_manager_; // not owned |
93 | 111 |
94 DISALLOW_COPY_AND_ASSIGN(TestApi); | 112 DISALLOW_COPY_AND_ASSIGN(TestApi); |
95 }; | 113 }; |
96 | 114 |
97 class Observer { | 115 class Observer { |
98 public: | 116 public: |
99 virtual ~Observer() {} | 117 virtual ~Observer() {} |
100 virtual void OnWallpaperAnimationFinished(const std::string& user_id) = 0; | 118 virtual void OnWallpaperAnimationFinished(const std::string& user_id) = 0; |
| 119 virtual void OnUpdateWallpaperForTesting() {} |
101 }; | 120 }; |
102 | 121 |
103 // This is "wallpaper either scheduled to load, or loading right now". | 122 // This is "wallpaper either scheduled to load, or loading right now". |
104 // | 123 // |
105 // While enqueued, it defines moment in the future, when it will be loaded. | 124 // While enqueued, it defines moment in the future, when it will be loaded. |
106 // Enqueued but not started request might be updated by subsequent load | 125 // Enqueued but not started request might be updated by subsequent load |
107 // request. Therefore it's created empty, and updated being enqueued. | 126 // request. Therefore it's created empty, and updated being enqueued. |
108 // | 127 // |
109 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 128 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
110 // is passed to other threads by PostTask() calls, therefore it is | 129 // is passed to other threads by PostTask() calls, therefore it is |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 base::Time started_load_at_; | 183 base::Time started_load_at_; |
165 | 184 |
166 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); | 185 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); |
167 }; | 186 }; |
168 | 187 |
169 static WallpaperManager* Get(); | 188 static WallpaperManager* Get(); |
170 | 189 |
171 WallpaperManager(); | 190 WallpaperManager(); |
172 virtual ~WallpaperManager(); | 191 virtual ~WallpaperManager(); |
173 | 192 |
174 void set_command_line_for_testing(base::CommandLine* command_line) { | 193 void SetCommandLineForTesting(base::CommandLine* command_line); |
175 command_line_for_testing_ = command_line; | |
176 } | |
177 | 194 |
178 // Indicates imminent shutdown, allowing the WallpaperManager to remove any | 195 // Indicates imminent shutdown, allowing the WallpaperManager to remove any |
179 // observers it has registered. | 196 // observers it has registered. |
180 void Shutdown(); | 197 void Shutdown(); |
181 | 198 |
182 // Registers wallpaper manager preferences. | 199 // Registers wallpaper manager preferences. |
183 static void RegisterPrefs(PrefRegistrySimple* registry); | 200 static void RegisterPrefs(PrefRegistrySimple* registry); |
184 | 201 |
185 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | 202 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. |
186 void AddObservers(); | 203 void AddObservers(); |
(...skipping 30 matching lines...) Expand all Loading... |
217 | 234 |
218 // Removes all |user_id| related wallpaper info and saved wallpapers. | 235 // Removes all |user_id| related wallpaper info and saved wallpapers. |
219 void RemoveUserWallpaperInfo(const std::string& user_id); | 236 void RemoveUserWallpaperInfo(const std::string& user_id); |
220 | 237 |
221 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 238 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
222 // and |preferred_height| while maintaining aspect ratio. | 239 // and |preferred_height| while maintaining aspect ratio. |
223 bool ResizeWallpaper(const UserImage& wallpaper, | 240 bool ResizeWallpaper(const UserImage& wallpaper, |
224 ash::WallpaperLayout layout, | 241 ash::WallpaperLayout layout, |
225 int preferred_width, | 242 int preferred_width, |
226 int preferred_height, | 243 int preferred_height, |
227 scoped_refptr<base::RefCountedBytes>* output) const; | 244 scoped_refptr<base::RefCountedBytes>* output, |
| 245 gfx::ImageSkia* output_skia) const; |
228 | 246 |
229 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 247 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
230 // and |preferred_height| while maintaining aspect ratio. And saves the | 248 // and |preferred_height| while maintaining aspect ratio. And saves the |
231 // resized wallpaper to |path|. | 249 // resized wallpaper to |path|. |result| is optional (may be NULL). |
232 void ResizeAndSaveWallpaper(const UserImage& wallpaper, | 250 // Returns true on success. |
| 251 bool ResizeAndSaveWallpaper(const UserImage& wallpaper, |
233 const base::FilePath& path, | 252 const base::FilePath& path, |
234 ash::WallpaperLayout layout, | 253 ash::WallpaperLayout layout, |
235 int preferred_width, | 254 int preferred_width, |
236 int preferred_height) const; | 255 int preferred_height, |
| 256 gfx::ImageSkia* result_out) const; |
237 | 257 |
238 // Saves custom wallpaper to file, post task to generate thumbnail and updates | 258 // Saves custom wallpaper to file, post task to generate thumbnail and updates |
239 // local state preferences. If |update_wallpaper| is false, don't change | 259 // local state preferences. If |update_wallpaper| is false, don't change |
240 // wallpaper but only update cache. | 260 // wallpaper but only update cache. |
241 void SetCustomWallpaper(const std::string& user_id, | 261 void SetCustomWallpaper(const std::string& user_id, |
242 const std::string& user_id_hash, | 262 const std::string& user_id_hash, |
243 const std::string& file, | 263 const std::string& file, |
244 ash::WallpaperLayout layout, | 264 ash::WallpaperLayout layout, |
245 User::WallpaperType type, | 265 User::WallpaperType type, |
246 const UserImage& wallpaper, | 266 const UserImage& wallpaper, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 318 |
299 // Called when the wallpaper policy has been cleared for |user_id|. | 319 // Called when the wallpaper policy has been cleared for |user_id|. |
300 void OnPolicyCleared(const std::string& policy, const std::string& user_id); | 320 void OnPolicyCleared(const std::string& policy, const std::string& user_id); |
301 | 321 |
302 // Called when the policy-set wallpaper has been fetched. Initiates decoding | 322 // Called when the policy-set wallpaper has been fetched. Initiates decoding |
303 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | 323 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). |
304 void OnPolicyFetched(const std::string& policy, | 324 void OnPolicyFetched(const std::string& policy, |
305 const std::string& user_id, | 325 const std::string& user_id, |
306 scoped_ptr<std::string> data); | 326 scoped_ptr<std::string> data); |
307 | 327 |
| 328 // Returns the appropriate wallpaper resolution for all root windows. |
| 329 static WallpaperResolution GetAppropriateResolution(); |
| 330 |
308 private: | 331 private: |
309 friend class TestApi; | 332 friend class TestApi; |
310 friend class WallpaperManagerBrowserTest; | 333 friend class WallpaperManagerBrowserTest; |
| 334 friend class WallpaperManagerBrowserTestDefaultWallpaper; |
311 friend class WallpaperManagerPolicyTest; | 335 friend class WallpaperManagerPolicyTest; |
312 | 336 |
313 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 337 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
314 | 338 |
315 // Set |wallpaper| controlled by policy. | 339 // Set |wallpaper| controlled by policy. |
316 void SetPolicyControlledWallpaper(const std::string& user_id, | 340 void SetPolicyControlledWallpaper(const std::string& user_id, |
317 const UserImage& wallpaper); | 341 const UserImage& wallpaper); |
318 | 342 |
319 // Gets encoded wallpaper from cache. Returns true if success. | 343 // Gets encoded wallpaper from cache. Returns true if success. |
320 bool GetWallpaperFromCache(const std::string& user_id, | 344 bool GetWallpaperFromCache(const std::string& user_id, |
(...skipping 28 matching lines...) Expand all Loading... |
349 | 373 |
350 // Deletes all |user_id| related custom wallpapers and directories. | 374 // Deletes all |user_id| related custom wallpapers and directories. |
351 void DeleteUserWallpapers(const std::string& user_id, | 375 void DeleteUserWallpapers(const std::string& user_id, |
352 const std::string& path_to_file); | 376 const std::string& path_to_file); |
353 | 377 |
354 // Creates all new custom wallpaper directories for |user_id_hash| if not | 378 // Creates all new custom wallpaper directories for |user_id_hash| if not |
355 // exist. | 379 // exist. |
356 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); | 380 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); |
357 | 381 |
358 // Gets the CommandLine representing the current process's command line. | 382 // Gets the CommandLine representing the current process's command line. |
359 base::CommandLine* GetComandLine(); | 383 base::CommandLine* GetCommandLine(); |
360 | 384 |
361 // Initialize wallpaper of registered device after device policy is trusted. | 385 // Initialize wallpaper of registered device after device policy is trusted. |
362 // Note that before device is enrolled, it proceeds with untrusted setting. | 386 // Note that before device is enrolled, it proceeds with untrusted setting. |
363 void InitializeRegisteredDeviceWallpaper(); | 387 void InitializeRegisteredDeviceWallpaper(); |
364 | 388 |
365 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets | 389 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets |
366 // wallpaper to the loaded wallpaper. | 390 // wallpaper to the loaded wallpaper. |
367 void LoadWallpaper(const std::string& user_id, | 391 void LoadWallpaper(const std::string& user_id, |
368 const WallpaperInfo& info, | 392 const WallpaperInfo& info, |
369 bool update_wallpaper, | 393 bool update_wallpaper, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 void RecordUma(User::WallpaperType type, int index) const; | 444 void RecordUma(User::WallpaperType type, int index) const; |
421 | 445 |
422 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 446 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
423 // and starts resizing operation of the custom wallpaper if necessary. | 447 // and starts resizing operation of the custom wallpaper if necessary. |
424 void SaveCustomWallpaper(const std::string& user_id_hash, | 448 void SaveCustomWallpaper(const std::string& user_id_hash, |
425 const base::FilePath& path, | 449 const base::FilePath& path, |
426 ash::WallpaperLayout layout, | 450 ash::WallpaperLayout layout, |
427 const UserImage& wallpaper); | 451 const UserImage& wallpaper); |
428 | 452 |
429 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 453 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
430 void SaveWallpaperInternal(const base::FilePath& path, const char* data, | 454 // True on success. |
| 455 bool SaveWallpaperInternal(const base::FilePath& path, |
| 456 const char* data, |
431 int size) const; | 457 int size) const; |
432 | 458 |
433 // Creates new PendingWallpaper request (or updates currently pending). | 459 // Creates new PendingWallpaper request (or updates currently pending). |
434 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 460 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
435 | 461 |
436 // Sets wallpaper to default. | 462 // Sets wallpaper to default. |
437 void DoSetDefaultWallpaper( | 463 void DoSetDefaultWallpaper( |
438 const std::string& user_id, | 464 const std::string& user_id, |
439 MovableOnDestroyCallbackHolder on_finish); | 465 MovableOnDestroyCallbackHolder on_finish); |
440 | 466 |
(...skipping 16 matching lines...) Expand all Loading... |
457 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | 483 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, |
458 bool delayed); | 484 bool delayed); |
459 | 485 |
460 // Calculate delay for next wallpaper load. | 486 // Calculate delay for next wallpaper load. |
461 // It is usually average wallpaper load time. | 487 // It is usually average wallpaper load time. |
462 // If last wallpaper load happened long ago, timeout should be reduced by | 488 // If last wallpaper load happened long ago, timeout should be reduced by |
463 // the time passed after last wallpaper load. So usual user experience results | 489 // the time passed after last wallpaper load. So usual user experience results |
464 // in zero delay. | 490 // in zero delay. |
465 base::TimeDelta GetWallpaperLoadDelay() const; | 491 base::TimeDelta GetWallpaperLoadDelay() const; |
466 | 492 |
| 493 // Init |*default_*_wallpaper_file_| from given command line and |
| 494 // clear |default_wallpaper_image_|. |
| 495 void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line); |
| 496 |
| 497 // Sets wallpaper to decoded default. |
| 498 void OnDefaultWallpaperDecoded(const base::FilePath& path, |
| 499 const ash::WallpaperLayout layout, |
| 500 scoped_ptr<UserImage>* result, |
| 501 MovableOnDestroyCallbackHolder on_finish, |
| 502 const UserImage& wallpaper); |
| 503 |
| 504 // Start decoding given default wallpaper. |
| 505 void StartLoadAndSetDefaultWallpaper(const base::FilePath& path, |
| 506 const ash::WallpaperLayout layout, |
| 507 MovableOnDestroyCallbackHolder on_finish, |
| 508 scoped_ptr<UserImage>* result_out); |
| 509 |
| 510 // Returns wallpaper subdirectory name for current resolution. |
| 511 const char* GetCustomWallpaperSubdirForCurrentResolution(); |
| 512 |
467 // The number of loaded wallpapers. | 513 // The number of loaded wallpapers. |
468 int loaded_wallpapers_; | 514 int loaded_wallpapers_; |
469 | 515 |
470 // Sequence token associated with wallpaper operations. | 516 // Sequence token associated with wallpaper operations. |
471 base::SequencedWorkerPool::SequenceToken sequence_token_; | 517 base::SequencedWorkerPool::SequenceToken sequence_token_; |
472 | 518 |
473 // Wallpaper sequenced task runner. | 519 // Wallpaper sequenced task runner. |
474 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 520 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
475 | 521 |
476 // The file path of current loaded/loading custom/online wallpaper. | 522 // The file path of current loaded/loading custom/online wallpaper. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // Pointer to last inactive (waiting) entry of 'loading_' list. | 559 // Pointer to last inactive (waiting) entry of 'loading_' list. |
514 // NULL when there is no inactive request. | 560 // NULL when there is no inactive request. |
515 PendingWallpaper* pending_inactive_; | 561 PendingWallpaper* pending_inactive_; |
516 | 562 |
517 // Owns PendingWallpaper. | 563 // Owns PendingWallpaper. |
518 // PendingWallpaper deletes itself from here on load complete. | 564 // PendingWallpaper deletes itself from here on load complete. |
519 // All pending will be finally deleted on destroy. | 565 // All pending will be finally deleted on destroy. |
520 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 566 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
521 PendingList loading_; | 567 PendingList loading_; |
522 | 568 |
| 569 base::FilePath default_small_wallpaper_file_; |
| 570 base::FilePath default_large_wallpaper_file_; |
| 571 |
| 572 base::FilePath guest_small_wallpaper_file_; |
| 573 base::FilePath guest_large_wallpaper_file_; |
| 574 |
| 575 // Current decoded default image is stored in cache. |
| 576 scoped_ptr<UserImage> default_wallpaper_image_; |
| 577 |
523 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 578 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
524 }; | 579 }; |
525 | 580 |
526 } // namespace chromeos | 581 } // namespace chromeos |
527 | 582 |
528 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 583 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
OLD | NEW |