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

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

Issue 11308068: Remove the old wallpaper picker code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to master Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "ash/desktop_background/desktop_background_controller.h" 9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "ash/desktop_background/desktop_background_resources.h" 10 #include "ash/desktop_background/desktop_background_resources.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using content::BrowserThread; 44 using content::BrowserThread;
45 45
46 namespace { 46 namespace {
47 47
48 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; 48 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60;
49 49
50 // A dictionary pref that maps usernames to file paths to their wallpapers. 50 // A dictionary pref that maps usernames to file paths to their wallpapers.
51 // Deprecated. Will remove this const char after done migration. 51 // Deprecated. Will remove this const char after done migration.
52 const char kUserWallpapers[] = "UserWallpapers"; 52 const char kUserWallpapers[] = "UserWallpapers";
53 53
54 // Names of nodes with info about wallpaper in |kUserWallpapers| dictionary.
55 const char kWallpaperTypeNodeName[] = "type";
56 const char kWallpaperIndexNodeName[] = "index";
57 const char kWallpaperDateNodeName[] = "date";
58
59 const int kThumbnailWidth = 128; 54 const int kThumbnailWidth = 128;
60 const int kThumbnailHeight = 80; 55 const int kThumbnailHeight = 80;
61 56
62 const int kCacheWallpaperDelayMs = 500; 57 const int kCacheWallpaperDelayMs = 500;
63 58
64 // Default wallpaper index used in OOBE (first boot). 59 // Default wallpaper index used in OOBE (first boot).
65 // Defined here because Chromium default index differs. 60 // Defined here because Chromium default index differs.
66 // Also see ash::WallpaperInfo kDefaultWallpapers in 61 // Also see ash::WallpaperInfo kDefaultWallpapers in
67 // desktop_background_resources.cc 62 // desktop_background_resources.cc
68 #if defined(GOOGLE_CHROME_BUILD) 63 #if defined(GOOGLE_CHROME_BUILD)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 g_wallpaper_manager = new WallpaperManager(); 111 g_wallpaper_manager = new WallpaperManager();
117 return g_wallpaper_manager; 112 return g_wallpaper_manager;
118 } 113 }
119 114
120 WallpaperManager::WallpaperManager() 115 WallpaperManager::WallpaperManager()
121 : loaded_wallpapers_(0), 116 : loaded_wallpapers_(0),
122 ALLOW_THIS_IN_INITIALIZER_LIST(current_default_wallpaper_index_( 117 ALLOW_THIS_IN_INITIALIZER_LIST(current_default_wallpaper_index_(
123 ash::GetInvalidWallpaperIndex())), 118 ash::GetInvalidWallpaperIndex())),
124 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_( 119 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(
125 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))), 120 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))),
126 current_user_wallpaper_type_(User::UNKNOWN),
127 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
128 ash::GetInvalidWallpaperIndex())),
129 should_cache_wallpaper_(false), 121 should_cache_wallpaper_(false),
130 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 122 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
131 RestartTimer(); 123 RestartTimer();
132 registrar_.Add(this, 124 registrar_.Add(this,
133 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 125 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
134 content::NotificationService::AllSources()); 126 content::NotificationService::AllSources());
135 registrar_.Add(this, 127 registrar_.Add(this,
136 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 128 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
137 content::NotificationService::AllSources()); 129 content::NotificationService::AllSources());
138 registrar_.Add(this, 130 registrar_.Add(this,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( 200 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail(
209 const std::string& email) { 201 const std::string& email) {
210 CustomWallpaperMap::const_iterator it = 202 CustomWallpaperMap::const_iterator it =
211 custom_wallpaper_thumbnail_cache_.find(email); 203 custom_wallpaper_thumbnail_cache_.find(email);
212 if (it != custom_wallpaper_thumbnail_cache_.end()) 204 if (it != custom_wallpaper_thumbnail_cache_.end())
213 return (*it).second; 205 return (*it).second;
214 else 206 else
215 return gfx::ImageSkia(); 207 return gfx::ImageSkia();
216 } 208 }
217 209
218 void WallpaperManager::GetLoggedInUserWallpaperProperties(
219 User::WallpaperType* type,
220 int* index,
221 base::Time* last_modification_date) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223
224 if (UserManager::Get()->IsLoggedInAsStub()) {
225 *type = current_user_wallpaper_type_ = User::DEFAULT;
226 *index = current_user_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
227 return;
228 }
229
230 GetUserWallpaperProperties(UserManager::Get()->GetLoggedInUser()->email(),
231 type, index, last_modification_date);
232 }
233
234 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { 210 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 212
237 if (UserManager::Get()->IsLoggedInAsStub()) { 213 if (UserManager::Get()->IsLoggedInAsStub()) {
238 info->file = current_user_wallpaper_info_.file = ""; 214 info->file = current_user_wallpaper_info_.file = "";
239 info->layout = current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 215 info->layout = current_user_wallpaper_info_.layout = ash::CENTER_CROPPED;
240 info->type = current_user_wallpaper_info_.type = User::DEFAULT; 216 info->type = current_user_wallpaper_info_.type = User::DEFAULT;
241 return true; 217 return true;
242 } 218 }
243 219
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 304 }
329 break; 305 break;
330 } 306 }
331 default: 307 default:
332 NOTREACHED() << "Unexpected notification " << type; 308 NOTREACHED() << "Unexpected notification " << type;
333 } 309 }
334 } 310 }
335 311
336 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { 312 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) {
337 PrefService* prefs = g_browser_process->local_state(); 313 PrefService* prefs = g_browser_process->local_state();
338 DictionaryPrefUpdate prefs_wallpapers_update(prefs,
339 kUserWallpapersProperties);
340 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL);
341
342 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 314 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
343 prefs::kUsersWallpaperInfo); 315 prefs::kUsersWallpaperInfo);
344 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); 316 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL);
345 317
346 DeleteUserWallpapers(email); 318 DeleteUserWallpapers(email);
347 } 319 }
348 320
349 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, 321 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper,
350 const FilePath& path, 322 const FilePath& path,
351 ash::WallpaperLayout layout, 323 ash::WallpaperLayout layout,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // Set up a one shot timer which will batch update wallpaper at midnight. 390 // Set up a one shot timer which will batch update wallpaper at midnight.
419 timer_.Start(FROM_HERE, 391 timer_.Start(FROM_HERE,
420 base::TimeDelta::FromSeconds(remaining_seconds), 392 base::TimeDelta::FromSeconds(remaining_seconds),
421 this, 393 this,
422 &WallpaperManager::BatchUpdateWallpaper); 394 &WallpaperManager::BatchUpdateWallpaper);
423 } 395 }
424 396
425 void WallpaperManager::SetCustomWallpaper(const std::string& username, 397 void WallpaperManager::SetCustomWallpaper(const std::string& username,
426 ash::WallpaperLayout layout, 398 ash::WallpaperLayout layout,
427 User::WallpaperType type, 399 User::WallpaperType type,
428 base::WeakPtr<WallpaperDelegate> delegate,
429 const UserImage& wallpaper) { 400 const UserImage& wallpaper) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
431 402
432 std::string wallpaper_path = 403 std::string wallpaper_path =
433 GetOriginalWallpaperPathForUser(username).value(); 404 GetOriginalWallpaperPathForUser(username).value();
434 405
435 // If decoded wallpaper is empty, we are probably failed to decode the file. 406 // If decoded wallpaper is empty, we are probably failed to decode the file.
436 // Use default wallpaper in this case. 407 // Use default wallpaper in this case.
437 if (wallpaper.image().isNull()) { 408 if (wallpaper.image().isNull()) {
438 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); 409 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
(...skipping 14 matching lines...) Expand all
453 }; 424 };
454 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 425 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
455 BrowserThread::PostTask( 426 BrowserThread::PostTask(
456 BrowserThread::FILE, 427 BrowserThread::FILE,
457 FROM_HERE, 428 FROM_HERE,
458 base::Bind(&WallpaperManager::ProcessCustomWallpaper, 429 base::Bind(&WallpaperManager::ProcessCustomWallpaper,
459 base::Unretained(this), 430 base::Unretained(this),
460 username, 431 username,
461 is_persistent, 432 is_persistent,
462 wallpaper_info, 433 wallpaper_info,
463 delegate,
464 base::Passed(&deep_copy), 434 base::Passed(&deep_copy),
465 wallpaper.raw_image())); 435 wallpaper.raw_image()));
466 ash::Shell::GetInstance()->desktop_background_controller()-> 436 ash::Shell::GetInstance()->desktop_background_controller()->
467 SetCustomWallpaper(wallpaper.image(), layout); 437 SetCustomWallpaper(wallpaper.image(), layout);
468 438
469 // User's custom wallpaper path is determined by username/email and the 439 // User's custom wallpaper path is determined by username/email and the
470 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use 440 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use
471 // DUMMY as file name here. 441 // DUMMY as file name here.
472 WallpaperInfo info = { 442 WallpaperInfo info = {
473 "DUMMY", 443 "DUMMY",
474 layout, 444 layout,
475 User::CUSTOMIZED, 445 User::CUSTOMIZED,
476 base::Time::Now().LocalMidnight() 446 base::Time::Now().LocalMidnight()
477 }; 447 };
478 SetUserWallpaperInfo(username, info, is_persistent); 448 SetUserWallpaperInfo(username, info, is_persistent);
479
480 SetUserWallpaperProperties(username, type, layout, is_persistent);
481 }
482
483 void WallpaperManager::SetUserWallpaperFromFile(
484 const std::string& username,
485 const FilePath& path,
486 ash::WallpaperLayout layout,
487 base::WeakPtr<WallpaperDelegate> delegate) {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
489
490 // For wallpapers, save the image without resizing.
491 wallpaper_loader_->Start(
492 path.value(), 0,
493 base::Bind(&WallpaperManager::SetCustomWallpaper,
494 base::Unretained(this), username, layout, User::CUSTOMIZED,
495 delegate));
496 }
497
498 void WallpaperManager::SetUserWallpaperProperties(const std::string& email,
499 User::WallpaperType type,
500 int index,
501 bool is_persistent) {
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
503
504 current_user_wallpaper_type_ = type;
505 current_user_wallpaper_index_ = index;
506 if (!is_persistent)
507 return;
508
509 PrefService* local_state = g_browser_process->local_state();
510 DictionaryPrefUpdate wallpaper_update(local_state, kUserWallpapersProperties);
511
512 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
513 wallpaper_properties->Set(kWallpaperTypeNodeName,
514 new base::FundamentalValue(type));
515 wallpaper_properties->Set(kWallpaperIndexNodeName,
516 new base::FundamentalValue(index));
517 wallpaper_properties->SetString(kWallpaperDateNodeName,
518 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
519 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties);
520 } 449 }
521 450
522 void WallpaperManager::SetDefaultWallpaper(int index) { 451 void WallpaperManager::SetDefaultWallpaper(int index) {
523 // Prevents loading of the same wallpaper as the currently loading/loaded one. 452 // Prevents loading of the same wallpaper as the currently loading/loaded one.
524 if (current_default_wallpaper_index_ == index) 453 if (current_default_wallpaper_index_ == index)
525 return; 454 return;
526 current_default_wallpaper_index_ = index; 455 current_default_wallpaper_index_ = index;
527 current_wallpaper_path_ = FilePath(""); 456 current_wallpaper_path_ = FilePath("");
528 loaded_wallpapers_++; 457 loaded_wallpapers_++;
529 ash::Shell::GetInstance()->desktop_background_controller()-> 458 ash::Shell::GetInstance()->desktop_background_controller()->
530 SetDefaultWallpaper(index); 459 SetDefaultWallpaper(index);
531 } 460 }
532 461
533 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, 462 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
534 bool is_persistent) { 463 bool is_persistent) {
535 current_user_wallpaper_type_ = User::DEFAULT;
536 if (username == kGuestUser)
537 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
538 else
539 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
540
541 current_user_wallpaper_info_.file = ""; 464 current_user_wallpaper_info_.file = "";
542 current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 465 current_user_wallpaper_info_.layout = ash::CENTER_CROPPED;
543 current_user_wallpaper_info_.type = User::DEFAULT; 466 current_user_wallpaper_info_.type = User::DEFAULT;
544 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); 467 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
545 468
546 WallpaperInfo info = current_user_wallpaper_info_; 469 WallpaperInfo info = current_user_wallpaper_info_;
547 SetUserWallpaperInfo(username, info, is_persistent); 470 SetUserWallpaperInfo(username, info, is_persistent);
548 471
549 // Some browser tests do not have shell instance. And it is not necessary to 472 // Some browser tests do not have shell instance. And it is not necessary to
550 // create a wallpaper for these tests. Add HasInstance check to prevent tests 473 // create a wallpaper for these tests. Add HasInstance check to prevent tests
551 // crash and speed up the tests by avoid loading wallpaper. 474 // crash and speed up the tests by avoid loading wallpaper.
552 if (ash::Shell::HasInstance()) 475 if (ash::Shell::HasInstance()) {
553 SetDefaultWallpaper(current_user_wallpaper_index_); 476 if (username == kGuestUser)
477 SetDefaultWallpaper(ash::GetGuestWallpaperIndex());
478 else
479 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
480 }
554 } 481 }
555 482
556 void WallpaperManager::SetUserWallpaperInfo(const std::string& username, 483 void WallpaperManager::SetUserWallpaperInfo(const std::string& username,
557 const WallpaperInfo& info, 484 const WallpaperInfo& info,
558 bool is_persistent) { 485 bool is_persistent) {
559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
560 current_user_wallpaper_info_ = info; 487 current_user_wallpaper_info_ = info;
561 if (!is_persistent) 488 if (!is_persistent)
562 return; 489 return;
563 490
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 572 }
646 573
647 void WallpaperManager::UpdateWallpaper() { 574 void WallpaperManager::UpdateWallpaper() {
648 ClearWallpaperCache(); 575 ClearWallpaperCache();
649 SetUserWallpaper(last_selected_user_); 576 SetUserWallpaper(last_selected_user_);
650 } 577 }
651 578
652 // WallpaperManager, private: -------------------------------------------------- 579 // WallpaperManager, private: --------------------------------------------------
653 580
654 WallpaperManager::~WallpaperManager() { 581 WallpaperManager::~WallpaperManager() {
582 ClearObsoleteWallpaperPrefs();
655 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 583 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
656 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 584 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
657 weak_factory_.InvalidateWeakPtrs(); 585 weak_factory_.InvalidateWeakPtrs();
658 } 586 }
659 587
660 void WallpaperManager::BatchUpdateWallpaper() { 588 void WallpaperManager::BatchUpdateWallpaper() {
661 PrefService* local_state = g_browser_process->local_state(); 589 NOTIMPLEMENTED();
662 UserManager* user_manager = UserManager::Get();
663 bool show_users = true;
664 CrosSettings::Get()->GetBoolean(
665 kAccountsPrefShowUserNamesOnSignIn, &show_users);
666 if (local_state) {
667 User::WallpaperType type;
668 int index = 0;
669 base::Time last_modification_date;
670 const UserList& users = user_manager->GetUsers();
671 for (UserList::const_iterator it = users.begin();
672 it != users.end(); ++it) {
673 std::string email = (*it)->email();
674 GetUserWallpaperProperties(email, &type, &index, &last_modification_date);
675 base::Time current_date = base::Time::Now().LocalMidnight();
676 if (type == User::DAILY && current_date != last_modification_date) {
677 SetUserWallpaperProperties(email, type, index, true);
678 }
679 // Force a wallpaper update for logged in / last selected user.
680 // TODO(bshe): Notify lock screen, wallpaper picker UI to update wallpaper
681 // as well.
682 if (user_manager->IsUserLoggedIn() &&
683 email == user_manager->GetLoggedInUser()->email()) {
684 SetUserWallpaper(email);
685 } else if (show_users &&
686 email == last_selected_user_) {
687 SetUserWallpaper(email);
688 }
689 }
690 }
691 RestartTimer();
692 } 590 }
693 591
694 void WallpaperManager::CacheAllUsersWallpapers() { 592 void WallpaperManager::CacheAllUsersWallpapers() {
695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
696 UserList users = UserManager::Get()->GetUsers(); 594 UserList users = UserManager::Get()->GetUsers();
697 595
698 if (!users.empty()) { 596 if (!users.empty()) {
699 UserList::const_iterator it = users.begin(); 597 UserList::const_iterator it = users.begin();
700 // Skip the wallpaper of first user in the list. It should have been cached. 598 // Skip the wallpaper of first user in the list. It should have been cached.
701 it++; 599 it++;
(...skipping 27 matching lines...) Expand all
729 } 627 }
730 } 628 }
731 629
732 void WallpaperManager::CacheThumbnail(const std::string& email, 630 void WallpaperManager::CacheThumbnail(const std::string& email,
733 scoped_ptr<gfx::ImageSkia> wallpaper) { 631 scoped_ptr<gfx::ImageSkia> wallpaper) {
734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
735 custom_wallpaper_thumbnail_cache_[email] = 633 custom_wallpaper_thumbnail_cache_[email] =
736 GetWallpaperThumbnail(*wallpaper.get()); 634 GetWallpaperThumbnail(*wallpaper.get());
737 } 635 }
738 636
637 void WallpaperManager::ClearObsoleteWallpaperPrefs() {
638 PrefService* prefs = g_browser_process->local_state();
639 DictionaryPrefUpdate wallpaper_properties_pref(prefs,
640 kUserWallpapersProperties);
641 wallpaper_properties_pref->Clear();
642 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers);
643 wallpapers_pref->Clear();
644 }
645
739 void WallpaperManager::DeleteWallpaperInList( 646 void WallpaperManager::DeleteWallpaperInList(
740 const std::vector<FilePath>& file_list) { 647 const std::vector<FilePath>& file_list) {
741 for (std::vector<FilePath>::const_iterator it = file_list.begin(); 648 for (std::vector<FilePath>::const_iterator it = file_list.begin();
742 it != file_list.end(); ++it) { 649 it != file_list.end(); ++it) {
743 FilePath path = *it; 650 FilePath path = *it;
744 if (!file_util::Delete(path, false)) { 651 if (!file_util::Delete(path, false)) {
745 LOG(ERROR) << "Failed to remove user wallpaper."; 652 LOG(ERROR) << "Failed to remove user wallpaper.";
746 } 653 }
747 654
748 // Some users may still have wallpapers with a file extension. This will 655 // Some users may still have wallpapers with a file extension. This will
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 &date_string) && 757 &date_string) &&
851 base::StringToInt64(date_string, &val))) 758 base::StringToInt64(date_string, &val)))
852 val = 0; 759 val = 0;
853 info->date = base::Time::FromInternalValue(val); 760 info->date = base::Time::FromInternalValue(val);
854 return true; 761 return true;
855 } 762 }
856 763
857 return false; 764 return false;
858 } 765 }
859 766
860 void WallpaperManager::GetUserWallpaperProperties(const std::string& email,
861 User::WallpaperType* type,
862 int* index,
863 base::Time* last_modification_date) {
864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
865
866 // Default to the values cached in memory.
867 *type = current_user_wallpaper_type_;
868 *index = current_user_wallpaper_index_;
869
870 // Override with values found in local store, if any.
871 if (!email.empty()) {
872 const DictionaryValue* user_wallpapers = g_browser_process->local_state()->
873 GetDictionary(kUserWallpapersProperties);
874 const base::DictionaryValue* wallpaper_properties;
875 if (user_wallpapers->GetDictionaryWithoutPathExpansion(
876 email,
877 &wallpaper_properties)) {
878 *type = User::UNKNOWN;
879 *index = ash::GetInvalidWallpaperIndex();
880 wallpaper_properties->GetInteger(kWallpaperTypeNodeName,
881 reinterpret_cast<int*>(type));
882 wallpaper_properties->GetInteger(kWallpaperIndexNodeName, index);
883 std::string date_string;
884 int64 val;
885 if (!(wallpaper_properties->GetString(kWallpaperDateNodeName,
886 &date_string) &&
887 base::StringToInt64(date_string, &val)))
888 val = 0;
889 *last_modification_date = base::Time::FromInternalValue(val);
890 }
891 }
892
893 // Index maybe invalid when update from official build to unofficial build.
894 // Revert to default in that case.
895 if (*type == User::DEFAULT &&
896 (*index < 0 || *index >= ash::GetWallpaperCount())) {
897 *index = ash::GetDefaultWallpaperIndex();
898 }
899 }
900
901 void WallpaperManager::GenerateUserWallpaperThumbnail( 767 void WallpaperManager::GenerateUserWallpaperThumbnail(
902 const std::string& email, 768 const std::string& email,
903 User::WallpaperType type, 769 User::WallpaperType type,
904 base::WeakPtr<WallpaperDelegate> delegate,
905 const gfx::ImageSkia& wallpaper) { 770 const gfx::ImageSkia& wallpaper) {
906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
907 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); 772 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper);
908
909 // Notify thumbnail is ready.
910 BrowserThread::PostTask(
911 BrowserThread::UI,
912 FROM_HERE,
913 base::Bind(&WallpaperManager::OnThumbnailUpdated,
914 base::Unretained(this), delegate));
915 } 773 }
916 774
917 void WallpaperManager::GetCustomWallpaperInternal( 775 void WallpaperManager::GetCustomWallpaperInternal(
918 const std::string& email, 776 const std::string& email,
919 const WallpaperInfo& info, 777 const WallpaperInfo& info,
920 const FilePath& wallpaper_path, 778 const FilePath& wallpaper_path,
921 bool update_wallpaper) { 779 bool update_wallpaper) {
922 std::string file_name = wallpaper_path.BaseName().value(); 780 std::string file_name = wallpaper_path.BaseName().value();
923 781
924 if (!file_util::PathExists(wallpaper_path)) { 782 if (!file_util::PathExists(wallpaper_path)) {
(...skipping 14 matching lines...) Expand all
939 info.type, 797 info.type,
940 info.date 798 info.date
941 }; 799 };
942 800
943 BrowserThread::PostTask( 801 BrowserThread::PostTask(
944 BrowserThread::UI, FROM_HERE, 802 BrowserThread::UI, FROM_HERE,
945 base::Bind(&WallpaperManager::LoadWallpaper, 803 base::Bind(&WallpaperManager::LoadWallpaper,
946 base::Unretained(this), email, new_info, update_wallpaper)); 804 base::Unretained(this), email, new_info, update_wallpaper));
947 } 805 }
948 806
949 void WallpaperManager::MigrateWallpaperData(const UserList& users) {
950 PrefService* local_state = g_browser_process->local_state();
951 if (local_state) {
952 const DictionaryValue* user_wallpapers =
953 local_state->GetDictionary(kUserWallpapers);
954 int index;
955 const DictionaryValue* new_user_wallpapers =
956 local_state->GetDictionary(kUserWallpapersProperties);
957 if (new_user_wallpapers->empty()) {
958 for (UserList::const_iterator it = users.begin();
959 it != users.end();
960 ++it) {
961 std::string username = (*it)->email();
962 if (user_wallpapers->GetIntegerWithoutPathExpansion(
963 username, &index)) {
964 DictionaryPrefUpdate prefs_wallpapers_update(
965 local_state, kUserWallpapers);
966 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL);
967 SetUserWallpaperProperties(username, User::DEFAULT, index, true);
968 } else {
969 // Before M20, wallpaper index is not saved into LocalState unless
970 // user specifically sets a wallpaper. After M20, the default
971 // wallpaper index is saved to LocalState as soon as a new user login.
972 // When migrating wallpaper index from M20 to M21, we only migrate
973 // data that is in LocalState. This cause a problem when users login
974 // on a M20 device and then update the device to M21. The default
975 // wallpaper index failed to migrate because it was not saved into
976 // LocalState. Then we assume that all users have index saved in
977 // LocalState in M21. This is not true and it results an empty
978 // wallpaper for those users as described in cr/130685. So here we use
979 // default wallpaper for users that exist in user list but does not
980 // have an index saved in LocalState.
981 SetUserWallpaperProperties(
982 username, User::DEFAULT, ash::GetDefaultWallpaperIndex(), true);
983 }
984 }
985 }
986 }
987 }
988
989 void WallpaperManager::MigrateBuiltInWallpaper(const std::string& email) {
990 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
991 if (!email.empty() && UserManager::Get()->IsKnownUser(email)) {
992 PrefService* prefs = g_browser_process->local_state();
993 const DictionaryValue* user_wallpapers = prefs->
994 GetDictionary(kUserWallpapersProperties);
995 const base::DictionaryValue* wallpaper_properties;
996 User::WallpaperType type;
997 int index;
998 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
999 desktop_background_controller()->GetAppropriateResolution();
1000 if (user_wallpapers->GetDictionaryWithoutPathExpansion(email,
1001 &wallpaper_properties)) {
1002 base::Time date;
1003 GetUserWallpaperProperties(email, &type, &index, &date);
1004
1005 FilePath wallpaper_dir;
1006 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
1007 DCHECK(type != User::UNKNOWN);
1008
1009 FilePath wallpaper_path;
1010 if (type != User::CUSTOMIZED) {
1011 base::RefCountedStaticMemory* wallpaper =
1012 ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
1013 GetWallpaperViewInfo(index, ash::LARGE).id);
1014
1015 // Saves large wallpaper to user custom wallpaper path.
1016 wallpaper_path = GetWallpaperPathForUser(email, false);
1017 BrowserThread::PostTask(
1018 BrowserThread::FILE,
1019 FROM_HERE,
1020 base::Bind(&WallpaperManager::SaveWallpaperInternal,
1021 base::Unretained(this), wallpaper_path,
1022 reinterpret_cast<const char*>(wallpaper->front()),
1023 wallpaper->size()));
1024
1025 wallpaper =
1026 ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
1027 GetWallpaperViewInfo(index, ash::SMALL).id);
1028
1029 // Saves small wallpaper to user custom wallpaper thumbnail path.
1030 wallpaper_path = GetWallpaperPathForUser(email, true);
1031 BrowserThread::PostTask(
1032 BrowserThread::FILE,
1033 FROM_HERE,
1034 base::Bind(&WallpaperManager::SaveWallpaperInternal,
1035 base::Unretained(this), wallpaper_path,
1036 reinterpret_cast<const char*>(wallpaper->front()),
1037 wallpaper->size()));
1038 }
1039
1040 bool small_resolution = (resolution == ash::SMALL);
1041 std::string file_name =
1042 GetWallpaperPathForUser(email, small_resolution).BaseName().value();
1043 WallpaperInfo info = {
1044 file_name,
1045 GetWallpaperViewInfo(index, resolution).layout,
1046 type,
1047 base::Time::Now().LocalMidnight()
1048 };
1049 SetUserWallpaperInfo(email, info, true);
1050 }
1051 }
1052 }
1053
1054 void WallpaperManager::OnThumbnailUpdated(
1055 base::WeakPtr<WallpaperDelegate> delegate) {
1056 if (delegate)
1057 delegate->SetCustomWallpaperThumbnail();
1058 }
1059
1060 void WallpaperManager::OnWallpaperDecoded(const std::string& email, 807 void WallpaperManager::OnWallpaperDecoded(const std::string& email,
1061 ash::WallpaperLayout layout, 808 ash::WallpaperLayout layout,
1062 bool update_wallpaper, 809 bool update_wallpaper,
1063 const UserImage& wallpaper) { 810 const UserImage& wallpaper) {
1064 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1065 812
1066 // If decoded wallpaper is empty, we are probably failed to decode the file. 813 // If decoded wallpaper is empty, we are probably failed to decode the file.
1067 // Use default wallpaper in this case. 814 // Use default wallpaper in this case.
1068 if (wallpaper.image().isNull()) { 815 if (wallpaper.image().isNull()) {
1069 // Updates user pref to default wallpaper. 816 // Updates user pref to default wallpaper.
(...skipping 30 matching lines...) Expand all
1100 if (update_wallpaper) { 847 if (update_wallpaper) {
1101 ash::Shell::GetInstance()->desktop_background_controller()-> 848 ash::Shell::GetInstance()->desktop_background_controller()->
1102 SetCustomWallpaper(wallpaper.image(), layout); 849 SetCustomWallpaper(wallpaper.image(), layout);
1103 } 850 }
1104 } 851 }
1105 852
1106 void WallpaperManager::ProcessCustomWallpaper( 853 void WallpaperManager::ProcessCustomWallpaper(
1107 const std::string& email, 854 const std::string& email,
1108 bool persistent, 855 bool persistent,
1109 const WallpaperInfo& info, 856 const WallpaperInfo& info,
1110 base::WeakPtr<WallpaperDelegate> delegate,
1111 scoped_ptr<gfx::ImageSkia> image, 857 scoped_ptr<gfx::ImageSkia> image,
1112 const UserImage::RawImage& raw_image) { 858 const UserImage::RawImage& raw_image) {
1113 UserImage wallpaper(*image.get(), raw_image); 859 UserImage wallpaper(*image.get(), raw_image);
1114 GenerateUserWallpaperThumbnail(email, info.type, delegate, wallpaper.image()); 860 GenerateUserWallpaperThumbnail(email, info.type, wallpaper.image());
1115 if (persistent) 861 if (persistent)
1116 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); 862 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper);
1117 } 863 }
1118 864
1119 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, 865 void WallpaperManager::OnWallpaperEncoded(const FilePath& path,
1120 scoped_refptr<base::RefCountedBytes> data) { 866 scoped_refptr<base::RefCountedBytes> data) {
1121 SaveWallpaperInternal(path, 867 SaveWallpaperInternal(path,
1122 reinterpret_cast<const char*>(data->front()), 868 reinterpret_cast<const char*>(data->front()),
1123 data->size()); 869 data->size());
1124 } 870 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 FROM_HERE, 958 FROM_HERE,
1213 base::Bind(&WallpaperManager::StartLoad, 959 base::Bind(&WallpaperManager::StartLoad,
1214 base::Unretained(this), 960 base::Unretained(this),
1215 email, 961 email,
1216 info, 962 info,
1217 update_wallpaper, 963 update_wallpaper,
1218 valid_path)); 964 valid_path));
1219 } 965 }
1220 966
1221 } // chromeos 967 } // chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/resources/options/chromeos/set_wallpaper_options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698