Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager.h

Issue 208273005: If customization includes default wallpaper, download and apply it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after-review. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_small,
78 const base::FilePath& path_rescaled_large);
79
80 base::FilePath path_rescaled_small;
81 base::FilePath path_rescaled_large;
82 };
83
84 struct CustomizedWallpaperFilesExist {
85 CustomizedWallpaperFilesExist();
86
87 bool AllRescaledExist() const;
88
89 bool downloaded;
90 bool rescaled_small;
91 bool rescaled_large;
92 };
93
75 // For testing. 94 // For testing.
76 class TestApi { 95 class TestApi {
77 public: 96 public:
78 explicit TestApi(WallpaperManager* wallpaper_manager); 97 explicit TestApi(WallpaperManager* wallpaper_manager);
79 virtual ~TestApi(); 98 virtual ~TestApi();
80 99
81 base::FilePath current_wallpaper_path(); 100 base::FilePath current_wallpaper_path();
82 101
83 bool GetWallpaperFromCache(const std::string& user_id, 102 bool GetWallpaperFromCache(const std::string& user_id,
84 gfx::ImageSkia* image); 103 gfx::ImageSkia* image);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 set_command_line_for_testing(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
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 // Result is 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) 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,
247 bool update_wallpaper); 267 bool update_wallpaper);
248 268
269 // Use given files as new default wallpaper.
270 // Reloads current wallpaper, if old default was loaded.
271 void SetDefaultWallpaperPath(
272 const base::FilePath& customized_default_wallpaper_file_small,
273 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
274 const base::FilePath& customized_default_wallpaper_file_large,
275 scoped_ptr<gfx::ImageSkia> large_wallpaper_image);
276
249 // Sets wallpaper to default wallpaper (asynchronously with zero delay). 277 // Sets wallpaper to default wallpaper (asynchronously with zero delay).
250 void SetDefaultWallpaperNow(const std::string& user_id); 278 void SetDefaultWallpaperNow(const std::string& user_id);
251 279
252 // Sets wallpaper to default wallpaper (asynchronously with default delay). 280 // Sets wallpaper to default wallpaper (asynchronously with default delay).
253 void SetDefaultWallpaperDelayed(const std::string& user_id); 281 void SetDefaultWallpaperDelayed(const std::string& user_id);
254 282
255 // Initialize wallpaper for the specified user to default and saves this 283 // Initialize wallpaper for the specified user to default and saves this
256 // settings in local state. 284 // settings in local state.
257 void InitInitialUserWallpaper(const std::string& user_id, 285 void InitInitialUserWallpaper(const std::string& user_id,
258 bool is_persistent); 286 bool is_persistent);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 326
299 // Called when the wallpaper policy has been cleared for |user_id|. 327 // Called when the wallpaper policy has been cleared for |user_id|.
300 void OnPolicyCleared(const std::string& policy, const std::string& user_id); 328 void OnPolicyCleared(const std::string& policy, const std::string& user_id);
301 329
302 // Called when the policy-set wallpaper has been fetched. Initiates decoding 330 // Called when the policy-set wallpaper has been fetched. Initiates decoding
303 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper(). 331 // of the JPEG |data| with a callback to SetPolicyControlledWallpaper().
304 void OnPolicyFetched(const std::string& policy, 332 void OnPolicyFetched(const std::string& policy,
305 const std::string& user_id, 333 const std::string& user_id,
306 scoped_ptr<std::string> data); 334 scoped_ptr<std::string> data);
307 335
336 // This is called from CustomizationDocument.
337 // resized_directory - directory where resized versions are stored
338 // (must be writable)
339 void SetCustomizedDefaultWallpaper(const GURL& wallpaper_url,
340 const base::FilePath& downloaded_file,
341 const base::FilePath& resized_directory);
308 private: 342 private:
309 friend class TestApi; 343 friend class TestApi;
310 friend class WallpaperManagerBrowserTest; 344 friend class WallpaperManagerBrowserTest;
345 friend class WallpaperManagerTest;
346
311 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; 347 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
312 348
313 // Set |wallpaper| controlled by policy. 349 // Set |wallpaper| controlled by policy.
314 void SetPolicyControlledWallpaper(const std::string& user_id, 350 void SetPolicyControlledWallpaper(const std::string& user_id,
315 const UserImage& wallpaper); 351 const UserImage& wallpaper);
316 352
317 // Gets encoded wallpaper from cache. Returns true if success. 353 // Gets encoded wallpaper from cache. Returns true if success.
318 bool GetWallpaperFromCache(const std::string& user_id, 354 bool GetWallpaperFromCache(const std::string& user_id,
319 gfx::ImageSkia* wallpaper); 355 gfx::ImageSkia* wallpaper);
320 356
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 void RecordUma(User::WallpaperType type, int index) const; 454 void RecordUma(User::WallpaperType type, int index) const;
419 455
420 // Saves original custom wallpaper to |path| (absolute path) on filesystem 456 // Saves original custom wallpaper to |path| (absolute path) on filesystem
421 // and starts resizing operation of the custom wallpaper if necessary. 457 // and starts resizing operation of the custom wallpaper if necessary.
422 void SaveCustomWallpaper(const std::string& user_id_hash, 458 void SaveCustomWallpaper(const std::string& user_id_hash,
423 const base::FilePath& path, 459 const base::FilePath& path,
424 ash::WallpaperLayout layout, 460 ash::WallpaperLayout layout,
425 const UserImage& wallpaper); 461 const UserImage& wallpaper);
426 462
427 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. 463 // Saves wallpaper image raw |data| to |path| (absolute path) in file system.
428 void SaveWallpaperInternal(const base::FilePath& path, const char* data, 464 // True on success.
465 bool SaveWallpaperInternal(const base::FilePath& path,
466 const char* data,
429 int size) const; 467 int size) const;
430 468
431 // Creates new PendingWallpaper request (or updates currently pending). 469 // Creates new PendingWallpaper request (or updates currently pending).
432 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); 470 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed);
433 471
434 // Sets wallpaper to default. 472 // Sets wallpaper to default.
435 void DoSetDefaultWallpaper( 473 void DoSetDefaultWallpaper(
436 const std::string& user_id, 474 const std::string& user_id,
437 MovableOnDestroyCallbackHolder on_finish); 475 MovableOnDestroyCallbackHolder on_finish);
438 476
(...skipping 16 matching lines...) Expand all
455 PendingWallpaper* GetPendingWallpaper(const std::string& user_id, 493 PendingWallpaper* GetPendingWallpaper(const std::string& user_id,
456 bool delayed); 494 bool delayed);
457 495
458 // Calculate delay for next wallpaper load. 496 // Calculate delay for next wallpaper load.
459 // It is usually average wallpaper load time. 497 // It is usually average wallpaper load time.
460 // If last wallpaper load happened long ago, timeout should be reduced by 498 // 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 499 // the time passed after last wallpaper load. So usual user experience results
462 // in zero delay. 500 // in zero delay.
463 base::TimeDelta GetWallpaperLoadDelay() const; 501 base::TimeDelta GetWallpaperLoadDelay() const;
464 502
503 // This is called after we check that supplied default wallpaper files exist.
504 void SetCustomizedDefaultWallpaperAfterCheck(
505 const GURL& wallpaper_url,
506 const base::FilePath& downloaded_file,
507 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
508 scoped_ptr<CustomizedWallpaperFilesExist> exist);
509
510 // Starts rescaling of customized wallpaper.
511 void OnCustomizedDefaultWallpaperDecoded(
512 const GURL& wallpaper_url,
513 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
514 const UserImage& user_image);
515
516 // Resize and save customized default wallpaper.
517 void ResizeCustomizedDefaultWallpaper(
518 scoped_ptr<gfx::ImageSkia> image,
519 const UserImage::RawImage& raw_image,
520 const CustomizedWallpaperRescaledFiles* rescaled_files,
521 bool* success,
522 gfx::ImageSkia* small_wallpaper_image,
523 gfx::ImageSkia* large_wallpaper_image);
524
525 // Check the result of ResizeCustomizedDefaultWallpaper and finally
526 // apply Customized Default Wallpaper.
527 void OnCustomizedDefaultWallpaperResized(
528 const GURL& wallpaper_url,
529 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
530 scoped_ptr<bool> success,
531 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
532 scoped_ptr<gfx::ImageSkia> large_wallpaper_image);
533
534 // These global default values are used to set customized default
535 // wallpaper path in InitializeWallpaper().
536 static base::FilePath GetCustomizedWallpaperDefaultRescaledFileName(
537 const char* suffix);
538
539 // If DesktopBackgroundController should start with customized default
540 // wallpaper in InitializeWallpaper().
541 static bool ShouldUseCustomizedDefaultWallpaper();
542
543 // Init "*default_*_wallpaper_file_" from given command line.
544 void SetDefaultWallpaperPathFromCommandLine(base::CommandLine* command_line);
545
546 // Sets wallpaper to decoded default.
547 void OnDefaultWallpaperDecoded(const base::FilePath& path,
548 scoped_ptr<gfx::ImageSkia>* result,
549 MovableOnDestroyCallbackHolder on_finish,
550 const UserImage& wallpaper);
551
552 // Start decoding given default wallpaper.
553 void StartLoadAndSetDefaultWallpaper(
554 const base::FilePath& path,
555 scoped_ptr<gfx::ImageSkia>* result,
556 MovableOnDestroyCallbackHolder on_finish);
557
465 // The number of loaded wallpapers. 558 // The number of loaded wallpapers.
466 int loaded_wallpapers_; 559 int loaded_wallpapers_;
467 560
468 // Sequence token associated with wallpaper operations. 561 // Sequence token associated with wallpaper operations.
469 base::SequencedWorkerPool::SequenceToken sequence_token_; 562 base::SequencedWorkerPool::SequenceToken sequence_token_;
470 563
471 // Wallpaper sequenced task runner. 564 // Wallpaper sequenced task runner.
472 scoped_refptr<base::SequencedTaskRunner> task_runner_; 565 scoped_refptr<base::SequencedTaskRunner> task_runner_;
473 566
474 // The file path of current loaded/loading custom/online wallpaper. 567 // The file path of current loaded/loading custom/online wallpaper.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // Pointer to last inactive (waiting) entry of 'loading_' list. 604 // Pointer to last inactive (waiting) entry of 'loading_' list.
512 // NULL when there is no inactive request. 605 // NULL when there is no inactive request.
513 PendingWallpaper* pending_inactive_; 606 PendingWallpaper* pending_inactive_;
514 607
515 // Owns PendingWallpaper. 608 // Owns PendingWallpaper.
516 // PendingWallpaper deletes itself from here on load complete. 609 // PendingWallpaper deletes itself from here on load complete.
517 // All pending will be finally deleted on destroy. 610 // All pending will be finally deleted on destroy.
518 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; 611 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList;
519 PendingList loading_; 612 PendingList loading_;
520 613
614 base::FilePath default_small_wallpaper_file_;
615 base::FilePath default_large_wallpaper_file_;
616
617 base::FilePath guest_default_small_wallpaper_file_;
618 base::FilePath guest_default_large_wallpaper_file_;
619
620 // Decoded default images are stored here.
621 scoped_ptr<gfx::ImageSkia> default_small_wallpaper_image_;
622 scoped_ptr<gfx::ImageSkia> default_large_wallpaper_image_;
623 scoped_ptr<gfx::ImageSkia> guest_default_small_wallpaper_image_;
624 scoped_ptr<gfx::ImageSkia> guest_default_large_wallpaper_image_;
625
521 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); 626 DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
522 }; 627 };
523 628
524 } // namespace chromeos 629 } // namespace chromeos
525 630
526 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ 631 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_location_monitor.cc ('k') | chrome/browser/chromeos/login/wallpaper_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698