| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 370 } |
| 371 | 371 |
| 372 void WallpaperManager::InitializeWallpaper() { | 372 void WallpaperManager::InitializeWallpaper() { |
| 373 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 373 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 374 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 374 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 375 | 375 |
| 376 // Apply device customization. | 376 // Apply device customization. |
| 377 if (ShouldUseCustomizedDefaultWallpaper()) { | 377 if (ShouldUseCustomizedDefaultWallpaper()) { |
| 378 SetDefaultWallpaperPath(GetCustomizedWallpaperDefaultRescaledFileName( | 378 SetDefaultWallpaperPath(GetCustomizedWallpaperDefaultRescaledFileName( |
| 379 wallpaper::kSmallWallpaperSuffix), | 379 wallpaper::kSmallWallpaperSuffix), |
| 380 scoped_ptr<gfx::ImageSkia>(), | 380 std::unique_ptr<gfx::ImageSkia>(), |
| 381 GetCustomizedWallpaperDefaultRescaledFileName( | 381 GetCustomizedWallpaperDefaultRescaledFileName( |
| 382 wallpaper::kLargeWallpaperSuffix), | 382 wallpaper::kLargeWallpaperSuffix), |
| 383 scoped_ptr<gfx::ImageSkia>()); | 383 std::unique_ptr<gfx::ImageSkia>()); |
| 384 } | 384 } |
| 385 | 385 |
| 386 base::CommandLine* command_line = GetCommandLine(); | 386 base::CommandLine* command_line = GetCommandLine(); |
| 387 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 387 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
| 388 // Guest wallpaper should be initialized when guest login. | 388 // Guest wallpaper should be initialized when guest login. |
| 389 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 389 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
| 390 // used here to determine if current user is guest. | 390 // used here to determine if current user is guest. |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 | 393 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 GetUserWallpaperInfo(account_id, &info); | 468 GetUserWallpaperInfo(account_id, &info); |
| 469 DictionaryPrefUpdate prefs_wallpapers_info_update( | 469 DictionaryPrefUpdate prefs_wallpapers_info_update( |
| 470 prefs, wallpaper::kUsersWallpaperInfo); | 470 prefs, wallpaper::kUsersWallpaperInfo); |
| 471 prefs_wallpapers_info_update->RemoveWithoutPathExpansion( | 471 prefs_wallpapers_info_update->RemoveWithoutPathExpansion( |
| 472 account_id.GetUserEmail(), NULL); | 472 account_id.GetUserEmail(), NULL); |
| 473 DeleteUserWallpapers(account_id, info.location); | 473 DeleteUserWallpapers(account_id, info.location); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void WallpaperManager::OnPolicyFetched(const std::string& policy, | 476 void WallpaperManager::OnPolicyFetched(const std::string& policy, |
| 477 const AccountId& account_id, | 477 const AccountId& account_id, |
| 478 scoped_ptr<std::string> data) { | 478 std::unique_ptr<std::string> data) { |
| 479 if (!data) | 479 if (!data) |
| 480 return; | 480 return; |
| 481 | 481 |
| 482 user_image_loader::StartWithData( | 482 user_image_loader::StartWithData( |
| 483 task_runner_, std::move(data), ImageDecoder::ROBUST_JPEG_CODEC, | 483 task_runner_, std::move(data), ImageDecoder::ROBUST_JPEG_CODEC, |
| 484 0, // Do not crop. | 484 0, // Do not crop. |
| 485 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, | 485 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, |
| 486 weak_factory_.GetWeakPtr(), account_id)); | 486 weak_factory_.GetWeakPtr(), account_id)); |
| 487 } | 487 } |
| 488 | 488 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 525 |
| 526 WallpaperInfo wallpaper_info = { | 526 WallpaperInfo wallpaper_info = { |
| 527 wallpaper_path.value(), | 527 wallpaper_path.value(), |
| 528 layout, | 528 layout, |
| 529 type, | 529 type, |
| 530 // Date field is not used. | 530 // Date field is not used. |
| 531 base::Time::Now().LocalMidnight() | 531 base::Time::Now().LocalMidnight() |
| 532 }; | 532 }; |
| 533 if (is_persistent) { | 533 if (is_persistent) { |
| 534 image.EnsureRepsForSupportedScales(); | 534 image.EnsureRepsForSupportedScales(); |
| 535 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 535 std::unique_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
| 536 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper | 536 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper |
| 537 // that the user selected. | 537 // that the user selected. |
| 538 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | 538 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = |
| 539 BrowserThread::GetBlockingPool() | 539 BrowserThread::GetBlockingPool() |
| 540 ->GetSequencedTaskRunnerWithShutdownBehavior( | 540 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 541 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 541 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 542 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | 542 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. |
| 543 blocking_task_runner->PostTask( | 543 blocking_task_runner->PostTask( |
| 544 FROM_HERE, | 544 FROM_HERE, |
| 545 base::Bind(&WallpaperManager::SaveCustomWallpaper, wallpaper_files_id, | 545 base::Bind(&WallpaperManager::SaveCustomWallpaper, wallpaper_files_id, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 break; | 820 break; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 | 823 |
| 824 if (loading_.empty()) | 824 if (loading_.empty()) |
| 825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); | 825 FOR_EACH_OBSERVER(Observer, observers_, OnPendingListEmptyForTesting()); |
| 826 } | 826 } |
| 827 | 827 |
| 828 void WallpaperManager::SetPolicyControlledWallpaper( | 828 void WallpaperManager::SetPolicyControlledWallpaper( |
| 829 const AccountId& account_id, | 829 const AccountId& account_id, |
| 830 scoped_ptr<user_manager::UserImage> user_image) { | 830 std::unique_ptr<user_manager::UserImage> user_image) { |
| 831 const user_manager::User* user = | 831 const user_manager::User* user = |
| 832 user_manager::UserManager::Get()->FindUser(account_id); | 832 user_manager::UserManager::Get()->FindUser(account_id); |
| 833 if (!user) { | 833 if (!user) { |
| 834 NOTREACHED() << "Unknown user."; | 834 NOTREACHED() << "Unknown user."; |
| 835 return; | 835 return; |
| 836 } | 836 } |
| 837 | 837 |
| 838 const wallpaper::WallpaperFilesId wallpaper_files_id = | 838 const wallpaper::WallpaperFilesId wallpaper_files_id = |
| 839 GetKnownUserWallpaperFilesId(*user); | 839 GetKnownUserWallpaperFilesId(*user); |
| 840 if (!wallpaper_files_id.is_valid()) { | 840 if (!wallpaper_files_id.is_valid()) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 info->type = static_cast<user_manager::User::WallpaperType>(type); | 940 info->type = static_cast<user_manager::User::WallpaperType>(type); |
| 941 info->date = base::Time::FromInternalValue(date_val); | 941 info->date = base::Time::FromInternalValue(date_val); |
| 942 return true; | 942 return true; |
| 943 } | 943 } |
| 944 | 944 |
| 945 void WallpaperManager::OnWallpaperDecoded( | 945 void WallpaperManager::OnWallpaperDecoded( |
| 946 const AccountId& account_id, | 946 const AccountId& account_id, |
| 947 wallpaper::WallpaperLayout layout, | 947 wallpaper::WallpaperLayout layout, |
| 948 bool update_wallpaper, | 948 bool update_wallpaper, |
| 949 MovableOnDestroyCallbackHolder on_finish, | 949 MovableOnDestroyCallbackHolder on_finish, |
| 950 scoped_ptr<user_manager::UserImage> user_image) { | 950 std::unique_ptr<user_manager::UserImage> user_image) { |
| 951 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 951 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 952 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); | 952 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); |
| 953 | 953 |
| 954 // If decoded wallpaper is empty, we have probably failed to decode the file. | 954 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 955 // Use default wallpaper in this case. | 955 // Use default wallpaper in this case. |
| 956 if (user_image->image().isNull()) { | 956 if (user_image->image().isNull()) { |
| 957 // Updates user pref to default wallpaper. | 957 // Updates user pref to default wallpaper. |
| 958 WallpaperInfo info = {"", | 958 WallpaperInfo info = {"", |
| 959 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, | 959 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 960 user_manager::User::DEFAULT, | 960 user_manager::User::DEFAULT, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 task_runner_, wallpaper_path, ImageDecoder::ROBUST_JPEG_CODEC, | 993 task_runner_, wallpaper_path, ImageDecoder::ROBUST_JPEG_CODEC, |
| 994 0, // Do not crop. | 994 0, // Do not crop. |
| 995 base::Bind(&WallpaperManager::OnWallpaperDecoded, | 995 base::Bind(&WallpaperManager::OnWallpaperDecoded, |
| 996 weak_factory_.GetWeakPtr(), account_id, info.layout, | 996 weak_factory_.GetWeakPtr(), account_id, info.layout, |
| 997 update_wallpaper, base::Passed(std::move(on_finish)))); | 997 update_wallpaper, base::Passed(std::move(on_finish)))); |
| 998 } | 998 } |
| 999 | 999 |
| 1000 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( | 1000 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( |
| 1001 const GURL& wallpaper_url, | 1001 const GURL& wallpaper_url, |
| 1002 const base::FilePath& downloaded_file, | 1002 const base::FilePath& downloaded_file, |
| 1003 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) { | 1003 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) { |
| 1004 PrefService* pref_service = g_browser_process->local_state(); | 1004 PrefService* pref_service = g_browser_process->local_state(); |
| 1005 | 1005 |
| 1006 std::string current_url = | 1006 std::string current_url = |
| 1007 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); | 1007 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); |
| 1008 if (current_url != wallpaper_url.spec() || !rescaled_files->AllSizesExist()) { | 1008 if (current_url != wallpaper_url.spec() || !rescaled_files->AllSizesExist()) { |
| 1009 DCHECK(rescaled_files->downloaded_exists()); | 1009 DCHECK(rescaled_files->downloaded_exists()); |
| 1010 | 1010 |
| 1011 // Either resized images do not exist or cached version is incorrect. | 1011 // Either resized images do not exist or cached version is incorrect. |
| 1012 // Need to start resize again. | 1012 // Need to start resize again. |
| 1013 user_image_loader::StartWithFilePath( | 1013 user_image_loader::StartWithFilePath( |
| 1014 task_runner_, downloaded_file, ImageDecoder::ROBUST_JPEG_CODEC, | 1014 task_runner_, downloaded_file, ImageDecoder::ROBUST_JPEG_CODEC, |
| 1015 0, // Do not crop. | 1015 0, // Do not crop. |
| 1016 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, | 1016 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, |
| 1017 weak_factory_.GetWeakPtr(), wallpaper_url, | 1017 weak_factory_.GetWeakPtr(), wallpaper_url, |
| 1018 base::Passed(std::move(rescaled_files)))); | 1018 base::Passed(std::move(rescaled_files)))); |
| 1019 } else { | 1019 } else { |
| 1020 SetDefaultWallpaperPath( | 1020 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), |
| 1021 rescaled_files->path_rescaled_small(), scoped_ptr<gfx::ImageSkia>(), | 1021 std::unique_ptr<gfx::ImageSkia>(), |
| 1022 rescaled_files->path_rescaled_large(), scoped_ptr<gfx::ImageSkia>()); | 1022 rescaled_files->path_rescaled_large(), |
| 1023 std::unique_ptr<gfx::ImageSkia>()); |
| 1023 } | 1024 } |
| 1024 } | 1025 } |
| 1025 | 1026 |
| 1026 void WallpaperManager::OnCustomizedDefaultWallpaperResized( | 1027 void WallpaperManager::OnCustomizedDefaultWallpaperResized( |
| 1027 const GURL& wallpaper_url, | 1028 const GURL& wallpaper_url, |
| 1028 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 1029 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 1029 scoped_ptr<bool> success, | 1030 std::unique_ptr<bool> success, |
| 1030 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 1031 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 1031 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | 1032 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) { |
| 1032 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1033 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1033 DCHECK(rescaled_files); | 1034 DCHECK(rescaled_files); |
| 1034 DCHECK(success.get()); | 1035 DCHECK(success.get()); |
| 1035 if (!*success) { | 1036 if (!*success) { |
| 1036 LOG(WARNING) << "Failed to save resized customized default wallpaper"; | 1037 LOG(WARNING) << "Failed to save resized customized default wallpaper"; |
| 1037 return; | 1038 return; |
| 1038 } | 1039 } |
| 1039 PrefService* pref_service = g_browser_process->local_state(); | 1040 PrefService* pref_service = g_browser_process->local_state(); |
| 1040 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL, | 1041 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL, |
| 1041 wallpaper_url.spec()); | 1042 wallpaper_url.spec()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1066 child_small_wallpaper_file_ = command_line->GetSwitchValuePath( | 1067 child_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1067 chromeos::switches::kChildWallpaperSmall); | 1068 chromeos::switches::kChildWallpaperSmall); |
| 1068 child_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1069 child_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1069 chromeos::switches::kChildWallpaperLarge); | 1070 chromeos::switches::kChildWallpaperLarge); |
| 1070 default_wallpaper_image_.reset(); | 1071 default_wallpaper_image_.reset(); |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 void WallpaperManager::OnDefaultWallpaperDecoded( | 1074 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1074 const base::FilePath& path, | 1075 const base::FilePath& path, |
| 1075 const wallpaper::WallpaperLayout layout, | 1076 const wallpaper::WallpaperLayout layout, |
| 1076 scoped_ptr<user_manager::UserImage>* result_out, | 1077 std::unique_ptr<user_manager::UserImage>* result_out, |
| 1077 MovableOnDestroyCallbackHolder on_finish, | 1078 MovableOnDestroyCallbackHolder on_finish, |
| 1078 scoped_ptr<user_manager::UserImage> user_image) { | 1079 std::unique_ptr<user_manager::UserImage> user_image) { |
| 1079 *result_out = std::move(user_image); | 1080 *result_out = std::move(user_image); |
| 1080 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1081 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 1081 (*result_out)->image(), layout); | 1082 (*result_out)->image(), layout); |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1085 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1085 const base::FilePath& path, | 1086 const base::FilePath& path, |
| 1086 const wallpaper::WallpaperLayout layout, | 1087 const wallpaper::WallpaperLayout layout, |
| 1087 MovableOnDestroyCallbackHolder on_finish, | 1088 MovableOnDestroyCallbackHolder on_finish, |
| 1088 scoped_ptr<user_manager::UserImage>* result_out) { | 1089 std::unique_ptr<user_manager::UserImage>* result_out) { |
| 1089 user_image_loader::StartWithFilePath( | 1090 user_image_loader::StartWithFilePath( |
| 1090 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, | 1091 task_runner_, path, ImageDecoder::ROBUST_JPEG_CODEC, |
| 1091 0, // Do not crop. | 1092 0, // Do not crop. |
| 1092 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | 1093 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
| 1093 weak_factory_.GetWeakPtr(), path, layout, | 1094 weak_factory_.GetWeakPtr(), path, layout, |
| 1094 base::Unretained(result_out), | 1095 base::Unretained(result_out), |
| 1095 base::Passed(std::move(on_finish)))); | 1096 base::Passed(std::move(on_finish)))); |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 void WallpaperManager::SetDefaultWallpaperPath( | 1099 void WallpaperManager::SetDefaultWallpaperPath( |
| 1099 const base::FilePath& default_small_wallpaper_file, | 1100 const base::FilePath& default_small_wallpaper_file, |
| 1100 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | 1101 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 1101 const base::FilePath& default_large_wallpaper_file, | 1102 const base::FilePath& default_large_wallpaper_file, |
| 1102 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | 1103 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image) { |
| 1103 default_small_wallpaper_file_ = default_small_wallpaper_file; | 1104 default_small_wallpaper_file_ = default_small_wallpaper_file; |
| 1104 default_large_wallpaper_file_ = default_large_wallpaper_file; | 1105 default_large_wallpaper_file_ = default_large_wallpaper_file; |
| 1105 | 1106 |
| 1106 ash::DesktopBackgroundController* dbc = | 1107 ash::DesktopBackgroundController* dbc = |
| 1107 ash::Shell::GetInstance()->desktop_background_controller(); | 1108 ash::Shell::GetInstance()->desktop_background_controller(); |
| 1108 | 1109 |
| 1109 // |need_update_screen| is true if the previous default wallpaper is visible | 1110 // |need_update_screen| is true if the previous default wallpaper is visible |
| 1110 // now, so we need to update wallpaper on the screen. | 1111 // now, so we need to update wallpaper on the screen. |
| 1111 // | 1112 // |
| 1112 // Layout is ignored here, so wallpaper::WALLPAPER_LAYOUT_CENTER is used | 1113 // Layout is ignored here, so wallpaper::WALLPAPER_LAYOUT_CENTER is used |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1136 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); | 1137 DoSetDefaultWallpaper(EmptyAccountId(), MovableOnDestroyCallbackHolder()); |
| 1137 } | 1138 } |
| 1138 } | 1139 } |
| 1139 | 1140 |
| 1140 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( | 1141 wallpaper::WallpaperFilesId WallpaperManager::GetFilesId( |
| 1141 const user_manager::User& user) const { | 1142 const user_manager::User& user) const { |
| 1142 return GetKnownUserWallpaperFilesId(user); | 1143 return GetKnownUserWallpaperFilesId(user); |
| 1143 } | 1144 } |
| 1144 | 1145 |
| 1145 } // namespace chromeos | 1146 } // namespace chromeos |
| OLD | NEW |