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

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: 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // static 108 // static
114 WallpaperManager* WallpaperManager::Get() { 109 WallpaperManager* WallpaperManager::Get() {
115 if (!g_wallpaper_manager) 110 if (!g_wallpaper_manager)
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 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_( 116 : ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(
122 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))), 117 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))),
123 current_user_wallpaper_type_(User::UNKNOWN),
124 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
125 ash::GetInvalidWallpaperIndex())),
126 should_cache_wallpaper_(false), 118 should_cache_wallpaper_(false),
127 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 119 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
128 RestartTimer(); 120 RestartTimer();
129 registrar_.Add(this, 121 registrar_.Add(this,
130 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 122 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
131 content::NotificationService::AllSources()); 123 content::NotificationService::AllSources());
132 registrar_.Add(this, 124 registrar_.Add(this,
133 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 125 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
134 content::NotificationService::AllSources()); 126 content::NotificationService::AllSources());
135 registrar_.Add(this, 127 registrar_.Add(this,
(...skipping 21 matching lines...) Expand all
157 WallpaperInfo info; 149 WallpaperInfo info;
158 if (GetLoggedInUserWallpaperInfo(&info)) { 150 if (GetLoggedInUserWallpaperInfo(&info)) {
159 // TODO(sschmitz): We need an index for default wallpapers for the new UI. 151 // TODO(sschmitz): We need an index for default wallpapers for the new UI.
160 RecordUma(info.type, -1); 152 RecordUma(info.type, -1);
161 if (info == current_user_wallpaper_info_) 153 if (info == current_user_wallpaper_info_)
162 return; 154 return;
163 } 155 }
164 SetUserWallpaper(UserManager::Get()->GetLoggedInUser()->email()); 156 SetUserWallpaper(UserManager::Get()->GetLoggedInUser()->email());
165 } 157 }
166 158
167 void WallpaperManager::GetCustomWallpaper(const std::string& email,
168 bool update_wallpaper) {
169 User::WallpaperType type;
170 int index;
171 base::Time date;
172 // Get layout, type and date while on UI thread.
173 GetUserWallpaperProperties(email, &type, &index, &date);
174 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index);
175 // Initializes file name to a dummy string here. The real file path will
176 // be set in GetCustomWallpaperInternal.
177 WallpaperInfo info = {
178 "DUMMY",
179 layout,
180 type,
181 date
182 };
183 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
184 desktop_background_controller()->GetAppropriateResolution();
185
186 BrowserThread::PostTask(
187 BrowserThread::FILE, FROM_HERE,
188 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
189 base::Unretained(this), email, info, resolution,
190 update_wallpaper));
191 }
192
193 void WallpaperManager::ClearWallpaperCache() { 159 void WallpaperManager::ClearWallpaperCache() {
194 // Cancel callback for previous cache requests. 160 // Cancel callback for previous cache requests.
195 weak_factory_.InvalidateWeakPtrs(); 161 weak_factory_.InvalidateWeakPtrs();
196 wallpaper_cache_.clear(); 162 wallpaper_cache_.clear();
197 } 163 }
198 164
199 bool WallpaperManager::GetWallpaperFromCache(const std::string& email, 165 bool WallpaperManager::GetWallpaperFromCache(const std::string& email,
200 gfx::ImageSkia* wallpaper) { 166 gfx::ImageSkia* wallpaper) {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
202 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(email); 168 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(email);
(...skipping 28 matching lines...) Expand all
231 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( 197 gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail(
232 const std::string& email) { 198 const std::string& email) {
233 CustomWallpaperMap::const_iterator it = 199 CustomWallpaperMap::const_iterator it =
234 custom_wallpaper_thumbnail_cache_.find(email); 200 custom_wallpaper_thumbnail_cache_.find(email);
235 if (it != custom_wallpaper_thumbnail_cache_.end()) 201 if (it != custom_wallpaper_thumbnail_cache_.end())
236 return (*it).second; 202 return (*it).second;
237 else 203 else
238 return gfx::ImageSkia(); 204 return gfx::ImageSkia();
239 } 205 }
240 206
241 void WallpaperManager::GetLoggedInUserWallpaperProperties(
242 User::WallpaperType* type,
243 int* index,
244 base::Time* last_modification_date) {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246
247 if (UserManager::Get()->IsLoggedInAsStub()) {
248 *type = current_user_wallpaper_type_ = User::DEFAULT;
249 *index = current_user_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
250 return;
251 }
252
253 GetUserWallpaperProperties(UserManager::Get()->GetLoggedInUser()->email(),
254 type, index, last_modification_date);
255 }
256
257 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { 207 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
259 209
260 if (UserManager::Get()->IsLoggedInAsStub()) { 210 if (UserManager::Get()->IsLoggedInAsStub()) {
261 info->file = current_user_wallpaper_info_.file = ""; 211 info->file = current_user_wallpaper_info_.file = "";
262 info->layout = current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 212 info->layout = current_user_wallpaper_info_.layout = ash::CENTER_CROPPED;
263 info->type = current_user_wallpaper_info_.type = User::DEFAULT; 213 info->type = current_user_wallpaper_info_.type = User::DEFAULT;
264 return true; 214 return true;
265 } 215 }
266 216
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 303 }
354 break; 304 break;
355 } 305 }
356 default: 306 default:
357 NOTREACHED() << "Unexpected notification " << type; 307 NOTREACHED() << "Unexpected notification " << type;
358 } 308 }
359 } 309 }
360 310
361 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { 311 void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) {
362 PrefService* prefs = g_browser_process->local_state(); 312 PrefService* prefs = g_browser_process->local_state();
363 DictionaryPrefUpdate prefs_wallpapers_update(prefs,
364 kUserWallpapersProperties);
365 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL);
366
367 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs, 313 DictionaryPrefUpdate prefs_wallpapers_info_update(prefs,
368 prefs::kUsersWallpaperInfo); 314 prefs::kUsersWallpaperInfo);
369 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL); 315 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(email, NULL);
370 316
371 DeleteUserWallpapers(email); 317 DeleteUserWallpapers(email);
372 } 318 }
373 319
374 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, 320 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper,
375 const FilePath& path, 321 const FilePath& path,
376 ash::WallpaperLayout layout, 322 ash::WallpaperLayout layout,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 // Set up a one shot timer which will batch update wallpaper at midnight. 389 // Set up a one shot timer which will batch update wallpaper at midnight.
444 timer_.Start(FROM_HERE, 390 timer_.Start(FROM_HERE,
445 base::TimeDelta::FromSeconds(remaining_seconds), 391 base::TimeDelta::FromSeconds(remaining_seconds),
446 this, 392 this,
447 &WallpaperManager::BatchUpdateWallpaper); 393 &WallpaperManager::BatchUpdateWallpaper);
448 } 394 }
449 395
450 void WallpaperManager::SetCustomWallpaper(const std::string& username, 396 void WallpaperManager::SetCustomWallpaper(const std::string& username,
451 ash::WallpaperLayout layout, 397 ash::WallpaperLayout layout,
452 User::WallpaperType type, 398 User::WallpaperType type,
453 base::WeakPtr<WallpaperDelegate> delegate,
454 const UserImage& wallpaper) { 399 const UserImage& wallpaper) {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
456 401
457 std::string wallpaper_path = 402 std::string wallpaper_path =
458 GetOriginalWallpaperPathForUser(username).value(); 403 GetOriginalWallpaperPathForUser(username).value();
459 404
460 // If decoded wallpaper is empty, we are probably failed to decode the file. 405 // If decoded wallpaper is empty, we are probably failed to decode the file.
461 // Use default wallpaper in this case. 406 // Use default wallpaper in this case.
462 if (wallpaper.image().isNull()) { 407 if (wallpaper.image().isNull()) {
463 ash::Shell::GetInstance()->desktop_background_controller()-> 408 ash::Shell::GetInstance()->desktop_background_controller()->
(...skipping 15 matching lines...) Expand all
479 }; 424 };
480 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 425 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
481 BrowserThread::PostTask( 426 BrowserThread::PostTask(
482 BrowserThread::FILE, 427 BrowserThread::FILE,
483 FROM_HERE, 428 FROM_HERE,
484 base::Bind(&WallpaperManager::ProcessCustomWallpaper, 429 base::Bind(&WallpaperManager::ProcessCustomWallpaper,
485 base::Unretained(this), 430 base::Unretained(this),
486 username, 431 username,
487 is_persistent, 432 is_persistent,
488 wallpaper_info, 433 wallpaper_info,
489 delegate,
490 base::Passed(&deep_copy), 434 base::Passed(&deep_copy),
491 wallpaper.raw_image())); 435 wallpaper.raw_image()));
492 ash::Shell::GetInstance()->desktop_background_controller()-> 436 ash::Shell::GetInstance()->desktop_background_controller()->
493 SetCustomWallpaper(wallpaper.image(), layout); 437 SetCustomWallpaper(wallpaper.image(), layout);
494 438
495 // 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
496 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use 440 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use
497 // DUMMY as file name here. 441 // DUMMY as file name here.
498 WallpaperInfo info = { 442 WallpaperInfo info = {
499 "DUMMY", 443 "DUMMY",
500 layout, 444 layout,
501 User::CUSTOMIZED, 445 User::CUSTOMIZED,
502 base::Time::Now().LocalMidnight() 446 base::Time::Now().LocalMidnight()
503 }; 447 };
504 SetUserWallpaperInfo(username, info, is_persistent); 448 SetUserWallpaperInfo(username, info, is_persistent);
505
506 SetUserWallpaperProperties(username, type, layout, is_persistent);
507 }
508
509 void WallpaperManager::SetUserWallpaperFromFile(
510 const std::string& username,
511 const FilePath& path,
512 ash::WallpaperLayout layout,
513 base::WeakPtr<WallpaperDelegate> delegate) {
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
515
516 // For wallpapers, save the image without resizing.
517 wallpaper_loader_->Start(
518 path.value(), 0,
519 base::Bind(&WallpaperManager::SetCustomWallpaper,
520 base::Unretained(this), username, layout, User::CUSTOMIZED,
521 delegate));
522 }
523
524 void WallpaperManager::SetUserWallpaperProperties(const std::string& email,
525 User::WallpaperType type,
526 int index,
527 bool is_persistent) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
529
530 current_user_wallpaper_type_ = type;
531 current_user_wallpaper_index_ = index;
532 if (!is_persistent)
533 return;
534
535 PrefService* local_state = g_browser_process->local_state();
536 DictionaryPrefUpdate wallpaper_update(local_state, kUserWallpapersProperties);
537
538 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
539 wallpaper_properties->Set(kWallpaperTypeNodeName,
540 new base::FundamentalValue(type));
541 wallpaper_properties->Set(kWallpaperIndexNodeName,
542 new base::FundamentalValue(index));
543 wallpaper_properties->SetString(kWallpaperDateNodeName,
544 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
545 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties);
546 } 449 }
547 450
548 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, 451 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
549 bool is_persistent) { 452 bool is_persistent) {
550 current_user_wallpaper_type_ = User::DEFAULT;
551 if (username == kGuestUser)
552 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
553 else
554 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
555
556 current_user_wallpaper_info_.file = ""; 453 current_user_wallpaper_info_.file = "";
557 current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 454 current_user_wallpaper_info_.layout = ash::CENTER_CROPPED;
558 current_user_wallpaper_info_.type = User::DEFAULT; 455 current_user_wallpaper_info_.type = User::DEFAULT;
559 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); 456 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
560 457
561 WallpaperInfo info = current_user_wallpaper_info_; 458 WallpaperInfo info = current_user_wallpaper_info_;
562 SetUserWallpaperInfo(username, info, is_persistent); 459 SetUserWallpaperInfo(username, info, is_persistent);
563 460
564 // Some browser tests do not have shell instance. And it is not necessary to 461 // Some browser tests do not have shell instance. And it is not necessary to
565 // create a wallpaper for these tests. Add HasInstance check to prevent tests 462 // create a wallpaper for these tests. Add HasInstance check to prevent tests
566 // crash and speed up the tests by avoid loading wallpaper. 463 // crash and speed up the tests by avoid loading wallpaper.
567 if (ash::Shell::HasInstance()) { 464 if (ash::Shell::HasInstance()) {
568 ash::Shell::GetInstance()->desktop_background_controller()-> 465 if (username == kGuestUser) {
569 SetDefaultWallpaper(current_user_wallpaper_index_); 466 ash::Shell::GetInstance()->desktop_background_controller()->
467 SetDefaultWallpaper(ash::GetGuestWallpaperIndex());
468 } else {
469 ash::Shell::GetInstance()->desktop_background_controller()->
470 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
471 }
570 } 472 }
571 } 473 }
572 474
573 void WallpaperManager::SetUserWallpaperInfo(const std::string& username, 475 void WallpaperManager::SetUserWallpaperInfo(const std::string& username,
574 const WallpaperInfo& info, 476 const WallpaperInfo& info,
575 bool is_persistent) { 477 bool is_persistent) {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
577 current_user_wallpaper_info_ = info; 479 current_user_wallpaper_info_ = info;
578 if (!is_persistent) 480 if (!is_persistent)
579 return; 481 return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 } 559 }
658 560
659 void WallpaperManager::UpdateWallpaper() { 561 void WallpaperManager::UpdateWallpaper() {
660 ClearWallpaperCache(); 562 ClearWallpaperCache();
661 SetUserWallpaper(last_selected_user_); 563 SetUserWallpaper(last_selected_user_);
662 } 564 }
663 565
664 // WallpaperManager, private: -------------------------------------------------- 566 // WallpaperManager, private: --------------------------------------------------
665 567
666 WallpaperManager::~WallpaperManager() { 568 WallpaperManager::~WallpaperManager() {
569 ClearObsoleteWallpaperPrefs();
667 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 570 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
668 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 571 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
669 weak_factory_.InvalidateWeakPtrs(); 572 weak_factory_.InvalidateWeakPtrs();
670 } 573 }
671 574
672 void WallpaperManager::BatchUpdateWallpaper() { 575 void WallpaperManager::BatchUpdateWallpaper() {
673 PrefService* local_state = g_browser_process->local_state(); 576 NOTIMPLEMENTED();
674 UserManager* user_manager = UserManager::Get();
675 bool show_users = true;
676 CrosSettings::Get()->GetBoolean(
677 kAccountsPrefShowUserNamesOnSignIn, &show_users);
678 if (local_state) {
679 User::WallpaperType type;
680 int index = 0;
681 base::Time last_modification_date;
682 const UserList& users = user_manager->GetUsers();
683 for (UserList::const_iterator it = users.begin();
684 it != users.end(); ++it) {
685 std::string email = (*it)->email();
686 GetUserWallpaperProperties(email, &type, &index, &last_modification_date);
687 base::Time current_date = base::Time::Now().LocalMidnight();
688 if (type == User::DAILY && current_date != last_modification_date) {
689 SetUserWallpaperProperties(email, type, index, true);
690 }
691 // Force a wallpaper update for logged in / last selected user.
692 // TODO(bshe): Notify lock screen, wallpaper picker UI to update wallpaper
693 // as well.
694 if (user_manager->IsUserLoggedIn() &&
695 email == user_manager->GetLoggedInUser()->email()) {
696 SetUserWallpaper(email);
697 } else if (show_users &&
698 email == last_selected_user_) {
699 SetUserWallpaper(email);
700 }
701 }
702 }
703 RestartTimer();
704 } 577 }
705 578
706 void WallpaperManager::CacheAllUsersWallpapers() { 579 void WallpaperManager::CacheAllUsersWallpapers() {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708 UserList users = UserManager::Get()->GetUsers(); 581 UserList users = UserManager::Get()->GetUsers();
709 582
710 if (!users.empty()) { 583 if (!users.empty()) {
711 UserList::const_iterator it = users.begin(); 584 UserList::const_iterator it = users.begin();
712 // Skip the wallpaper of first user in the list. It should have been cached. 585 // Skip the wallpaper of first user in the list. It should have been cached.
713 it++; 586 it++;
(...skipping 25 matching lines...) Expand all
739 } 612 }
740 } 613 }
741 614
742 void WallpaperManager::CacheThumbnail(const std::string& email, 615 void WallpaperManager::CacheThumbnail(const std::string& email,
743 scoped_ptr<gfx::ImageSkia> wallpaper) { 616 scoped_ptr<gfx::ImageSkia> wallpaper) {
744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
745 custom_wallpaper_thumbnail_cache_[email] = 618 custom_wallpaper_thumbnail_cache_[email] =
746 GetWallpaperThumbnail(*wallpaper.get()); 619 GetWallpaperThumbnail(*wallpaper.get());
747 } 620 }
748 621
622 void WallpaperManager::ClearObsoleteWallpaperPrefs() {
623 PrefService* prefs = g_browser_process->local_state();
624 DictionaryPrefUpdate wallpaper_properties_pref(prefs,
625 kUserWallpapersProperties);
626 wallpaper_properties_pref->Clear();
627 DictionaryPrefUpdate wallpapers_pref(prefs, kUserWallpapers);
628 wallpapers_pref->Clear();
629 }
630
749 void WallpaperManager::DeleteWallpaperInList( 631 void WallpaperManager::DeleteWallpaperInList(
750 const std::vector<FilePath>& file_list) { 632 const std::vector<FilePath>& file_list) {
751 for (std::vector<FilePath>::const_iterator it = file_list.begin(); 633 for (std::vector<FilePath>::const_iterator it = file_list.begin();
752 it != file_list.end(); ++it) { 634 it != file_list.end(); ++it) {
753 FilePath path = *it; 635 FilePath path = *it;
754 if (!file_util::Delete(path, false)) { 636 if (!file_util::Delete(path, false)) {
755 LOG(ERROR) << "Failed to remove user wallpaper."; 637 LOG(ERROR) << "Failed to remove user wallpaper.";
756 } 638 }
757 639
758 // Some users may still have wallpapers with a file extension. This will 640 // Some users may still have wallpapers with a file extension. This will
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 &date_string) && 733 &date_string) &&
852 base::StringToInt64(date_string, &val))) 734 base::StringToInt64(date_string, &val)))
853 val = 0; 735 val = 0;
854 info->date = base::Time::FromInternalValue(val); 736 info->date = base::Time::FromInternalValue(val);
855 return true; 737 return true;
856 } 738 }
857 739
858 return false; 740 return false;
859 } 741 }
860 742
861 void WallpaperManager::GetUserWallpaperProperties(const std::string& email,
862 User::WallpaperType* type,
863 int* index,
864 base::Time* last_modification_date) {
865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
866
867 // Default to the values cached in memory.
868 *type = current_user_wallpaper_type_;
869 *index = current_user_wallpaper_index_;
870
871 // Override with values found in local store, if any.
872 if (!email.empty()) {
873 const DictionaryValue* user_wallpapers = g_browser_process->local_state()->
874 GetDictionary(kUserWallpapersProperties);
875 const base::DictionaryValue* wallpaper_properties;
876 if (user_wallpapers->GetDictionaryWithoutPathExpansion(
877 email,
878 &wallpaper_properties)) {
879 *type = User::UNKNOWN;
880 *index = ash::GetInvalidWallpaperIndex();
881 wallpaper_properties->GetInteger(kWallpaperTypeNodeName,
882 reinterpret_cast<int*>(type));
883 wallpaper_properties->GetInteger(kWallpaperIndexNodeName, index);
884 std::string date_string;
885 int64 val;
886 if (!(wallpaper_properties->GetString(kWallpaperDateNodeName,
887 &date_string) &&
888 base::StringToInt64(date_string, &val)))
889 val = 0;
890 *last_modification_date = base::Time::FromInternalValue(val);
891 }
892 }
893
894 // Index maybe invalid when update from official build to unofficial build.
895 // Revert to default in that case.
896 if (*type == User::DEFAULT &&
897 (*index < 0 || *index >= ash::GetWallpaperCount())) {
898 *index = ash::GetDefaultWallpaperIndex();
899 }
900 }
901
902 void WallpaperManager::GenerateUserWallpaperThumbnail( 743 void WallpaperManager::GenerateUserWallpaperThumbnail(
903 const std::string& email, 744 const std::string& email,
904 User::WallpaperType type, 745 User::WallpaperType type,
905 base::WeakPtr<WallpaperDelegate> delegate,
906 const gfx::ImageSkia& wallpaper) { 746 const gfx::ImageSkia& wallpaper) {
907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
908 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper); 748 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper);
909
910 // Notify thumbnail is ready.
911 BrowserThread::PostTask(
912 BrowserThread::UI,
913 FROM_HERE,
914 base::Bind(&WallpaperManager::OnThumbnailUpdated,
915 base::Unretained(this), delegate));
916 } 749 }
917 750
918 void WallpaperManager::GetCustomWallpaperInternal( 751 void WallpaperManager::GetCustomWallpaperInternal(
919 const std::string& email, 752 const std::string& email,
920 const WallpaperInfo& info, 753 const WallpaperInfo& info,
921 ash::WallpaperResolution resolution, 754 ash::WallpaperResolution resolution,
922 bool update_wallpaper) { 755 bool update_wallpaper) {
923 bool is_small = (resolution == ash::SMALL); 756 bool is_small = (resolution == ash::SMALL);
924 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small); 757 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small);
925 std::string file_name = wallpaper_path.BaseName().value(); 758 std::string file_name = wallpaper_path.BaseName().value();
(...skipping 16 matching lines...) Expand all
942 info.type, 775 info.type,
943 info.date 776 info.date
944 }; 777 };
945 778
946 BrowserThread::PostTask( 779 BrowserThread::PostTask(
947 BrowserThread::UI, FROM_HERE, 780 BrowserThread::UI, FROM_HERE,
948 base::Bind(&WallpaperManager::LoadWallpaper, 781 base::Bind(&WallpaperManager::LoadWallpaper,
949 base::Unretained(this), email, new_info, update_wallpaper)); 782 base::Unretained(this), email, new_info, update_wallpaper));
950 } 783 }
951 784
952 void WallpaperManager::MigrateWallpaperData(const UserList& users) {
953 PrefService* local_state = g_browser_process->local_state();
954 if (local_state) {
955 const DictionaryValue* user_wallpapers =
956 local_state->GetDictionary(kUserWallpapers);
957 int index;
958 const DictionaryValue* new_user_wallpapers =
959 local_state->GetDictionary(kUserWallpapersProperties);
960 if (new_user_wallpapers->empty()) {
961 for (UserList::const_iterator it = users.begin();
962 it != users.end();
963 ++it) {
964 std::string username = (*it)->email();
965 if (user_wallpapers->GetIntegerWithoutPathExpansion(
966 username, &index)) {
967 DictionaryPrefUpdate prefs_wallpapers_update(
968 local_state, kUserWallpapers);
969 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL);
970 SetUserWallpaperProperties(username, User::DEFAULT, index, true);
971 } else {
972 // Before M20, wallpaper index is not saved into LocalState unless
973 // user specifically sets a wallpaper. After M20, the default
974 // wallpaper index is saved to LocalState as soon as a new user login.
975 // When migrating wallpaper index from M20 to M21, we only migrate
976 // data that is in LocalState. This cause a problem when users login
977 // on a M20 device and then update the device to M21. The default
978 // wallpaper index failed to migrate because it was not saved into
979 // LocalState. Then we assume that all users have index saved in
980 // LocalState in M21. This is not true and it results an empty
981 // wallpaper for those users as described in cr/130685. So here we use
982 // default wallpaper for users that exist in user list but does not
983 // have an index saved in LocalState.
984 SetUserWallpaperProperties(
985 username, User::DEFAULT, ash::GetDefaultWallpaperIndex(), true);
986 }
987 }
988 }
989 }
990 }
991
992 void WallpaperManager::MigrateBuiltInWallpaper(const std::string& email) {
993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
994 if (!email.empty() && UserManager::Get()->IsKnownUser(email)) {
995 PrefService* prefs = g_browser_process->local_state();
996 const DictionaryValue* user_wallpapers = prefs->
997 GetDictionary(kUserWallpapersProperties);
998 const base::DictionaryValue* wallpaper_properties;
999 User::WallpaperType type;
1000 int index;
1001 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
1002 desktop_background_controller()->GetAppropriateResolution();
1003 if (user_wallpapers->GetDictionaryWithoutPathExpansion(email,
1004 &wallpaper_properties)) {
1005 base::Time date;
1006 GetUserWallpaperProperties(email, &type, &index, &date);
1007
1008 FilePath wallpaper_dir;
1009 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
1010 DCHECK(type != User::UNKNOWN);
1011
1012 FilePath wallpaper_path;
1013 if (type != User::CUSTOMIZED) {
1014 base::RefCountedStaticMemory* wallpaper =
1015 ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
1016 GetWallpaperViewInfo(index, ash::LARGE).id);
1017
1018 // Saves large wallpaper to user custom wallpaper path.
1019 wallpaper_path = GetWallpaperPathForUser(email, false);
1020 BrowserThread::PostTask(
1021 BrowserThread::FILE,
1022 FROM_HERE,
1023 base::Bind(&WallpaperManager::SaveWallpaperInternal,
1024 base::Unretained(this), wallpaper_path,
1025 reinterpret_cast<const char*>(wallpaper->front()),
1026 wallpaper->size()));
1027
1028 wallpaper =
1029 ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
1030 GetWallpaperViewInfo(index, ash::SMALL).id);
1031
1032 // Saves small wallpaper to user custom wallpaper thumbnail path.
1033 wallpaper_path = GetWallpaperPathForUser(email, true);
1034 BrowserThread::PostTask(
1035 BrowserThread::FILE,
1036 FROM_HERE,
1037 base::Bind(&WallpaperManager::SaveWallpaperInternal,
1038 base::Unretained(this), wallpaper_path,
1039 reinterpret_cast<const char*>(wallpaper->front()),
1040 wallpaper->size()));
1041 }
1042
1043 bool small_resolution = (resolution == ash::SMALL);
1044 std::string file_name =
1045 GetWallpaperPathForUser(email, small_resolution).BaseName().value();
1046 WallpaperInfo info = {
1047 file_name,
1048 GetWallpaperViewInfo(index, resolution).layout,
1049 type,
1050 base::Time::Now().LocalMidnight()
1051 };
1052 SetUserWallpaperInfo(email, info, true);
1053 }
1054 }
1055 }
1056
1057 void WallpaperManager::OnThumbnailUpdated(
1058 base::WeakPtr<WallpaperDelegate> delegate) {
1059 if (delegate)
1060 delegate->SetCustomWallpaperThumbnail();
1061 }
1062
1063 void WallpaperManager::OnWallpaperDecoded(const std::string& email, 785 void WallpaperManager::OnWallpaperDecoded(const std::string& email,
1064 ash::WallpaperLayout layout, 786 ash::WallpaperLayout layout,
1065 bool update_wallpaper, 787 bool update_wallpaper,
1066 const UserImage& wallpaper) { 788 const UserImage& wallpaper) {
1067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1068 790
1069 // If decoded wallpaper is empty, we are probably failed to decode the file. 791 // If decoded wallpaper is empty, we are probably failed to decode the file.
1070 // Use default wallpaper in this case. 792 // Use default wallpaper in this case.
1071 if (wallpaper.image().isNull()) { 793 if (wallpaper.image().isNull()) {
1072 // Updates user pref to default wallpaper. 794 // Updates user pref to default wallpaper.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 if (update_wallpaper) { 826 if (update_wallpaper) {
1105 ash::Shell::GetInstance()->desktop_background_controller()-> 827 ash::Shell::GetInstance()->desktop_background_controller()->
1106 SetCustomWallpaper(wallpaper.image(), layout); 828 SetCustomWallpaper(wallpaper.image(), layout);
1107 } 829 }
1108 } 830 }
1109 831
1110 void WallpaperManager::ProcessCustomWallpaper( 832 void WallpaperManager::ProcessCustomWallpaper(
1111 const std::string& email, 833 const std::string& email,
1112 bool persistent, 834 bool persistent,
1113 const WallpaperInfo& info, 835 const WallpaperInfo& info,
1114 base::WeakPtr<WallpaperDelegate> delegate,
1115 scoped_ptr<gfx::ImageSkia> image, 836 scoped_ptr<gfx::ImageSkia> image,
1116 const UserImage::RawImage& raw_image) { 837 const UserImage::RawImage& raw_image) {
1117 UserImage wallpaper(*image.get(), raw_image); 838 UserImage wallpaper(*image.get(), raw_image);
1118 GenerateUserWallpaperThumbnail(email, info.type, delegate, wallpaper.image()); 839 GenerateUserWallpaperThumbnail(email, info.type, wallpaper.image());
1119 if (persistent) 840 if (persistent)
1120 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper); 841 SaveCustomWallpaper(email, FilePath(info.file), info.layout, wallpaper);
1121 } 842 }
1122 843
1123 void WallpaperManager::OnWallpaperEncoded(const FilePath& path, 844 void WallpaperManager::OnWallpaperEncoded(const FilePath& path,
1124 scoped_refptr<base::RefCountedBytes> data) { 845 scoped_refptr<base::RefCountedBytes> data) {
1125 SaveWallpaperInternal(path, 846 SaveWallpaperInternal(path,
1126 reinterpret_cast<const char*>(data->front()), 847 reinterpret_cast<const char*>(data->front()),
1127 data->size()); 848 data->size());
1128 } 849 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 FROM_HERE, 944 FROM_HERE,
1224 base::Bind(&WallpaperManager::StartLoad, 945 base::Bind(&WallpaperManager::StartLoad,
1225 base::Unretained(this), 946 base::Unretained(this),
1226 email, 947 email,
1227 info, 948 info,
1228 update_wallpaper, 949 update_wallpaper,
1229 valid_path)); 950 valid_path));
1230 } 951 }
1231 952
1232 } // chromeos 953 } // chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698