OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
6 | 6 |
7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 BatchUpdateWallpaper(); | 312 BatchUpdateWallpaper(); |
313 } else { | 313 } else { |
314 // Set up a one shot timer which will batch update wallpaper at midnight. | 314 // Set up a one shot timer which will batch update wallpaper at midnight. |
315 timer_.Start(FROM_HERE, | 315 timer_.Start(FROM_HERE, |
316 base::TimeDelta::FromSeconds(remaining_seconds), | 316 base::TimeDelta::FromSeconds(remaining_seconds), |
317 this, | 317 this, |
318 &WallpaperManager::BatchUpdateWallpaper); | 318 &WallpaperManager::BatchUpdateWallpaper); |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 void WallpaperManager::SaveUserWallpaperProperties(const std::string& email, | 322 void WallpaperManager::SetUserWallpaperProperties(const std::string& email, |
323 User::WallpaperType type, | 323 User::WallpaperType type, |
324 int index) { | 324 int index, |
| 325 bool is_persistent) { |
325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
326 | 327 |
327 current_user_wallpaper_type_ = type; | 328 current_user_wallpaper_type_ = type; |
328 current_user_wallpaper_index_ = index; | 329 current_user_wallpaper_index_ = index; |
329 // Ephemeral users can not save data to local state. We just cache the index | 330 if (!is_persistent) |
330 // in memory for them. | |
331 if (UserManager::Get()->IsCurrentUserEphemeral()) | |
332 return; | 331 return; |
333 | 332 |
334 PrefService* local_state = g_browser_process->local_state(); | 333 PrefService* local_state = g_browser_process->local_state(); |
335 DictionaryPrefUpdate wallpaper_update(local_state, | 334 DictionaryPrefUpdate wallpaper_update(local_state, |
336 UserManager::kUserWallpapersProperties); | 335 UserManager::kUserWallpapersProperties); |
337 | 336 |
338 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); | 337 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
339 wallpaper_properties->Set(kWallpaperTypeNodeName, | 338 wallpaper_properties->Set(kWallpaperTypeNodeName, |
340 new base::FundamentalValue(type)); | 339 new base::FundamentalValue(type)); |
341 wallpaper_properties->Set(kWallpaperIndexNodeName, | 340 wallpaper_properties->Set(kWallpaperIndexNodeName, |
(...skipping 11 matching lines...) Expand all Loading... |
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
354 | 353 |
355 // For wallpapers, save the image without resizing. | 354 // For wallpapers, save the image without resizing. |
356 wallpaper_loader_->Start( | 355 wallpaper_loader_->Start( |
357 path.value(), 0, | 356 path.value(), 0, |
358 base::Bind(&WallpaperManager::SetWallpaper, | 357 base::Bind(&WallpaperManager::SetWallpaper, |
359 base::Unretained(this), username, layout, User::CUSTOMIZED, | 358 base::Unretained(this), username, layout, User::CUSTOMIZED, |
360 delegate)); | 359 delegate)); |
361 } | 360 } |
362 | 361 |
363 void WallpaperManager::SetInitialUserWallpaper(const std::string& username) { | 362 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, |
| 363 bool is_persistent) { |
364 current_user_wallpaper_type_ = User::DEFAULT; | 364 current_user_wallpaper_type_ = User::DEFAULT; |
365 if (username == kGuestUser) | 365 if (username == kGuestUser) |
366 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); | 366 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); |
367 else | 367 else |
368 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); | 368 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); |
369 SaveUserWallpaperProperties(username, | 369 SetUserWallpaperProperties(username, |
370 current_user_wallpaper_type_, | 370 current_user_wallpaper_type_, |
371 current_user_wallpaper_index_); | 371 current_user_wallpaper_index_, |
| 372 is_persistent); |
372 | 373 |
373 // Some browser tests do not have shell instance. And it is not necessary to | 374 // Some browser tests do not have shell instance. And it is not necessary to |
374 // create a wallpaper for these tests. Add HasInstance check to prevent tests | 375 // create a wallpaper for these tests. Add HasInstance check to prevent tests |
375 // crash and speed up the tests by avoid loading wallpaper. | 376 // crash and speed up the tests by avoid loading wallpaper. |
376 if (ash::Shell::HasInstance()) { | 377 if (ash::Shell::HasInstance()) { |
377 ash::Shell::GetInstance()->desktop_background_controller()-> | 378 ash::Shell::GetInstance()->desktop_background_controller()-> |
378 SetDefaultWallpaper(current_user_wallpaper_index_, false); | 379 SetDefaultWallpaper(current_user_wallpaper_index_, false); |
379 } | 380 } |
380 } | 381 } |
381 | 382 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 418 |
418 if (!UserManager::Get()->IsKnownUser(email)) | 419 if (!UserManager::Get()->IsKnownUser(email)) |
419 return; | 420 return; |
420 | 421 |
421 User::WallpaperType type; | 422 User::WallpaperType type; |
422 int index; | 423 int index; |
423 base::Time date; | 424 base::Time date; |
424 GetUserWallpaperProperties(email, &type, &index, &date); | 425 GetUserWallpaperProperties(email, &type, &index, &date); |
425 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { | 426 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { |
426 index = ash::GetNextWallpaperIndex(index); | 427 index = ash::GetNextWallpaperIndex(index); |
427 SaveUserWallpaperProperties(email, User::DAILY, index); | 428 SetUserWallpaperProperties(email, User::DAILY, index, |
| 429 ShouldPersistDataForUser(email)); |
428 } else if (type == User::CUSTOMIZED) { | 430 } else if (type == User::CUSTOMIZED) { |
429 // For security reason, use default wallpaper instead of custom wallpaper | 431 // For security reason, use default wallpaper instead of custom wallpaper |
430 // at login screen. The security issue is tracked in issue 143198. Once it | 432 // at login screen. The security issue is tracked in issue 143198. Once it |
431 // fixed, we should then only use custom wallpaper. | 433 // fixed, we should then only use custom wallpaper. |
432 if (!UserManager::Get()->IsUserLoggedIn()) { | 434 if (!UserManager::Get()->IsUserLoggedIn()) { |
433 index = ash::GetDefaultWallpaperIndex(); | 435 index = ash::GetDefaultWallpaperIndex(); |
434 } else { | 436 } else { |
435 FetchCustomWallpaper(email); | 437 FetchCustomWallpaper(email); |
436 return; | 438 return; |
437 } | 439 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 int index = 0; | 472 int index = 0; |
471 base::Time last_modification_date; | 473 base::Time last_modification_date; |
472 const UserList& users = user_manager->GetUsers(); | 474 const UserList& users = user_manager->GetUsers(); |
473 for (UserList::const_iterator it = users.begin(); | 475 for (UserList::const_iterator it = users.begin(); |
474 it != users.end(); ++it) { | 476 it != users.end(); ++it) { |
475 std::string email = (*it)->email(); | 477 std::string email = (*it)->email(); |
476 GetUserWallpaperProperties(email, &type, &index, &last_modification_date); | 478 GetUserWallpaperProperties(email, &type, &index, &last_modification_date); |
477 base::Time current_date = base::Time::Now().LocalMidnight(); | 479 base::Time current_date = base::Time::Now().LocalMidnight(); |
478 if (type == User::DAILY && current_date != last_modification_date) { | 480 if (type == User::DAILY && current_date != last_modification_date) { |
479 index = ash::GetNextWallpaperIndex(index); | 481 index = ash::GetNextWallpaperIndex(index); |
480 SaveUserWallpaperProperties(email, type, index); | 482 SetUserWallpaperProperties(email, type, index, true); |
481 } | 483 } |
482 // Force a wallpaper update for logged in / last selected user. | 484 // Force a wallpaper update for logged in / last selected user. |
483 // TODO(bshe): Notify lock screen, wallpaper picker UI to update wallpaper | 485 // TODO(bshe): Notify lock screen, wallpaper picker UI to update wallpaper |
484 // as well. | 486 // as well. |
485 if (user_manager->IsUserLoggedIn() && | 487 if (user_manager->IsUserLoggedIn() && |
486 email == user_manager->GetLoggedInUser().email()) { | 488 email == user_manager->GetLoggedInUser().email()) { |
487 SetUserWallpaper(email); | 489 SetUserWallpaper(email); |
488 } else if (show_users && | 490 } else if (show_users && |
489 email == last_selected_user_) { | 491 email == last_selected_user_) { |
490 SetUserWallpaper(email); | 492 SetUserWallpaper(email); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 void WallpaperManager::SetWallpaper(const std::string& username, | 632 void WallpaperManager::SetWallpaper(const std::string& username, |
631 ash::WallpaperLayout layout, | 633 ash::WallpaperLayout layout, |
632 User::WallpaperType type, | 634 User::WallpaperType type, |
633 base::WeakPtr<WallpaperDelegate> delegate, | 635 base::WeakPtr<WallpaperDelegate> delegate, |
634 const UserImage& wallpaper) { | 636 const UserImage& wallpaper) { |
635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
636 | 638 |
637 std::string wallpaper_path = | 639 std::string wallpaper_path = |
638 GetWallpaperPathForUser(username, false).value(); | 640 GetWallpaperPathForUser(username, false).value(); |
639 | 641 |
640 // TODO(bshe): Ephemeral user should not save custom wallpaper to disk. | 642 bool is_persistent = ShouldPersistDataForUser(username); |
641 BrowserThread::PostTask( | 643 |
642 BrowserThread::FILE, | 644 if (is_persistent) { |
643 FROM_HERE, | 645 BrowserThread::PostTask( |
644 base::Bind(&WallpaperManager::SaveWallpaper, | 646 BrowserThread::FILE, |
645 base::Unretained(this), wallpaper_path, wallpaper)); | 647 FROM_HERE, |
| 648 base::Bind(&WallpaperManager::SaveWallpaper, |
| 649 base::Unretained(this), wallpaper_path, wallpaper)); |
| 650 } |
646 | 651 |
647 BrowserThread::PostTask( | 652 BrowserThread::PostTask( |
648 BrowserThread::FILE, | 653 BrowserThread::FILE, |
649 FROM_HERE, | 654 FROM_HERE, |
650 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail, | 655 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail, |
651 base::Unretained(this), username, type, delegate, | 656 base::Unretained(this), username, type, delegate, |
652 wallpaper.image())); | 657 wallpaper.image())); |
653 | 658 |
654 ash::Shell::GetInstance()->desktop_background_controller()-> | 659 ash::Shell::GetInstance()->desktop_background_controller()-> |
655 SetCustomWallpaper(wallpaper.image(), layout); | 660 SetCustomWallpaper(wallpaper.image(), layout); |
656 SaveUserWallpaperProperties(username, type, layout); | 661 SetUserWallpaperProperties(username, type, layout, is_persistent); |
| 662 } |
| 663 |
| 664 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) { |
| 665 UserManager* user_manager = UserManager::Get(); |
| 666 return !(email == user_manager->GetLoggedInUser().email() && |
| 667 user_manager->IsCurrentUserEphemeral()); |
657 } | 668 } |
658 | 669 |
659 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, | 670 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, |
660 const UserImage& user_image) { | 671 const UserImage& user_image) { |
661 SetWallpaperFromImageSkia(user_image.image(), layout); | 672 SetWallpaperFromImageSkia(user_image.image(), layout); |
662 } | 673 } |
663 | 674 |
664 void WallpaperManager::SystemResumed() { | 675 void WallpaperManager::SystemResumed() { |
665 BatchUpdateWallpaper(); | 676 BatchUpdateWallpaper(); |
666 } | 677 } |
667 | 678 |
668 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 679 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
669 RestartTimer(); | 680 RestartTimer(); |
670 } | 681 } |
671 | 682 |
672 } // chromeos | 683 } // chromeos |
OLD | NEW |