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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 private: | 91 private: |
92 WallpaperManager* wallpaper_manager_; // not owned | 92 WallpaperManager* wallpaper_manager_; // not owned |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(TestApi); | 94 DISALLOW_COPY_AND_ASSIGN(TestApi); |
95 }; | 95 }; |
96 | 96 |
97 class Observer { | 97 class Observer { |
98 public: | 98 public: |
99 virtual ~Observer() {} | 99 virtual ~Observer() {} |
100 virtual void OnWallpaperAnimationFinished(const std::string& email) = 0; | 100 virtual void OnWallpaperAnimationFinished(const std::string& user_id) = 0; |
101 }; | 101 }; |
102 | 102 |
103 // This is "wallpaper either scheduled to load, or loading right now". | 103 // This is "wallpaper either scheduled to load, or loading right now". |
104 // | 104 // |
105 // While enqueued, it defines moment in the future, when it will be loaded. | 105 // 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 | 106 // Enqueued but not started request might be updated by subsequent load |
107 // request. Therefore it's created empty, and updated being enqueued. | 107 // request. Therefore it's created empty, and updated being enqueued. |
108 // | 108 // |
109 // PendingWallpaper is owned by WallpaperManager, but reference to this object | 109 // PendingWallpaper is owned by WallpaperManager, but reference to this object |
110 // is passed to other threads by PoskTask() calls, therefore it is | 110 // is passed to other threads by PoskTask() calls, therefore it is |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged | 207 // Initializes wallpaper. If logged in, loads user's wallpaper. If not logged |
208 // in, uses a solid color wallpaper. If logged in as a stub user, uses an | 208 // in, uses a solid color wallpaper. If logged in as a stub user, uses an |
209 // empty wallpaper. | 209 // empty wallpaper. |
210 void InitializeWallpaper(); | 210 void InitializeWallpaper(); |
211 | 211 |
212 // NotificationObserver overrides: | 212 // NotificationObserver overrides: |
213 virtual void Observe(int type, | 213 virtual void Observe(int type, |
214 const content::NotificationSource& source, | 214 const content::NotificationSource& source, |
215 const content::NotificationDetails& details) OVERRIDE; | 215 const content::NotificationDetails& details) OVERRIDE; |
216 | 216 |
217 // Removes all |email| related wallpaper info and saved wallpapers. | 217 // Removes all |user_id| related wallpaper info and saved wallpapers. |
218 void RemoveUserWallpaperInfo(const std::string& email); | 218 void RemoveUserWallpaperInfo(const std::string& user_id); |
219 | 219 |
220 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 220 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
221 // and |preferred_height| while maintaining aspect ratio. | 221 // and |preferred_height| while maintaining aspect ratio. |
222 bool ResizeWallpaper(const UserImage& wallpaper, | 222 bool ResizeWallpaper(const UserImage& wallpaper, |
223 ash::WallpaperLayout layout, | 223 ash::WallpaperLayout layout, |
224 int preferred_width, | 224 int preferred_width, |
225 int preferred_height, | 225 int preferred_height, |
226 scoped_refptr<base::RefCountedBytes>* output); | 226 scoped_refptr<base::RefCountedBytes>* output); |
227 | 227 |
228 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| | 228 // Resizes |wallpaper| to a resolution which is nearest to |preferred_width| |
(...skipping 27 matching lines...) Expand all Loading... |
256 | 256 |
257 // Sets selected wallpaper information for |user_id| and saves it to Local | 257 // Sets selected wallpaper information for |user_id| and saves it to Local |
258 // State if |is_persistent| is true. | 258 // State if |is_persistent| is true. |
259 void SetUserWallpaperInfo(const std::string& user_id, | 259 void SetUserWallpaperInfo(const std::string& user_id, |
260 const WallpaperInfo& info, | 260 const WallpaperInfo& info, |
261 bool is_persistent); | 261 bool is_persistent); |
262 | 262 |
263 // Sets last selected user on user pod row. | 263 // Sets last selected user on user pod row. |
264 void SetLastSelectedUser(const std::string& last_selected_user); | 264 void SetLastSelectedUser(const std::string& last_selected_user); |
265 | 265 |
266 // Sets |email|'s wallpaper (asynchronously with zero delay). | 266 // Sets |user_id|'s wallpaper (asynchronously with zero delay). |
267 void SetUserWallpaperNow(const std::string& email); | 267 void SetUserWallpaperNow(const std::string& user_id); |
268 | 268 |
269 // Sets |email|'s wallpaper (asynchronously with default delay). | 269 // Sets |user_id|'s wallpaper (asynchronously with default delay). |
270 void SetUserWallpaperDelayed(const std::string& email); | 270 void SetUserWallpaperDelayed(const std::string& user_id); |
271 | 271 |
272 // Sets wallpaper to |wallpaper| (asynchronously with zero delay). | 272 // Sets wallpaper to |wallpaper| (asynchronously with zero delay). |
273 void SetWallpaperFromImageSkia(const std::string& email, | 273 void SetWallpaperFromImageSkia(const std::string& user_id, |
274 const gfx::ImageSkia& wallpaper, | 274 const gfx::ImageSkia& wallpaper, |
275 ash::WallpaperLayout layout); | 275 ash::WallpaperLayout layout); |
276 | 276 |
277 // Updates current wallpaper. It may switch the size of wallpaper based on the | 277 // Updates current wallpaper. It may switch the size of wallpaper based on the |
278 // current display's resolution. (asynchronously with zero delay) | 278 // current display's resolution. (asynchronously with zero delay) |
279 void UpdateWallpaper(); | 279 void UpdateWallpaper(); |
280 | 280 |
281 // Adds given observer to the list. | 281 // Adds given observer to the list. |
282 void AddObserver(Observer* observer); | 282 void AddObserver(Observer* observer); |
283 | 283 |
284 // Removes given observer from the list. | 284 // Removes given observer from the list. |
285 void RemoveObserver(Observer* observer); | 285 void RemoveObserver(Observer* observer); |
286 | 286 |
287 private: | 287 private: |
288 friend class TestApi; | 288 friend class TestApi; |
289 friend class WallpaperManagerBrowserTest; | 289 friend class WallpaperManagerBrowserTest; |
290 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; | 290 typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap; |
291 | 291 |
292 // Gets encoded wallpaper from cache. Returns true if success. | 292 // Gets encoded wallpaper from cache. Returns true if success. |
293 bool GetWallpaperFromCache(const std::string& email, | 293 bool GetWallpaperFromCache(const std::string& user_id, |
294 gfx::ImageSkia* wallpaper); | 294 gfx::ImageSkia* wallpaper); |
295 | 295 |
296 // The number of wallpapers have loaded. For test only. | 296 // The number of wallpapers have loaded. For test only. |
297 int loaded_wallpapers() const { return loaded_wallpapers_; } | 297 int loaded_wallpapers() const { return loaded_wallpapers_; } |
298 | 298 |
299 // Cache some (or all) logged in users' wallpapers to memory at login | 299 // Cache some (or all) logged in users' wallpapers to memory at login |
300 // screen. It should not compete with first wallpaper loading when boot | 300 // screen. It should not compete with first wallpaper loading when boot |
301 // up/initialize login WebUI page. | 301 // up/initialize login WebUI page. |
302 // There are two ways the first wallpaper might be loaded: | 302 // There are two ways the first wallpaper might be loaded: |
303 // 1. Loaded on boot. Login WebUI waits for it. | 303 // 1. Loaded on boot. Login WebUI waits for it. |
304 // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded | 304 // 2. When flag --disable-boot-animation is passed. Login WebUI is loaded |
305 // right away and in 500ms after. Wallpaper started to load. | 305 // right away and in 500ms after. Wallpaper started to load. |
306 // For case 2, should_cache_wallpaper_ is used to indicate if we need to | 306 // For case 2, should_cache_wallpaper_ is used to indicate if we need to |
307 // cache wallpapers on wallpaper animation finished. The cache operation | 307 // cache wallpapers on wallpaper animation finished. The cache operation |
308 // should be only executed once. | 308 // should be only executed once. |
309 void CacheUsersWallpapers(); | 309 void CacheUsersWallpapers(); |
310 | 310 |
311 // Caches |email|'s wallpaper to memory. | 311 // Caches |user_id|'s wallpaper to memory. |
312 void CacheUserWallpaper(const std::string& email); | 312 void CacheUserWallpaper(const std::string& user_id); |
313 | 313 |
314 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. | 314 // Clears all obsolete wallpaper prefs from old version wallpaper pickers. |
315 void ClearObsoleteWallpaperPrefs(); | 315 void ClearObsoleteWallpaperPrefs(); |
316 | 316 |
317 // Deletes everything else except |path| in the same directory. | 317 // Deletes everything else except |path| in the same directory. |
318 void DeleteAllExcept(const base::FilePath& path); | 318 void DeleteAllExcept(const base::FilePath& path); |
319 | 319 |
320 // Deletes a list of wallpaper files in |file_list|. | 320 // Deletes a list of wallpaper files in |file_list|. |
321 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list); | 321 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list); |
322 | 322 |
323 // Deletes all |email| related custom wallpapers and directories. | 323 // Deletes all |user_id| related custom wallpapers and directories. |
324 void DeleteUserWallpapers(const std::string& email, | 324 void DeleteUserWallpapers(const std::string& user_id, |
325 const std::string& path_to_file); | 325 const std::string& path_to_file); |
326 | 326 |
327 // Creates all new custom wallpaper directories for |user_id_hash| if not | 327 // Creates all new custom wallpaper directories for |user_id_hash| if not |
328 // exist. | 328 // exist. |
329 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); | 329 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash); |
330 | 330 |
331 // Gets the CommandLine representing the current process's command line. | 331 // Gets the CommandLine representing the current process's command line. |
332 CommandLine* GetComandLine(); | 332 CommandLine* GetComandLine(); |
333 | 333 |
334 // Initialize wallpaper of registered device after device policy is trusted. | 334 // Initialize wallpaper of registered device after device policy is trusted. |
335 // Note that before device is enrolled, it proceeds with untrusted setting. | 335 // Note that before device is enrolled, it proceeds with untrusted setting. |
336 void InitializeRegisteredDeviceWallpaper(); | 336 void InitializeRegisteredDeviceWallpaper(); |
337 | 337 |
338 // Loads |email|'s wallpaper. When |update_wallpaper| is true, sets wallpaper | 338 // Loads |user_id|'s wallpaper. When |update_wallpaper| is true, sets |
339 // to the loaded wallpaper. | 339 // wallpaper to the loaded wallpaper. |
340 void LoadWallpaper(const std::string& email, | 340 void LoadWallpaper(const std::string& user_id, |
341 const WallpaperInfo& info, | 341 const WallpaperInfo& info, |
342 bool update_wallpaper, | 342 bool update_wallpaper, |
343 MovableOnDestroyCallbackHolder on_finish); | 343 MovableOnDestroyCallbackHolder on_finish); |
344 | 344 |
345 // Moves custom wallpapers from |email| directory to |user_id_hash| | 345 // Moves custom wallpapers from |user_id| directory to |user_id_hash| |
346 // directory. | 346 // directory. |
347 void MoveCustomWallpapersOnWorker(const std::string& email, | 347 void MoveCustomWallpapersOnWorker(const std::string& user_id, |
348 const std::string& user_id_hash); | 348 const std::string& user_id_hash); |
349 | 349 |
350 // Called when the original custom wallpaper is moved to the new place. | 350 // Called when the original custom wallpaper is moved to the new place. |
351 // Updates the corresponding user wallpaper info. | 351 // Updates the corresponding user wallpaper info. |
352 void MoveCustomWallpapersSuccess(const std::string& email, | 352 void MoveCustomWallpapersSuccess(const std::string& user_id, |
353 const std::string& user_id_hash); | 353 const std::string& user_id_hash); |
354 | 354 |
355 // Moves custom wallpaper to a new place. Email address was used as directory | 355 // Moves custom wallpaper to a new place. Email address was used as directory |
356 // name in the old system, this is not safe. New directory system uses | 356 // name in the old system, this is not safe. New directory system uses |
357 // user_id_hash instead of email. This must be called after user_id_hash is | 357 // user_id_hash instead of user_id. This must be called after user_id_hash is |
358 // ready. | 358 // ready. |
359 void MoveLoggedInUserCustomWallpaper(); | 359 void MoveLoggedInUserCustomWallpaper(); |
360 | 360 |
361 // Gets |email|'s custom wallpaper at |wallpaper_path|. Falls back on original | 361 // Gets |user_id|'s custom wallpaper at |wallpaper_path|. Falls back on |
362 // custom wallpaper. When |update_wallpaper| is true, sets wallpaper to the | 362 // original custom wallpaper. When |update_wallpaper| is true, sets wallpaper |
363 // loaded wallpaper. Must run on wallpaper sequenced worker thread. | 363 // to the loaded wallpaper. Must run on wallpaper sequenced worker thread. |
364 void GetCustomWallpaperInternal(const std::string& email, | 364 void GetCustomWallpaperInternal(const std::string& user_id, |
365 const WallpaperInfo& info, | 365 const WallpaperInfo& info, |
366 const base::FilePath& wallpaper_path, | 366 const base::FilePath& wallpaper_path, |
367 bool update_wallpaper, | 367 bool update_wallpaper, |
368 MovableOnDestroyCallbackHolder on_finish); | 368 MovableOnDestroyCallbackHolder on_finish); |
369 | 369 |
370 // Gets wallpaper information of |email| from Local State or memory. Returns | 370 // Gets wallpaper information of |user_id| from Local State or memory. Returns |
371 // false if wallpaper information is not found. | 371 // false if wallpaper information is not found. |
372 bool GetUserWallpaperInfo(const std::string& email, WallpaperInfo* info); | 372 bool GetUserWallpaperInfo(const std::string& user_id, WallpaperInfo* info); |
373 | 373 |
374 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. | 374 // Sets wallpaper to the decoded wallpaper if |update_wallpaper| is true. |
375 // Otherwise, cache wallpaper to memory if not logged in. | 375 // Otherwise, cache wallpaper to memory if not logged in. |
376 void OnWallpaperDecoded(const std::string& email, | 376 void OnWallpaperDecoded(const std::string& user_id, |
377 ash::WallpaperLayout layout, | 377 ash::WallpaperLayout layout, |
378 bool update_wallpaper, | 378 bool update_wallpaper, |
379 MovableOnDestroyCallbackHolder on_finish, | 379 MovableOnDestroyCallbackHolder on_finish, |
380 const UserImage& wallpaper); | 380 const UserImage& wallpaper); |
381 | 381 |
382 // Generates thumbnail of custom wallpaper on wallpaper sequenced worker | 382 // Generates thumbnail of custom wallpaper on wallpaper sequenced worker |
383 // thread. If |persistent| is true, saves original custom image and resized | 383 // thread. If |persistent| is true, saves original custom image and resized |
384 // images to disk. | 384 // images to disk. |
385 void ProcessCustomWallpaper(const std::string& user_id_hash, | 385 void ProcessCustomWallpaper(const std::string& user_id_hash, |
386 bool persistent, | 386 bool persistent, |
387 const WallpaperInfo& info, | 387 const WallpaperInfo& info, |
388 scoped_ptr<gfx::ImageSkia> image, | 388 scoped_ptr<gfx::ImageSkia> image, |
389 const UserImage::RawImage& raw_image); | 389 const UserImage::RawImage& raw_image); |
390 | 390 |
391 // Record data for User Metrics Analysis. | 391 // Record data for User Metrics Analysis. |
392 void RecordUma(User::WallpaperType type, int index); | 392 void RecordUma(User::WallpaperType type, int index); |
393 | 393 |
394 // Saves original custom wallpaper to |path| (absolute path) on filesystem | 394 // Saves original custom wallpaper to |path| (absolute path) on filesystem |
395 // and starts resizing operation of the custom wallpaper if necessary. | 395 // and starts resizing operation of the custom wallpaper if necessary. |
396 void SaveCustomWallpaper(const std::string& user_id_hash, | 396 void SaveCustomWallpaper(const std::string& user_id_hash, |
397 const base::FilePath& path, | 397 const base::FilePath& path, |
398 ash::WallpaperLayout layout, | 398 ash::WallpaperLayout layout, |
399 const UserImage& wallpaper); | 399 const UserImage& wallpaper); |
400 | 400 |
401 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. | 401 // Saves wallpaper image raw |data| to |path| (absolute path) in file system. |
402 void SaveWallpaperInternal(const base::FilePath& path, const char* data, | 402 void SaveWallpaperInternal(const base::FilePath& path, const char* data, |
403 int size); | 403 int size); |
404 | 404 |
405 // Creates new PendingWallpaper request (or updates currently pending). | 405 // Creates new PendingWallpaper request (or updates currently pending). |
406 void ScheduleSetUserWallpaper(const std::string& email, bool delayed); | 406 void ScheduleSetUserWallpaper(const std::string& user_id, bool delayed); |
407 | 407 |
408 // Sets wallpaper to default. | 408 // Sets wallpaper to default. |
409 void DoSetDefaultWallpaper( | 409 void DoSetDefaultWallpaper( |
410 const std::string& user_id, | 410 const std::string& user_id, |
411 MovableOnDestroyCallbackHolder on_finish); | 411 MovableOnDestroyCallbackHolder on_finish); |
412 | 412 |
413 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the | 413 // Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is the |
414 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. | 414 // same as |current_wallpaper_path_|, do nothing. Must be called on UI thread. |
415 void StartLoad(const std::string& email, | 415 void StartLoad(const std::string& user_id, |
416 const WallpaperInfo& info, | 416 const WallpaperInfo& info, |
417 bool update_wallpaper, | 417 bool update_wallpaper, |
418 const base::FilePath& wallpaper_path, | 418 const base::FilePath& wallpaper_path, |
419 MovableOnDestroyCallbackHolder on_finish); | 419 MovableOnDestroyCallbackHolder on_finish); |
420 | 420 |
421 // After completed load operation, update average load time. | 421 // After completed load operation, update average load time. |
422 void SaveLastLoadTime(const base::TimeDelta elapsed); | 422 void SaveLastLoadTime(const base::TimeDelta elapsed); |
423 | 423 |
424 // Notify all registed observers. | 424 // Notify all registed observers. |
425 void NotifyAnimationFinished(); | 425 void NotifyAnimationFinished(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // All pending will be finally deleted on destroy. | 491 // All pending will be finally deleted on destroy. |
492 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; | 492 typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList; |
493 PendingList loading_; | 493 PendingList loading_; |
494 | 494 |
495 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); | 495 DISALLOW_COPY_AND_ASSIGN(WallpaperManager); |
496 }; | 496 }; |
497 | 497 |
498 } // namespace chromeos | 498 } // namespace chromeos |
499 | 499 |
500 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ | 500 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ |
OLD | NEW |