OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 static bool ResizeAndSaveWallpaper(const gfx::ImageSkia& image, | 216 static bool ResizeAndSaveWallpaper(const gfx::ImageSkia& image, |
217 const base::FilePath& path, | 217 const base::FilePath& path, |
218 ash::WallpaperLayout layout, | 218 ash::WallpaperLayout layout, |
219 int preferred_width, | 219 int preferred_width, |
220 int preferred_height, | 220 int preferred_height, |
221 gfx::ImageSkia* output_skia); | 221 gfx::ImageSkia* output_skia); |
222 | 222 |
223 // Returns the appropriate wallpaper resolution for all root windows. | 223 // Returns the appropriate wallpaper resolution for all root windows. |
224 static WallpaperResolution GetAppropriateResolution(); | 224 static WallpaperResolution GetAppropriateResolution(); |
225 | 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 |
226 void SetCommandLineForTesting(base::CommandLine* command_line); | 232 void SetCommandLineForTesting(base::CommandLine* command_line); |
227 | 233 |
228 // Indicates imminent shutdown, allowing the WallpaperManager to remove any | 234 // Indicates imminent shutdown, allowing the WallpaperManager to remove any |
229 // observers it has registered. | 235 // observers it has registered. |
230 void Shutdown(); | 236 void Shutdown(); |
231 | 237 |
232 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. | 238 // Adds PowerManagerClient, TimeZoneSettings and CrosSettings observers. |
233 void AddObservers(); | 239 void AddObservers(); |
234 | 240 |
235 // Loads wallpaper asynchronously if the current wallpaper is not the | 241 // Loads wallpaper asynchronously if the current wallpaper is not the |
236 // wallpaper of logged in user. | 242 // wallpaper of logged in user. |
237 void EnsureLoggedInUserWallpaperLoaded(); | 243 void EnsureLoggedInUserWallpaperLoaded(); |
238 | 244 |
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. | 245 // Gets wallpaper information of logged in user. |
246 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); | 246 bool GetLoggedInUserWallpaperInfo(WallpaperInfo* info); |
247 | 247 |
248 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged | 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 | 249 // in, uses a solid color wallpaper. If logged in as a stub user, uses an |
250 // empty wallpaper. | 250 // empty wallpaper. |
251 void InitializeWallpaper(); | 251 void InitializeWallpaper(); |
252 | 252 |
253 // NotificationObserver overrides: | 253 // NotificationObserver overrides: |
254 virtual void Observe(int type, | 254 virtual void Observe(int type, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // must be writable. | 336 // must be writable. |
337 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url, | 337 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url, |
338 const base::FilePath& downloaded_file, | 338 const base::FilePath& downloaded_file, |
339 const base::FilePath& resized_directory); | 339 const base::FilePath& resized_directory); |
340 | 340 |
341 // Returns queue size. | 341 // Returns queue size. |
342 size_t GetPendingListSizeForTesting() const; | 342 size_t GetPendingListSizeForTesting() const; |
343 | 343 |
344 private: | 344 private: |
345 friend class TestApi; | 345 friend class TestApi; |
| 346 friend class PendingWallpaper; |
346 friend class WallpaperManagerBrowserTest; | 347 friend class WallpaperManagerBrowserTest; |
347 friend class WallpaperManagerBrowserTestDefaultWallpaper; | 348 friend class WallpaperManagerBrowserTestDefaultWallpaper; |
348 friend class WallpaperManagerPolicyTest; | 349 friend class WallpaperManagerPolicyTest; |
349 | 350 |
350 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 351 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
351 | 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 |
352 // Initialize wallpaper for the specified user to default and saves this | 391 // Initialize wallpaper for the specified user to default and saves this |
353 // settings in local state. | 392 // settings in local state. |
354 void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent); | 393 void InitInitialUserWallpaper(const std::string& user_id, bool is_persistent); |
355 | 394 |
356 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage | 395 // Set wallpaper to |user_image| controlled by policy. (Takes a UserImage |
357 // because that's the callback interface provided by UserImageLoader.) | 396 // because that's the callback interface provided by UserImageLoader.) |
358 void SetPolicyControlledWallpaper(const std::string& user_id, | 397 void SetPolicyControlledWallpaper(const std::string& user_id, |
359 const UserImage& user_image); | 398 const UserImage& user_image); |
360 | 399 |
361 // Gets encoded wallpaper from cache. Returns true if success. | 400 // Gets encoded wallpaper from cache. Returns true if success. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // Note that before device is enrolled, it proceeds with untrusted setting. | 436 // Note that before device is enrolled, it proceeds with untrusted setting. |
398 void InitializeRegisteredDeviceWallpaper(); | 437 void InitializeRegisteredDeviceWallpaper(); |
399 | 438 |
400 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets | 439 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets |
401 // wallpaper to the loaded wallpaper. | 440 // wallpaper to the loaded wallpaper. |
402 void LoadWallpaper(const std::string& user_id, | 441 void LoadWallpaper(const std::string& user_id, |
403 const WallpaperInfo& info, | 442 const WallpaperInfo& info, |
404 bool update_wallpaper, | 443 bool update_wallpaper, |
405 MovableOnDestroyCallbackHolder on_finish); | 444 MovableOnDestroyCallbackHolder on_finish); |
406 | 445 |
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. | 446 // Called when the original custom wallpaper is moved to the new place. |
413 // Updates the corresponding user wallpaper info. | 447 // Updates the corresponding user wallpaper info. |
414 void MoveCustomWallpapersSuccess(const std::string& user_id, | 448 void MoveCustomWallpapersSuccess(const std::string& user_id, |
415 const std::string& user_id_hash); | 449 const std::string& user_id_hash); |
416 | 450 |
417 // Moves custom wallpaper to a new place. Email address was used as directory | 451 // 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 | 452 // 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 | 453 // user_id_hash instead of user_id. This must be called after user_id_hash is |
420 // ready. | 454 // ready. |
421 void MoveLoggedInUserCustomWallpaper(); | 455 void MoveLoggedInUserCustomWallpaper(); |
422 | 456 |
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 | 457 // Gets wallpaper information of |user_id| from Local State or memory. Returns |
433 // false if wallpaper information is not found. | 458 // false if wallpaper information is not found. |
434 bool GetUserWallpaperInfo(const std::string& user_id, | 459 bool GetUserWallpaperInfo(const std::string& user_id, |
435 WallpaperInfo* info) const; | 460 WallpaperInfo* info) const; |
436 | 461 |
437 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 462 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
438 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage | 463 // Otherwise, cache wallpaper to memory if not logged in. (Takes a UserImage |
439 // because that's the callback interface provided by UserImageLoader.) | 464 // because that's the callback interface provided by UserImageLoader.) |
440 void OnWallpaperDecoded(const std::string& user_id, | 465 void OnWallpaperDecoded(const std::string& user_id, |
441 ash::WallpaperLayout layout, | 466 ash::WallpaperLayout layout, |
442 bool update_wallpaper, | 467 bool update_wallpaper, |
443 MovableOnDestroyCallbackHolder on_finish, | 468 MovableOnDestroyCallbackHolder on_finish, |
444 const UserImage& user_image); | 469 const UserImage& user_image); |
445 | 470 |
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). | 471 // Creates new PendingWallpaper request (or updates currently pending). |
457 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); | 472 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
458 | 473 |
459 // Sets wallpaper to default. | 474 // Sets wallpaper to default. |
460 void DoSetDefaultWallpaper( | 475 void DoSetDefaultWallpaper( |
461 const std::string& user_id, | 476 const std::string& user_id, |
462 MovableOnDestroyCallbackHolder on_finish); | 477 MovableOnDestroyCallbackHolder on_finish); |
463 | 478 |
464 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the | 479 // 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. | 480 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. |
(...skipping 29 matching lines...) Expand all Loading... |
495 const GURL& wallpaper_url, | 510 const GURL& wallpaper_url, |
496 const base::FilePath& downloaded_file, | 511 const base::FilePath& downloaded_file, |
497 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files); | 512 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files); |
498 | 513 |
499 // Starts rescaling of customized wallpaper. | 514 // Starts rescaling of customized wallpaper. |
500 void OnCustomizedDefaultWallpaperDecoded( | 515 void OnCustomizedDefaultWallpaperDecoded( |
501 const GURL& wallpaper_url, | 516 const GURL& wallpaper_url, |
502 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 517 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
503 const UserImage& user_image); | 518 const UserImage& user_image); |
504 | 519 |
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 | 520 // Check the result of ResizeCustomizedDefaultWallpaper and finally |
515 // apply Customized Default Wallpaper. | 521 // apply Customized Default Wallpaper. |
516 void OnCustomizedDefaultWallpaperResized( | 522 void OnCustomizedDefaultWallpaperResized( |
517 const GURL& wallpaper_url, | 523 const GURL& wallpaper_url, |
518 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 524 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
519 scoped_ptr<bool> success, | 525 scoped_ptr<bool> success, |
520 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 526 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
521 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); | 527 scoped_ptr<gfx::ImageSkia> large_wallpaper_image); |
522 | 528 |
523 // Init |*default_*_wallpaper_file_| from given command line and | 529 // Init |*default_*_wallpaper_file_| from given command line and |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 613 |
608 // Current decoded default image is stored in cache. | 614 // Current decoded default image is stored in cache. |
609 scoped_ptr<UserImage> default_wallpaper_image_; | 615 scoped_ptr<UserImage> default_wallpaper_image_; |
610 | 616 |
611 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 617 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
612 }; | 618 }; |
613 | 619 |
614 } // namespace chromeos | 620 } // namespace chromeos |
615 | 621 |
616 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ | 622 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_WALLPAPER_WALLPAPER_MANAGER_H_ |
OLD | NEW |