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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // This class maintains wallpapers for users who have logged into this Chrome | 71 // This class maintains wallpapers for users who have logged into this Chrome |
72 // OS device. | 72 // OS device. |
73 class WallpaperManager: public content::NotificationObserver { | 73 class WallpaperManager: public content::NotificationObserver { |
74 public: | 74 public: |
75 struct CustomizedWallpaperRescaledFiles { | |
76 CustomizedWallpaperRescaledFiles( | |
77 const base::FilePath& path_rescaled_original, | |
78 const base::FilePath& path_rescaled_small, | |
79 const base::FilePath& path_rescaled_large); | |
80 | |
81 base::FilePath path_rescaled_original; | |
82 base::FilePath path_rescaled_small; | |
83 base::FilePath path_rescaled_large; | |
84 }; | |
85 | |
86 struct CustomizedWallpaperFilesExist { | |
87 CustomizedWallpaperFilesExist(); | |
88 | |
89 bool AllRescaledExist() const; | |
90 | |
91 bool dowloaded; | |
Daniel Erat
2014/03/25 21:58:29
s/dowloaded/downloaded/
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
92 bool rescaled_original; | |
93 bool rescaled_small; | |
94 bool rescaled_large; | |
95 }; | |
96 | |
75 // For testing. | 97 // For testing. |
76 class TestApi { | 98 class TestApi { |
77 public: | 99 public: |
78 explicit TestApi(WallpaperManager* wallpaper_manager); | 100 explicit TestApi(WallpaperManager* wallpaper_manager); |
79 virtual ~TestApi(); | 101 virtual ~TestApi(); |
80 | 102 |
81 base::FilePath current_wallpaper_path(); | 103 base::FilePath current_wallpaper_path(); |
82 | 104 |
83 bool GetWallpaperFromCache(const std::string& user_id, | 105 bool GetWallpaperFromCache(const std::string& user_id, |
84 gfx::ImageSkia* image); | 106 gfx::ImageSkia* image); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 base::Time started_load_at_; | 186 base::Time started_load_at_; |
165 | 187 |
166 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); | 188 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); |
167 }; | 189 }; |
168 | 190 |
169 static WallpaperManager* Get(); | 191 static WallpaperManager* Get(); |
170 | 192 |
171 WallpaperManager(); | 193 WallpaperManager(); |
172 virtual ~WallpaperManager(); | 194 virtual ~WallpaperManager(); |
173 | 195 |
174 void set_command_line_for_testing(base::CommandLine* command_line) { | 196 void set_command_line_for_testing(base::CommandLine* command_line); |
175 command_line_for_testing_ = command_line; | |
176 } | |
177 | 197 |
178 // Indicates imminent shutdown, allowing the WallpaperManager to remove any | 198 // Indicates imminent shutdown, allowing the WallpaperManager to remove any |
179 // observers it has registered. | 199 // observers it has registered. |
180 void Shutdown(); | 200 void Shutdown(); |
181 | 201 |
182 // Registers wallpaper manager preferences. | 202 // Registers wallpaper manager preferences. |
183 static void RegisterPrefs(PrefRegistrySimple* registry); | 203 static void RegisterPrefs(PrefRegistrySimple* registry); |
184 | 204 |
185 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | 205 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. |
186 void AddObservers(); | 206 void AddObservers(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 // and |preferred_height| while maintaining aspect ratio. | 242 // and |preferred_height| while maintaining aspect ratio. |
223 bool ResizeWallpaper(const UserImage& wallpaper, | 243 bool ResizeWallpaper(const UserImage& wallpaper, |
224 ash::WallpaperLayout layout, | 244 ash::WallpaperLayout layout, |
225 int preferred_width, | 245 int preferred_width, |
226 int preferred_height, | 246 int preferred_height, |
227 scoped_refptr<base::RefCountedBytes>* output) const; | 247 scoped_refptr<base::RefCountedBytes>* output) const; |
228 | 248 |
229 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 249 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
230 // and |preferred_height| while maintaining aspect ratio. And saves the | 250 // and |preferred_height| while maintaining aspect ratio. And saves the |
231 // resized wallpaper to |path|. | 251 // resized wallpaper to |path|. |
232 void ResizeAndSaveWallpaper(const UserImage& wallpaper, | 252 // Result is true on success. |
253 bool ResizeAndSaveWallpaper(const UserImage& wallpaper, | |
233 const base::FilePath& path, | 254 const base::FilePath& path, |
234 ash::WallpaperLayout layout, | 255 ash::WallpaperLayout layout, |
235 int preferred_width, | 256 int preferred_width, |
236 int preferred_height) const; | 257 int preferred_height) const; |
237 | 258 |
238 // Saves custom wallpaper to file, post task to generate thumbnail and updates | 259 // Saves custom wallpaper to file, post task to generate thumbnail and updates |
239 // local state preferences. If |update_wallpaper| is false, don't change | 260 // local state preferences. If |update_wallpaper| is false, don't change |
240 // wallpaper but only update cache. | 261 // wallpaper but only update cache. |
241 void SetCustomWallpaper(const std::string& user_id, | 262 void SetCustomWallpaper(const std::string& user_id, |
242 const std::string& user_id_hash, | 263 const std::string& user_id_hash, |
243 const std::string& file, | 264 const std::string& file, |
244 ash::WallpaperLayout layout, | 265 ash::WallpaperLayout layout, |
245 User::WallpaperType type, | 266 User::WallpaperType type, |
246 const UserImage& wallpaper, | 267 const UserImage& wallpaper, |
247 bool update_wallpaper); | 268 bool update_wallpaper); |
248 | 269 |
270 // Use given files as new default wallpaper. | |
271 // Reloads current wallpaper, if old default was loaded. | |
272 void SetDefaultWallpaperPath( | |
273 const base::FilePath& customized_default_wallpaper_file_small, | |
274 const base::FilePath& customized_default_wallpaper_file_large); | |
275 | |
249 // Sets wallpaper to default wallpaper (asynchronously with zero delay). | 276 // Sets wallpaper to default wallpaper (asynchronously with zero delay). |
250 void SetDefaultWallpaperNow(const std::string& user_id); | 277 void SetDefaultWallpaperNow(const std::string& user_id); |
251 | 278 |
252 // Sets wallpaper to default wallpaper (asynchronously with default delay). | 279 // Sets wallpaper to default wallpaper (asynchronously with default delay). |
253 void SetDefaultWallpaperDelayed(const std::string& user_id); | 280 void SetDefaultWallpaperDelayed(const std::string& user_id); |
254 | 281 |
255 // Initialize wallpaper for the specified user to default and saves this | 282 // Initialize wallpaper for the specified user to default and saves this |
256 // settings in local state. | 283 // settings in local state. |
257 void InitInitialUserWallpaper(const std::string& user_id, | 284 void InitInitialUserWallpaper(const std::string& user_id, |
258 bool is_persistent); | 285 bool is_persistent); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 325 |
299 // Called when the wallpaper policy has been cleared for |user_id|. | 326 // Called when the wallpaper policy has been cleared for |user_id|. |
300 void OnPolicyCleared(const std::string& policy, const std::string& user_id); | 327 void OnPolicyCleared(const std::string& policy, const std::string& user_id); |
301 | 328 |
302 // Called when the policy-set wallpaper has been fetched. Initiates decoding | 329 // Called when the policy-set wallpaper has been fetched. Initiates decoding |
303 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). | 330 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). |
304 void OnPolicyFetched(const std::string& policy, | 331 void OnPolicyFetched(const std::string& policy, |
305 const std::string& user_id, | 332 const std::string& user_id, |
306 scoped_ptr<std::string> data); | 333 scoped_ptr<std::string> data); |
307 | 334 |
335 // This is called from CustomizationDocument. | |
336 // scaled_directory - directory where resized versions are stored | |
Daniel Erat
2014/03/25 21:58:29
this comment seems outdated
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
337 // (must be writable) | |
338 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url, | |
339 const base::FilePath& downloaded_file, | |
340 const base::FilePath& resized_directory); | |
308 private: | 341 private: |
309 friend class TestApi; | 342 friend class TestApi; |
310 friend class WallpaperManagerBrowserTest; | 343 friend class WallpaperManagerBrowserTest; |
344 friend class WallpaperManagerTest; | |
345 | |
311 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 346 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
312 | 347 |
313 // Set |wallpaper| controlled by policy. | 348 // Set |wallpaper| controlled by policy. |
314 void SetPolicyControlledWallpaper(const std::string& user_id, | 349 void SetPolicyControlledWallpaper(const std::string& user_id, |
315 const UserImage& wallpaper); | 350 const UserImage& wallpaper); |
316 | 351 |
317 // Gets encoded wallpaper from cache. Returns true if success. | 352 // Gets encoded wallpaper from cache. Returns true if success. |
318 bool GetWallpaperFromCache(const std::string& user_id, | 353 bool GetWallpaperFromCache(const std::string& user_id, |
319 gfx::ImageSkia* wallpaper); | 354 gfx::ImageSkia* wallpaper); |
320 | 355 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 void RecordUma(User::WallpaperType type, int index) const; | 453 void RecordUma(User::WallpaperType type, int index) const; |
419 | 454 |
420 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 455 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
421 // and starts resizing operation of the custom wallpaper if necessary. | 456 // and starts resizing operation of the custom wallpaper if necessary. |
422 void SaveCustomWallpaper(const std::string& user_id_hash, | 457 void SaveCustomWallpaper(const std::string& user_id_hash, |
423 const base::FilePath& path, | 458 const base::FilePath& path, |
424 ash::WallpaperLayout layout, | 459 ash::WallpaperLayout layout, |
425 const UserImage& wallpaper); | 460 const UserImage& wallpaper); |
426 | 461 |
427 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 462 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
428 void SaveWallpaperInternal(const base::FilePath& path, const char* data, | 463 // True on success. |
464 bool SaveWallpaperInternal(const base::FilePath& path, | |
465 const char* data, | |
429 int size) const; | 466 int size) const; |
430 | 467 |
431 // Creates new PendingWallpaper request (or updates currently pending). | 468 // Creates new PendingWallpaper request (or updates currently pending). |
432 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 469 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
433 | 470 |
434 // Sets wallpaper to default. | 471 // Sets wallpaper to default. |
435 void DoSetDefaultWallpaper( | 472 void DoSetDefaultWallpaper( |
436 const std::string& user_id, | 473 const std::string& user_id, |
437 MovableOnDestroyCallbackHolder on_finish); | 474 MovableOnDestroyCallbackHolder on_finish); |
438 | 475 |
(...skipping 16 matching lines...) Expand all Loading... | |
455 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, | 492 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, |
456 bool delayed); | 493 bool delayed); |
457 | 494 |
458 // Calculate delay for next wallpaper load. | 495 // Calculate delay for next wallpaper load. |
459 // It is usually average wallpaper load time. | 496 // It is usually average wallpaper load time. |
460 // If last wallpaper load happened long ago, timeout should be reduced by | 497 // If last wallpaper load happened long ago, timeout should be reduced by |
461 // the time passed after last wallpaper load. So usual user experience results | 498 // the time passed after last wallpaper load. So usual user experience results |
462 // in zero delay. | 499 // in zero delay. |
463 base::TimeDelta GetWallpaperLoadDelay() const; | 500 base::TimeDelta GetWallpaperLoadDelay() const; |
464 | 501 |
502 // This is called after we check that supplied default wallpaper files exist. | |
503 void SetCustomizedDefaultWallpaperAfterCheck( | |
504 const GURL& wallpaper_url, | |
505 const base::FilePath& downloaded_file, | |
506 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
507 scoped_ptr<CustomizedWallpaperFilesExist> exist); | |
508 | |
509 // Starts rescaling of customized wallpaper. | |
510 void OnCustomizedDefaultWallpaperDecoded( | |
511 const GURL& wallpaper_url, | |
512 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
513 const UserImage& user_image); | |
514 | |
515 // Resize and save customized default wallpaper. | |
516 void ResizeCustomizedDefaultWallpaper( | |
517 scoped_ptr<gfx::ImageSkia> image, | |
518 const UserImage::RawImage& raw_image, | |
519 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
520 bool* success); | |
521 | |
522 // Check the result of ResizeCustomizedDefaultWallpaper and finally | |
523 // apply Customized Default Wallpaper. | |
524 void OnCustomizedDefaultWallpaperResized( | |
525 const GURL& wallpaper_url, | |
526 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
527 scoped_ptr<bool> success); | |
528 | |
529 // These global default values are used to set customized default | |
530 // wallpaper path in InitializeWallpaper(). | |
531 static base::FilePath GetCustomizedWallpaperDefaultRescaledFileName( | |
532 const char* suffix); | |
533 | |
534 // If DesktopBackgroundController should start with customized default | |
535 // wallpaper in InitializeWallpaper(). | |
536 static bool ShouldUseCustomizedDefaultWallpaper(); | |
537 | |
538 // Init "*default_*_wallpaper_file_" from given command line. | |
539 void SetDefaultWallpaperPathFromCommandLine(base::CommandLine* command_line); | |
540 | |
465 // The number of loaded wallpapers. | 541 // The number of loaded wallpapers. |
466 int loaded_wallpapers_; | 542 int loaded_wallpapers_; |
467 | 543 |
468 // Sequence token associated with wallpaper operations. | 544 // Sequence token associated with wallpaper operations. |
469 base::SequencedWorkerPool::SequenceToken sequence_token_; | 545 base::SequencedWorkerPool::SequenceToken sequence_token_; |
470 | 546 |
471 // Wallpaper sequenced task runner. | 547 // Wallpaper sequenced task runner. |
472 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 548 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
473 | 549 |
474 // The file path of current loaded/loading custom/online wallpaper. | 550 // The file path of current loaded/loading custom/online wallpaper. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 // Pointer to last inactive (waiting) entry of 'loading_' list. | 587 // Pointer to last inactive (waiting) entry of 'loading_' list. |
512 // NULL when there is no inactive request. | 588 // NULL when there is no inactive request. |
513 PendingWallpaper* pending_inactive_; | 589 PendingWallpaper* pending_inactive_; |
514 | 590 |
515 // Owns PendingWallpaper. | 591 // Owns PendingWallpaper. |
516 // PendingWallpaper deletes itself from here on load complete. | 592 // PendingWallpaper deletes itself from here on load complete. |
517 // All pending will be finally deleted on destroy. | 593 // All pending will be finally deleted on destroy. |
518 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 594 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
519 PendingList loading_; | 595 PendingList loading_; |
520 | 596 |
597 base::FilePath default_small_wallpaper_file_; | |
598 base::FilePath default_large_wallpaper_file_; | |
599 | |
600 base::FilePath guest_default_small_wallpaper_file_; | |
601 base::FilePath guest_default_large_wallpaper_file_; | |
602 | |
521 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 603 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
522 }; | 604 }; |
523 | 605 |
524 } // namespace chromeos | 606 } // namespace chromeos |
525 | 607 |
526 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 608 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
OLD | NEW |