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

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

Issue 322233002: Remove more unretained (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/users/wallpaper/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Some users may still have legacy wallpapers with png extension. We need 166 // Some users may still have legacy wallpapers with png extension. We need
167 // to delete these wallpapers too. 167 // to delete these wallpapers too.
168 if (!base::DeleteFile(path, true) && 168 if (!base::DeleteFile(path, true) &&
169 !base::DeleteFile(path.AddExtension(".png"), false)) { 169 !base::DeleteFile(path.AddExtension(".png"), false)) {
170 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value(); 170 LOG(ERROR) << "Failed to remove user wallpaper at " << path.value();
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 // Creates all new custom wallpaper directories for |user_id_hash| if not exist. 175 // Creates all new custom wallpaper directories for |user_id_hash| if not exist.
176 // static
176 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash) { 177 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash) {
177 base::FilePath dir; 178 base::FilePath dir;
178 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir); 179 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir);
179 dir = dir.Append(user_id_hash); 180 dir = dir.Append(user_id_hash);
180 if (!base::PathExists(dir)) 181 if (!base::PathExists(dir))
181 base::CreateDirectory(dir); 182 base::CreateDirectory(dir);
182 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir); 183 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir);
183 dir = dir.Append(user_id_hash); 184 dir = dir.Append(user_id_hash);
184 if (!base::PathExists(dir)) 185 if (!base::PathExists(dir))
185 base::CreateDirectory(dir); 186 base::CreateDirectory(dir);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 if (default_) { 391 if (default_) {
391 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); 392 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass());
392 } else if (!user_wallpaper_.isNull()) { 393 } else if (!user_wallpaper_.isNull()) {
393 ash::Shell::GetInstance() 394 ash::Shell::GetInstance()
394 ->desktop_background_controller() 395 ->desktop_background_controller()
395 ->SetWallpaperImage(user_wallpaper_, info_.layout); 396 ->SetWallpaperImage(user_wallpaper_, info_.layout);
396 } else if (!wallpaper_path_.empty()) { 397 } else if (!wallpaper_path_.empty()) {
397 manager->task_runner_->PostTask( 398 manager->task_runner_->PostTask(
398 FROM_HERE, 399 FROM_HERE,
399 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 400 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
400 base::Unretained(manager),
401 user_id_, 401 user_id_,
402 info_, 402 info_,
403 wallpaper_path_, 403 wallpaper_path_,
404 true /* update wallpaper */, 404 true /* update wallpaper */,
405 base::Passed(on_finish_.Pass()))); 405 base::Passed(on_finish_.Pass()),
406 manager->weak_factory_.GetWeakPtr()));
406 } else if (!info_.file.empty()) { 407 } else if (!info_.file.empty()) {
407 manager->LoadWallpaper(user_id_, info_, true, on_finish_.Pass()); 408 manager->LoadWallpaper(user_id_, info_, true, on_finish_.Pass());
408 } else { 409 } else {
409 // PendingWallpaper was created and never initialized? 410 // PendingWallpaper was created and never initialized?
410 NOTREACHED(); 411 NOTREACHED();
411 // Error. Do not record time. 412 // Error. Do not record time.
412 started_load_at_ = base::Time(); 413 started_load_at_ = base::Time();
413 } 414 }
414 on_finish_.reset(); 415 on_finish_.reset();
415 } 416 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); 520 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo);
520 registry->RegisterDictionaryPref(kUserWallpapers); 521 registry->RegisterDictionaryPref(kUserWallpapers);
521 registry->RegisterDictionaryPref(kUserWallpapersProperties); 522 registry->RegisterDictionaryPref(kUserWallpapersProperties);
522 } 523 }
523 524
524 void WallpaperManager::AddObservers() { 525 void WallpaperManager::AddObservers() {
525 show_user_name_on_signin_subscription_ = 526 show_user_name_on_signin_subscription_ =
526 CrosSettings::Get()->AddSettingsObserver( 527 CrosSettings::Get()->AddSettingsObserver(
527 kAccountsPrefShowUserNamesOnSignIn, 528 kAccountsPrefShowUserNamesOnSignIn,
528 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, 529 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper,
529 base::Unretained(this))); 530 weak_factory_.GetWeakPtr()));
530 } 531 }
531 532
532 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 533 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
533 // Some browser tests do not have a shell instance. As no wallpaper is needed 534 // Some browser tests do not have a shell instance. As no wallpaper is needed
534 // in these tests anyway, avoid loading one, preventing crashes and speeding 535 // in these tests anyway, avoid loading one, preventing crashes and speeding
535 // up the tests. 536 // up the tests.
536 if (!ash::Shell::HasInstance()) 537 if (!ash::Shell::HasInstance())
537 return; 538 return;
538 539
539 WallpaperInfo info; 540 WallpaperInfo info;
(...skipping 22 matching lines...) Expand all
562 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin(); 563 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin();
563 it != wallpaper_cache_.end(); ++it) { 564 it != wallpaper_cache_.end(); ++it) {
564 if (logged_in_users_names.find(it->first) != 565 if (logged_in_users_names.find(it->first) !=
565 logged_in_users_names.end()) { 566 logged_in_users_names.end()) {
566 logged_in_users_cache.insert(*it); 567 logged_in_users_cache.insert(*it);
567 } 568 }
568 } 569 }
569 wallpaper_cache_ = logged_in_users_cache; 570 wallpaper_cache_ = logged_in_users_cache;
570 } 571 }
571 572
572 base::FilePath WallpaperManager::GetCustomWallpaperPath(
573 const char* sub_dir,
574 const std::string& user_id_hash,
575 const std::string& file) const {
576 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir);
577 return custom_wallpaper_path.Append(user_id_hash).Append(file);
578 }
579
580 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { 573 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
582 575
583 if (UserManager::Get()->IsLoggedInAsStub()) { 576 if (UserManager::Get()->IsLoggedInAsStub()) {
584 info->file = current_user_wallpaper_info_.file = ""; 577 info->file = current_user_wallpaper_info_.file = "";
585 info->layout = current_user_wallpaper_info_.layout = 578 info->layout = current_user_wallpaper_info_.layout =
586 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 579 ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
587 info->type = current_user_wallpaper_info_.type = User::DEFAULT; 580 info->type = current_user_wallpaper_info_.type = User::DEFAULT;
588 info->date = current_user_wallpaper_info_.date = 581 info->date = current_user_wallpaper_info_.date =
589 base::Time::Now().LocalMidnight(); 582 base::Time::Now().LocalMidnight();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 WallpaperManager::GetAppropriateResolution() { 814 WallpaperManager::GetAppropriateResolution() {
822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
823 gfx::Size size = 816 gfx::Size size =
824 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); 817 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative();
825 return (size.width() > kSmallWallpaperMaxWidth || 818 return (size.width() > kSmallWallpaperMaxWidth ||
826 size.height() > kSmallWallpaperMaxHeight) 819 size.height() > kSmallWallpaperMaxHeight)
827 ? WALLPAPER_RESOLUTION_LARGE 820 ? WALLPAPER_RESOLUTION_LARGE
828 : WALLPAPER_RESOLUTION_SMALL; 821 : WALLPAPER_RESOLUTION_SMALL;
829 } 822 }
830 823
824 // static
825 base::FilePath WallpaperManager::GetCustomWallpaperPath(
826 const char* sub_dir,
827 const std::string& user_id_hash,
828 const std::string& file) {
829 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir);
830 return custom_wallpaper_path.Append(user_id_hash).Append(file);
831 }
832
833 // static
834 void WallpaperManager::RecordUma(User::WallpaperType type, int index) {
835 UMA_HISTOGRAM_ENUMERATION(
836 "Ash.Wallpaper.Type", type, User::WALLPAPER_TYPE_COUNT);
837 }
838
839 // static
840 void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash,
841 const base::FilePath& original_path,
842 ash::WallpaperLayout layout,
843 scoped_ptr<gfx::ImageSkia> image) {
844 EnsureCustomWallpaperDirectories(user_id_hash);
845 std::string file_name = original_path.BaseName().value();
846 base::FilePath small_wallpaper_path =
847 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name);
848 base::FilePath large_wallpaper_path =
849 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name);
850
851 // Re-encode orginal file to jpeg format and saves the result in case that
852 // resized wallpaper is not generated (i.e. chrome shutdown before resized
853 // wallpaper is saved).
854 ResizeAndSaveWallpaper(*image,
855 original_path,
856 ash::WALLPAPER_LAYOUT_STRETCH,
857 image->width(),
858 image->height(),
859 NULL);
860 DeleteAllExcept(original_path);
861
862 ResizeAndSaveWallpaper(*image,
863 small_wallpaper_path,
864 layout,
865 kSmallWallpaperMaxWidth,
866 kSmallWallpaperMaxHeight,
867 NULL);
868 DeleteAllExcept(small_wallpaper_path);
869 ResizeAndSaveWallpaper(*image,
870 large_wallpaper_path,
871 layout,
872 kLargeWallpaperMaxWidth,
873 kLargeWallpaperMaxHeight,
874 NULL);
875 DeleteAllExcept(large_wallpaper_path);
876 }
877
831 void WallpaperManager::SetPolicyControlledWallpaper( 878 void WallpaperManager::SetPolicyControlledWallpaper(
832 const std::string& user_id, 879 const std::string& user_id,
833 const UserImage& user_image) { 880 const UserImage& user_image) {
834 const User *user = chromeos::UserManager::Get()->FindUser(user_id); 881 const User *user = chromeos::UserManager::Get()->FindUser(user_id);
835 if (!user) { 882 if (!user) {
836 NOTREACHED() << "Unknown user."; 883 NOTREACHED() << "Unknown user.";
837 return; 884 return;
838 } 885 }
839 SetCustomWallpaper(user_id, 886 SetCustomWallpaper(user_id,
840 user->username_hash(), 887 user->username_hash(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper 936 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper
890 // that the user selected. 937 // that the user selected.
891 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 938 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
892 BrowserThread::GetBlockingPool() 939 BrowserThread::GetBlockingPool()
893 ->GetSequencedTaskRunnerWithShutdownBehavior( 940 ->GetSequencedTaskRunnerWithShutdownBehavior(
894 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); 941 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN);
895 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 942 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
896 blocking_task_runner->PostTask( 943 blocking_task_runner->PostTask(
897 FROM_HERE, 944 FROM_HERE,
898 base::Bind(&WallpaperManager::SaveCustomWallpaper, 945 base::Bind(&WallpaperManager::SaveCustomWallpaper,
899 base::Unretained(this),
900 user_id_hash, 946 user_id_hash,
901 base::FilePath(wallpaper_info.file), 947 base::FilePath(wallpaper_info.file),
902 wallpaper_info.layout, 948 wallpaper_info.layout,
903 base::Passed(deep_copy.Pass()))); 949 base::Passed(deep_copy.Pass())));
904 } 950 }
905 951
906 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); 952 std::string relative_path = base::FilePath(user_id_hash).Append(file).value();
907 // User's custom wallpaper path is determined by relative path and the 953 // User's custom wallpaper path is determined by relative path and the
908 // appropriate wallpaper resolution in GetCustomWallpaperInternal. 954 // appropriate wallpaper resolution in GetCustomWallpaperInternal.
909 WallpaperInfo info = { 955 WallpaperInfo info = {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1220
1175 base::FilePath wallpaper_dir; 1221 base::FilePath wallpaper_dir;
1176 base::FilePath wallpaper_path; 1222 base::FilePath wallpaper_path;
1177 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { 1223 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
1178 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); 1224 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
1179 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 1225 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
1180 wallpaper_path = wallpaper_path.Append(info.file); 1226 wallpaper_path = wallpaper_path.Append(info.file);
1181 task_runner_->PostTask( 1227 task_runner_->PostTask(
1182 FROM_HERE, 1228 FROM_HERE,
1183 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 1229 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
1184 base::Unretained(this),
1185 user_id, 1230 user_id,
1186 info, 1231 info,
1187 wallpaper_path, 1232 wallpaper_path,
1188 false /* do not update wallpaper */, 1233 false /* do not update wallpaper */,
1189 base::Passed(MovableOnDestroyCallbackHolder()))); 1234 base::Passed(MovableOnDestroyCallbackHolder()),
1235 weak_factory_.GetWeakPtr()));
1190 return; 1236 return;
1191 } 1237 }
1192 LoadWallpaper(user_id, 1238 LoadWallpaper(user_id,
1193 info, 1239 info,
1194 false /* do not update wallpaper */, 1240 false /* do not update wallpaper */,
1195 MovableOnDestroyCallbackHolder().Pass()); 1241 MovableOnDestroyCallbackHolder().Pass());
1196 } 1242 }
1197 } 1243 }
1198 1244
1199 void WallpaperManager::ClearObsoleteWallpaperPrefs() { 1245 void WallpaperManager::ClearObsoleteWallpaperPrefs() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 1428
1383 info->file = file; 1429 info->file = file;
1384 info->layout = static_cast<ash::WallpaperLayout>(layout); 1430 info->layout = static_cast<ash::WallpaperLayout>(layout);
1385 info->type = static_cast<User::WallpaperType>(type); 1431 info->type = static_cast<User::WallpaperType>(type);
1386 info->date = base::Time::FromInternalValue(date_val); 1432 info->date = base::Time::FromInternalValue(date_val);
1387 return true; 1433 return true;
1388 } 1434 }
1389 1435
1390 void WallpaperManager::MoveCustomWallpapersOnWorker( 1436 void WallpaperManager::MoveCustomWallpapersOnWorker(
1391 const std::string& user_id, 1437 const std::string& user_id,
1392 const std::string& user_id_hash) { 1438 const std::string& user_id_hash,
1439 base::WeakPtr<WallpaperManager> weak_ptr) {
1440 /*
1393 DCHECK(BrowserThread::GetBlockingPool()-> 1441 DCHECK(BrowserThread::GetBlockingPool()->
1394 IsRunningSequenceOnCurrentThread(sequence_token_)); 1442 IsRunningSequenceOnCurrentThread(sequence_token_));
1443 */
1395 if (MoveCustomWallpaperDirectory( 1444 if (MoveCustomWallpaperDirectory(
1396 kOriginalWallpaperSubDir, user_id, user_id_hash)) { 1445 kOriginalWallpaperSubDir, user_id, user_id_hash)) {
1397 // Consider success if the original wallpaper is moved to the new directory. 1446 // Consider success if the original wallpaper is moved to the new directory.
1398 // Original wallpaper is the fallback if the correct resolution wallpaper 1447 // Original wallpaper is the fallback if the correct resolution wallpaper
1399 // can not be found. 1448 // can not be found.
1400 BrowserThread::PostTask( 1449 BrowserThread::PostTask(
1401 BrowserThread::UI, 1450 BrowserThread::UI,
1402 FROM_HERE, 1451 FROM_HERE,
1403 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess, 1452 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess,
1404 base::Unretained(this), 1453 weak_ptr,
1405 user_id, 1454 user_id,
1406 user_id_hash)); 1455 user_id_hash));
1407 } 1456 }
1408 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash); 1457 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash);
1409 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash); 1458 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash);
1410 MoveCustomWallpaperDirectory( 1459 MoveCustomWallpaperDirectory(
1411 kThumbnailWallpaperSubDir, user_id, user_id_hash); 1460 kThumbnailWallpaperSubDir, user_id, user_id_hash);
1412 } 1461 }
1413 1462
1414 void WallpaperManager::MoveCustomWallpapersSuccess( 1463 void WallpaperManager::MoveCustomWallpapersSuccess(
(...skipping 11 matching lines...) Expand all
1426 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); 1475 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id);
1427 SetUserWallpaperInfo(user_id, info, is_persistent); 1476 SetUserWallpaperInfo(user_id, info, is_persistent);
1428 } 1477 }
1429 } 1478 }
1430 1479
1431 void WallpaperManager::MoveLoggedInUserCustomWallpaper() { 1480 void WallpaperManager::MoveLoggedInUserCustomWallpaper() {
1432 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); 1481 const User* logged_in_user = UserManager::Get()->GetLoggedInUser();
1433 task_runner_->PostTask( 1482 task_runner_->PostTask(
1434 FROM_HERE, 1483 FROM_HERE,
1435 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker, 1484 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker,
1436 base::Unretained(this),
1437 logged_in_user->email(), 1485 logged_in_user->email(),
1438 logged_in_user->username_hash())); 1486 logged_in_user->username_hash(),
1487 weak_factory_.GetWeakPtr()));
1439 } 1488 }
1440 1489
1441 void WallpaperManager::GetCustomWallpaperInternal( 1490 void WallpaperManager::GetCustomWallpaperInternal(
1442 const std::string& user_id, 1491 const std::string& user_id,
1443 const WallpaperInfo& info, 1492 const WallpaperInfo& info,
1444 const base::FilePath& wallpaper_path, 1493 const base::FilePath& wallpaper_path,
1445 bool update_wallpaper, 1494 bool update_wallpaper,
1446 MovableOnDestroyCallbackHolder on_finish) { 1495 MovableOnDestroyCallbackHolder on_finish,
1496 base::WeakPtr<WallpaperManager> weak_ptr) {
1497 /*
1447 DCHECK(BrowserThread::GetBlockingPool()-> 1498 DCHECK(BrowserThread::GetBlockingPool()->
1448 IsRunningSequenceOnCurrentThread(sequence_token_)); 1499 IsRunningSequenceOnCurrentThread(sequence_token_));
1500 */
1449 1501
1450 base::FilePath valid_path = wallpaper_path; 1502 base::FilePath valid_path = wallpaper_path;
1451 if (!base::PathExists(wallpaper_path)) { 1503 if (!base::PathExists(wallpaper_path)) {
1452 // Falls back on original file if the correct resolution file does not 1504 // Falls back on original file if the correct resolution file does not
1453 // exist. This may happen when the original custom wallpaper is small or 1505 // exist. This may happen when the original custom wallpaper is small or
1454 // browser shutdown before resized wallpaper saved. 1506 // browser shutdown before resized wallpaper saved.
1455 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); 1507 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
1456 valid_path = valid_path.Append(info.file); 1508 valid_path = valid_path.Append(info.file);
1457 } 1509 }
1458 1510
1459 if (!base::PathExists(valid_path)) { 1511 if (!base::PathExists(valid_path)) {
1460 // Falls back to custom wallpaper that uses email as part of its file path. 1512 // Falls back to custom wallpaper that uses email as part of its file path.
1461 // Note that email is used instead of user_id_hash here. 1513 // Note that email is used instead of user_id_hash here.
1462 valid_path = 1514 valid_path =
1463 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file); 1515 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file);
1464 } 1516 }
1465 1517
1466 if (!base::PathExists(valid_path)) { 1518 if (!base::PathExists(valid_path)) {
1467 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << 1519 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " <<
1468 "Fallback to default wallpaper"; 1520 "Fallback to default wallpaper";
1469 BrowserThread::PostTask(BrowserThread::UI, 1521 BrowserThread::PostTask(BrowserThread::UI,
1470 FROM_HERE, 1522 FROM_HERE,
1471 base::Bind(&WallpaperManager::DoSetDefaultWallpaper, 1523 base::Bind(&WallpaperManager::DoSetDefaultWallpaper,
1472 base::Unretained(this), 1524 weak_ptr,
1473 user_id, 1525 user_id,
1474 base::Passed(on_finish.Pass()))); 1526 base::Passed(on_finish.Pass())));
1475 } else { 1527 } else {
1476 BrowserThread::PostTask(BrowserThread::UI, 1528 BrowserThread::PostTask(BrowserThread::UI,
1477 FROM_HERE, 1529 FROM_HERE,
1478 base::Bind(&WallpaperManager::StartLoad, 1530 base::Bind(&WallpaperManager::StartLoad,
1479 base::Unretained(this), 1531 weak_ptr,
1480 user_id, 1532 user_id,
1481 info, 1533 info,
1482 update_wallpaper, 1534 update_wallpaper,
1483 valid_path, 1535 valid_path,
1484 base::Passed(on_finish.Pass()))); 1536 base::Passed(on_finish.Pass())));
1485 } 1537 }
1486 } 1538 }
1487 1539
1488 void WallpaperManager::OnWallpaperDecoded( 1540 void WallpaperManager::OnWallpaperDecoded(
1489 const std::string& user_id, 1541 const std::string& user_id,
(...skipping 23 matching lines...) Expand all
1513 1565
1514 wallpaper_cache_[user_id] = user_image.image(); 1566 wallpaper_cache_[user_id] = user_image.image();
1515 1567
1516 if (update_wallpaper) { 1568 if (update_wallpaper) {
1517 ash::Shell::GetInstance() 1569 ash::Shell::GetInstance()
1518 ->desktop_background_controller() 1570 ->desktop_background_controller()
1519 ->SetWallpaperImage(user_image.image(), layout); 1571 ->SetWallpaperImage(user_image.image(), layout);
1520 } 1572 }
1521 } 1573 }
1522 1574
1523 void WallpaperManager::SaveCustomWallpaper(
1524 const std::string& user_id_hash,
1525 const base::FilePath& original_path,
1526 ash::WallpaperLayout layout,
1527 scoped_ptr<gfx::ImageSkia> image) const {
1528 DCHECK(BrowserThread::GetBlockingPool()->
1529 IsRunningSequenceOnCurrentThread(sequence_token_));
1530 EnsureCustomWallpaperDirectories(user_id_hash);
1531 std::string file_name = original_path.BaseName().value();
1532 base::FilePath small_wallpaper_path =
1533 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name);
1534 base::FilePath large_wallpaper_path =
1535 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name);
1536
1537 // Re-encode orginal file to jpeg format and saves the result in case that
1538 // resized wallpaper is not generated (i.e. chrome shutdown before resized
1539 // wallpaper is saved).
1540 ResizeAndSaveWallpaper(*image,
1541 original_path,
1542 ash::WALLPAPER_LAYOUT_STRETCH,
1543 image->width(),
1544 image->height(),
1545 NULL);
1546 DeleteAllExcept(original_path);
1547
1548 ResizeAndSaveWallpaper(*image,
1549 small_wallpaper_path,
1550 layout,
1551 kSmallWallpaperMaxWidth,
1552 kSmallWallpaperMaxHeight,
1553 NULL);
1554 DeleteAllExcept(small_wallpaper_path);
1555 ResizeAndSaveWallpaper(*image,
1556 large_wallpaper_path,
1557 layout,
1558 kLargeWallpaperMaxWidth,
1559 kLargeWallpaperMaxHeight,
1560 NULL);
1561 DeleteAllExcept(large_wallpaper_path);
1562 }
1563
1564 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const {
1565 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type,
1566 User::WALLPAPER_TYPE_COUNT);
1567 }
1568
1569 void WallpaperManager::StartLoad(const std::string& user_id, 1575 void WallpaperManager::StartLoad(const std::string& user_id,
1570 const WallpaperInfo& info, 1576 const WallpaperInfo& info,
1571 bool update_wallpaper, 1577 bool update_wallpaper,
1572 const base::FilePath& wallpaper_path, 1578 const base::FilePath& wallpaper_path,
1573 MovableOnDestroyCallbackHolder on_finish) { 1579 MovableOnDestroyCallbackHolder on_finish) {
1574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1575 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); 1581 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this);
1576 1582
1577 wallpaper_loader_->Start(wallpaper_path.value(), 1583 wallpaper_loader_->Start(wallpaper_path.value(),
1578 0, // Do not crop. 1584 0, // Do not crop.
1579 base::Bind(&WallpaperManager::OnWallpaperDecoded, 1585 base::Bind(&WallpaperManager::OnWallpaperDecoded,
1580 base::Unretained(this), 1586 weak_factory_.GetWeakPtr(),
1581 user_id, 1587 user_id,
1582 info.layout, 1588 info.layout,
1583 update_wallpaper, 1589 update_wallpaper,
1584 base::Passed(on_finish.Pass()))); 1590 base::Passed(on_finish.Pass())));
1585 } 1591 }
1586 1592
1587 void WallpaperManager::SaveLastLoadTime(const base::TimeDelta elapsed) { 1593 void WallpaperManager::SaveLastLoadTime(const base::TimeDelta elapsed) {
1588 while (last_load_times_.size() >= kLastLoadsStatsMsMaxSize) 1594 while (last_load_times_.size() >= kLastLoadsStatsMsMaxSize)
1589 last_load_times_.pop_front(); 1595 last_load_times_.pop_front();
1590 1596
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 wallpaper.image().EnsureRepsForSupportedScales(); 1672 wallpaper.image().EnsureRepsForSupportedScales();
1667 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); 1673 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
1668 1674
1669 scoped_ptr<bool> success(new bool(false)); 1675 scoped_ptr<bool> success(new bool(false));
1670 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia); 1676 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia);
1671 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia); 1677 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia);
1672 1678
1673 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 1679 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
1674 base::Closure resize_closure = 1680 base::Closure resize_closure =
1675 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, 1681 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper,
1676 base::Unretained(this),
1677 base::Passed(&deep_copy), 1682 base::Passed(&deep_copy),
1678 wallpaper.raw_image(), 1683 wallpaper.raw_image(),
1679 base::Unretained(rescaled_files.get()), 1684 base::Unretained(rescaled_files.get()),
1680 base::Unretained(success.get()), 1685 base::Unretained(success.get()),
1681 base::Unretained(small_wallpaper_image.get()), 1686 base::Unretained(small_wallpaper_image.get()),
1682 base::Unretained(large_wallpaper_image.get())); 1687 base::Unretained(large_wallpaper_image.get()));
1683 base::Closure on_resized_closure = 1688 base::Closure on_resized_closure =
1684 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, 1689 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized,
1685 weak_factory_.GetWeakPtr(), 1690 weak_factory_.GetWeakPtr(),
1686 wallpaper_url, 1691 wallpaper_url,
1687 base::Passed(rescaled_files.Pass()), 1692 base::Passed(rescaled_files.Pass()),
1688 base::Passed(success.Pass()), 1693 base::Passed(success.Pass()),
1689 base::Passed(small_wallpaper_image.Pass()), 1694 base::Passed(small_wallpaper_image.Pass()),
1690 base::Passed(large_wallpaper_image.Pass())); 1695 base::Passed(large_wallpaper_image.Pass()));
1691 1696
1692 if (!task_runner_->PostTaskAndReply( 1697 if (!task_runner_->PostTaskAndReply(
1693 FROM_HERE, resize_closure, on_resized_closure)) { 1698 FROM_HERE, resize_closure, on_resized_closure)) {
1694 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; 1699 LOG(WARNING) << "Failed to start Customized Wallpaper resize.";
1695 } 1700 }
1696 } 1701 }
1697 1702
1698 void WallpaperManager::ResizeCustomizedDefaultWallpaper( 1703 void WallpaperManager::ResizeCustomizedDefaultWallpaper(
1699 scoped_ptr<gfx::ImageSkia> image, 1704 scoped_ptr<gfx::ImageSkia> image,
1700 const UserImage::RawImage& raw_image, 1705 const UserImage::RawImage& raw_image,
1701 const CustomizedWallpaperRescaledFiles* rescaled_files, 1706 const CustomizedWallpaperRescaledFiles* rescaled_files,
1702 bool* success, 1707 bool* success,
1703 gfx::ImageSkia* small_wallpaper_image, 1708 gfx::ImageSkia* small_wallpaper_image,
1704 gfx::ImageSkia* large_wallpaper_image) { 1709 gfx::ImageSkia* large_wallpaper_image) {
1705 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
1706 sequence_token_));
1707
1708 *success = true; 1710 *success = true;
1709 1711
1710 *success &= ResizeAndSaveWallpaper(*image, 1712 *success &= ResizeAndSaveWallpaper(*image,
1711 rescaled_files->path_rescaled_small(), 1713 rescaled_files->path_rescaled_small(),
1712 ash::WALLPAPER_LAYOUT_STRETCH, 1714 ash::WALLPAPER_LAYOUT_STRETCH,
1713 kSmallWallpaperMaxWidth, 1715 kSmallWallpaperMaxWidth,
1714 kSmallWallpaperMaxHeight, 1716 kSmallWallpaperMaxHeight,
1715 small_wallpaper_image); 1717 small_wallpaper_image);
1716 1718
1717 *success &= ResizeAndSaveWallpaper(*image, 1719 *success &= ResizeAndSaveWallpaper(*image,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 loaded_wallpapers_++; 1908 loaded_wallpapers_++;
1907 SkBitmap bitmap; 1909 SkBitmap bitmap;
1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); 1910 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0);
1909 bitmap.allocPixels(); 1911 bitmap.allocPixels();
1910 bitmap.eraseColor(kDefaultWallpaperColor); 1912 bitmap.eraseColor(kDefaultWallpaperColor);
1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1913 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1912 default_wallpaper_image_.reset(new UserImage(image)); 1914 default_wallpaper_image_.reset(new UserImage(image));
1913 } 1915 }
1914 1916
1915 } // namespace chromeos 1917 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698