| OLD | NEW |
| 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 Loading... |
| 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 | |
| 177 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash) { | 176 void EnsureCustomWallpaperDirectories(const std::string& user_id_hash) { |
| 178 base::FilePath dir; | 177 base::FilePath dir; |
| 179 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir); | 178 dir = GetCustomWallpaperDir(kSmallWallpaperSubDir); |
| 180 dir = dir.Append(user_id_hash); | 179 dir = dir.Append(user_id_hash); |
| 181 if (!base::PathExists(dir)) | 180 if (!base::PathExists(dir)) |
| 182 base::CreateDirectory(dir); | 181 base::CreateDirectory(dir); |
| 183 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir); | 182 dir = GetCustomWallpaperDir(kLargeWallpaperSubDir); |
| 184 dir = dir.Append(user_id_hash); | 183 dir = dir.Append(user_id_hash); |
| 185 if (!base::PathExists(dir)) | 184 if (!base::PathExists(dir)) |
| 186 base::CreateDirectory(dir); | 185 base::CreateDirectory(dir); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); | 519 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); |
| 521 registry->RegisterDictionaryPref(kUserWallpapers); | 520 registry->RegisterDictionaryPref(kUserWallpapers); |
| 522 registry->RegisterDictionaryPref(kUserWallpapersProperties); | 521 registry->RegisterDictionaryPref(kUserWallpapersProperties); |
| 523 } | 522 } |
| 524 | 523 |
| 525 void WallpaperManager::AddObservers() { | 524 void WallpaperManager::AddObservers() { |
| 526 show_user_name_on_signin_subscription_ = | 525 show_user_name_on_signin_subscription_ = |
| 527 CrosSettings::Get()->AddSettingsObserver( | 526 CrosSettings::Get()->AddSettingsObserver( |
| 528 kAccountsPrefShowUserNamesOnSignIn, | 527 kAccountsPrefShowUserNamesOnSignIn, |
| 529 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, | 528 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, |
| 530 weak_factory_.GetWeakPtr())); | 529 base::Unretained(this))); |
| 531 } | 530 } |
| 532 | 531 |
| 533 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { | 532 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { |
| 534 // Some browser tests do not have a shell instance. As no wallpaper is needed | 533 // Some browser tests do not have a shell instance. As no wallpaper is needed |
| 535 // in these tests anyway, avoid loading one, preventing crashes and speeding | 534 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 536 // up the tests. | 535 // up the tests. |
| 537 if (!ash::Shell::HasInstance()) | 536 if (!ash::Shell::HasInstance()) |
| 538 return; | 537 return; |
| 539 | 538 |
| 540 WallpaperInfo info; | 539 WallpaperInfo info; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 563 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin(); | 562 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin(); |
| 564 it != wallpaper_cache_.end(); ++it) { | 563 it != wallpaper_cache_.end(); ++it) { |
| 565 if (logged_in_users_names.find(it->first) != | 564 if (logged_in_users_names.find(it->first) != |
| 566 logged_in_users_names.end()) { | 565 logged_in_users_names.end()) { |
| 567 logged_in_users_cache.insert(*it); | 566 logged_in_users_cache.insert(*it); |
| 568 } | 567 } |
| 569 } | 568 } |
| 570 wallpaper_cache_ = logged_in_users_cache; | 569 wallpaper_cache_ = logged_in_users_cache; |
| 571 } | 570 } |
| 572 | 571 |
| 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 |
| 573 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { | 580 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { |
| 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 575 | 582 |
| 576 if (UserManager::Get()->IsLoggedInAsStub()) { | 583 if (UserManager::Get()->IsLoggedInAsStub()) { |
| 577 info->file = current_user_wallpaper_info_.file = ""; | 584 info->file = current_user_wallpaper_info_.file = ""; |
| 578 info->layout = current_user_wallpaper_info_.layout = | 585 info->layout = current_user_wallpaper_info_.layout = |
| 579 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 586 ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 580 info->type = current_user_wallpaper_info_.type = User::DEFAULT; | 587 info->type = current_user_wallpaper_info_.type = User::DEFAULT; |
| 581 info->date = current_user_wallpaper_info_.date = | 588 info->date = current_user_wallpaper_info_.date = |
| 582 base::Time::Now().LocalMidnight(); | 589 base::Time::Now().LocalMidnight(); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 WallpaperManager::GetAppropriateResolution() { | 821 WallpaperManager::GetAppropriateResolution() { |
| 815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 816 gfx::Size size = | 823 gfx::Size size = |
| 817 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); | 824 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); |
| 818 return (size.width() > kSmallWallpaperMaxWidth || | 825 return (size.width() > kSmallWallpaperMaxWidth || |
| 819 size.height() > kSmallWallpaperMaxHeight) | 826 size.height() > kSmallWallpaperMaxHeight) |
| 820 ? WALLPAPER_RESOLUTION_LARGE | 827 ? WALLPAPER_RESOLUTION_LARGE |
| 821 : WALLPAPER_RESOLUTION_SMALL; | 828 : WALLPAPER_RESOLUTION_SMALL; |
| 822 } | 829 } |
| 823 | 830 |
| 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("Ash.Wallpaper.Type", type, | |
| 836 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 | |
| 878 void WallpaperManager::SetPolicyControlledWallpaper( | 831 void WallpaperManager::SetPolicyControlledWallpaper( |
| 879 const std::string& user_id, | 832 const std::string& user_id, |
| 880 const UserImage& user_image) { | 833 const UserImage& user_image) { |
| 881 const User *user = chromeos::UserManager::Get()->FindUser(user_id); | 834 const User *user = chromeos::UserManager::Get()->FindUser(user_id); |
| 882 if (!user) { | 835 if (!user) { |
| 883 NOTREACHED() << "Unknown user."; | 836 NOTREACHED() << "Unknown user."; |
| 884 return; | 837 return; |
| 885 } | 838 } |
| 886 SetCustomWallpaper(user_id, | 839 SetCustomWallpaper(user_id, |
| 887 user->username_hash(), | 840 user->username_hash(), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper | 889 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper |
| 937 // that the user selected. | 890 // that the user selected. |
| 938 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | 891 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = |
| 939 BrowserThread::GetBlockingPool() | 892 BrowserThread::GetBlockingPool() |
| 940 ->GetSequencedTaskRunnerWithShutdownBehavior( | 893 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 941 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 894 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 942 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | 895 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. |
| 943 blocking_task_runner->PostTask( | 896 blocking_task_runner->PostTask( |
| 944 FROM_HERE, | 897 FROM_HERE, |
| 945 base::Bind(&WallpaperManager::SaveCustomWallpaper, | 898 base::Bind(&WallpaperManager::SaveCustomWallpaper, |
| 899 base::Unretained(this), |
| 946 user_id_hash, | 900 user_id_hash, |
| 947 base::FilePath(wallpaper_info.file), | 901 base::FilePath(wallpaper_info.file), |
| 948 wallpaper_info.layout, | 902 wallpaper_info.layout, |
| 949 base::Passed(deep_copy.Pass()))); | 903 base::Passed(deep_copy.Pass()))); |
| 950 } | 904 } |
| 951 | 905 |
| 952 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); | 906 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); |
| 953 // User's custom wallpaper path is determined by relative path and the | 907 // User's custom wallpaper path is determined by relative path and the |
| 954 // appropriate wallpaper resolution in GetCustomWallpaperInternal. | 908 // appropriate wallpaper resolution in GetCustomWallpaperInternal. |
| 955 WallpaperInfo info = { | 909 WallpaperInfo info = { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 | 1174 |
| 1221 base::FilePath wallpaper_dir; | 1175 base::FilePath wallpaper_dir; |
| 1222 base::FilePath wallpaper_path; | 1176 base::FilePath wallpaper_path; |
| 1223 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 1177 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
| 1224 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 1178 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
| 1225 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 1179 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 1226 wallpaper_path = wallpaper_path.Append(info.file); | 1180 wallpaper_path = wallpaper_path.Append(info.file); |
| 1227 task_runner_->PostTask( | 1181 task_runner_->PostTask( |
| 1228 FROM_HERE, | 1182 FROM_HERE, |
| 1229 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 1183 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
| 1230 weak_factory_.GetWeakPtr(), | 1184 base::Unretained(this), |
| 1231 user_id, | 1185 user_id, |
| 1232 info, | 1186 info, |
| 1233 wallpaper_path, | 1187 wallpaper_path, |
| 1234 false /* do not update wallpaper */, | 1188 false /* do not update wallpaper */, |
| 1235 base::Passed(MovableOnDestroyCallbackHolder()))); | 1189 base::Passed(MovableOnDestroyCallbackHolder()))); |
| 1236 return; | 1190 return; |
| 1237 } | 1191 } |
| 1238 LoadWallpaper(user_id, | 1192 LoadWallpaper(user_id, |
| 1239 info, | 1193 info, |
| 1240 false /* do not update wallpaper */, | 1194 false /* do not update wallpaper */, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 IsRunningSequenceOnCurrentThread(sequence_token_)); | 1394 IsRunningSequenceOnCurrentThread(sequence_token_)); |
| 1441 if (MoveCustomWallpaperDirectory( | 1395 if (MoveCustomWallpaperDirectory( |
| 1442 kOriginalWallpaperSubDir, user_id, user_id_hash)) { | 1396 kOriginalWallpaperSubDir, user_id, user_id_hash)) { |
| 1443 // Consider success if the original wallpaper is moved to the new directory. | 1397 // Consider success if the original wallpaper is moved to the new directory. |
| 1444 // Original wallpaper is the fallback if the correct resolution wallpaper | 1398 // Original wallpaper is the fallback if the correct resolution wallpaper |
| 1445 // can not be found. | 1399 // can not be found. |
| 1446 BrowserThread::PostTask( | 1400 BrowserThread::PostTask( |
| 1447 BrowserThread::UI, | 1401 BrowserThread::UI, |
| 1448 FROM_HERE, | 1402 FROM_HERE, |
| 1449 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess, | 1403 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess, |
| 1450 weak_factory_.GetWeakPtr(), | 1404 base::Unretained(this), |
| 1451 user_id, | 1405 user_id, |
| 1452 user_id_hash)); | 1406 user_id_hash)); |
| 1453 } | 1407 } |
| 1454 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash); | 1408 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash); |
| 1455 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash); | 1409 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash); |
| 1456 MoveCustomWallpaperDirectory( | 1410 MoveCustomWallpaperDirectory( |
| 1457 kThumbnailWallpaperSubDir, user_id, user_id_hash); | 1411 kThumbnailWallpaperSubDir, user_id, user_id_hash); |
| 1458 } | 1412 } |
| 1459 | 1413 |
| 1460 void WallpaperManager::MoveCustomWallpapersSuccess( | 1414 void WallpaperManager::MoveCustomWallpapersSuccess( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1472 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); | 1426 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); |
| 1473 SetUserWallpaperInfo(user_id, info, is_persistent); | 1427 SetUserWallpaperInfo(user_id, info, is_persistent); |
| 1474 } | 1428 } |
| 1475 } | 1429 } |
| 1476 | 1430 |
| 1477 void WallpaperManager::MoveLoggedInUserCustomWallpaper() { | 1431 void WallpaperManager::MoveLoggedInUserCustomWallpaper() { |
| 1478 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); | 1432 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); |
| 1479 task_runner_->PostTask( | 1433 task_runner_->PostTask( |
| 1480 FROM_HERE, | 1434 FROM_HERE, |
| 1481 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker, | 1435 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker, |
| 1482 weak_factory_.GetWeakPtr(), | 1436 base::Unretained(this), |
| 1483 logged_in_user->email(), | 1437 logged_in_user->email(), |
| 1484 logged_in_user->username_hash())); | 1438 logged_in_user->username_hash())); |
| 1485 } | 1439 } |
| 1486 | 1440 |
| 1487 void WallpaperManager::GetCustomWallpaperInternal( | 1441 void WallpaperManager::GetCustomWallpaperInternal( |
| 1488 const std::string& user_id, | 1442 const std::string& user_id, |
| 1489 const WallpaperInfo& info, | 1443 const WallpaperInfo& info, |
| 1490 const base::FilePath& wallpaper_path, | 1444 const base::FilePath& wallpaper_path, |
| 1491 bool update_wallpaper, | 1445 bool update_wallpaper, |
| 1492 MovableOnDestroyCallbackHolder on_finish) { | 1446 MovableOnDestroyCallbackHolder on_finish) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1508 valid_path = | 1462 valid_path = |
| 1509 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file); | 1463 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file); |
| 1510 } | 1464 } |
| 1511 | 1465 |
| 1512 if (!base::PathExists(valid_path)) { | 1466 if (!base::PathExists(valid_path)) { |
| 1513 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << | 1467 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << |
| 1514 "Fallback to default wallpaper"; | 1468 "Fallback to default wallpaper"; |
| 1515 BrowserThread::PostTask(BrowserThread::UI, | 1469 BrowserThread::PostTask(BrowserThread::UI, |
| 1516 FROM_HERE, | 1470 FROM_HERE, |
| 1517 base::Bind(&WallpaperManager::DoSetDefaultWallpaper, | 1471 base::Bind(&WallpaperManager::DoSetDefaultWallpaper, |
| 1518 weak_factory_.GetWeakPtr(), | 1472 base::Unretained(this), |
| 1519 user_id, | 1473 user_id, |
| 1520 base::Passed(on_finish.Pass()))); | 1474 base::Passed(on_finish.Pass()))); |
| 1521 } else { | 1475 } else { |
| 1522 BrowserThread::PostTask(BrowserThread::UI, | 1476 BrowserThread::PostTask(BrowserThread::UI, |
| 1523 FROM_HERE, | 1477 FROM_HERE, |
| 1524 base::Bind(&WallpaperManager::StartLoad, | 1478 base::Bind(&WallpaperManager::StartLoad, |
| 1525 weak_factory_.GetWeakPtr(), | 1479 base::Unretained(this), |
| 1526 user_id, | 1480 user_id, |
| 1527 info, | 1481 info, |
| 1528 update_wallpaper, | 1482 update_wallpaper, |
| 1529 valid_path, | 1483 valid_path, |
| 1530 base::Passed(on_finish.Pass()))); | 1484 base::Passed(on_finish.Pass()))); |
| 1531 } | 1485 } |
| 1532 } | 1486 } |
| 1533 | 1487 |
| 1534 void WallpaperManager::OnWallpaperDecoded( | 1488 void WallpaperManager::OnWallpaperDecoded( |
| 1535 const std::string& user_id, | 1489 const std::string& user_id, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1559 | 1513 |
| 1560 wallpaper_cache_[user_id] = user_image.image(); | 1514 wallpaper_cache_[user_id] = user_image.image(); |
| 1561 | 1515 |
| 1562 if (update_wallpaper) { | 1516 if (update_wallpaper) { |
| 1563 ash::Shell::GetInstance() | 1517 ash::Shell::GetInstance() |
| 1564 ->desktop_background_controller() | 1518 ->desktop_background_controller() |
| 1565 ->SetWallpaperImage(user_image.image(), layout); | 1519 ->SetWallpaperImage(user_image.image(), layout); |
| 1566 } | 1520 } |
| 1567 } | 1521 } |
| 1568 | 1522 |
| 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, | 1569 void WallpaperManager::StartLoad(const std::string& user_id, |
| 1570 const WallpaperInfo& info, | 1570 const WallpaperInfo& info, |
| 1571 bool update_wallpaper, | 1571 bool update_wallpaper, |
| 1572 const base::FilePath& wallpaper_path, | 1572 const base::FilePath& wallpaper_path, |
| 1573 MovableOnDestroyCallbackHolder on_finish) { | 1573 MovableOnDestroyCallbackHolder on_finish) { |
| 1574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1575 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1575 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| 1576 | 1576 |
| 1577 wallpaper_loader_->Start(wallpaper_path.value(), | 1577 wallpaper_loader_->Start(wallpaper_path.value(), |
| 1578 0, // Do not crop. | 1578 0, // Do not crop. |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 loaded_wallpapers_++; | 1906 loaded_wallpapers_++; |
| 1907 SkBitmap bitmap; | 1907 SkBitmap bitmap; |
| 1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); | 1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); |
| 1909 bitmap.allocPixels(); | 1909 bitmap.allocPixels(); |
| 1910 bitmap.eraseColor(kDefaultWallpaperColor); | 1910 bitmap.eraseColor(kDefaultWallpaperColor); |
| 1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 1912 default_wallpaper_image_.reset(new UserImage(image)); | 1912 default_wallpaper_image_.reset(new UserImage(image)); |
| 1913 } | 1913 } |
| 1914 | 1914 |
| 1915 } // namespace chromeos | 1915 } // namespace chromeos |
| OLD | NEW |