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

Side by Side Diff: components/wallpaper/wallpaper_manager_base.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
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 "components/wallpaper/wallpaper_manager_base.h" 5 #include "components/wallpaper/wallpaper_manager_base.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <vector> 8 #include <vector>
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // TODO(bshe): Lifetime of WallpaperManagerBase needs more consideration. 486 // TODO(bshe): Lifetime of WallpaperManagerBase needs more consideration.
487 // http://crbug.com/171694 487 // http://crbug.com/171694
488 weak_factory_.InvalidateWeakPtrs(); 488 weak_factory_.InvalidateWeakPtrs();
489 } 489 }
490 490
491 // static 491 // static
492 void WallpaperManagerBase::SaveCustomWallpaper( 492 void WallpaperManagerBase::SaveCustomWallpaper(
493 const WallpaperFilesId& wallpaper_files_id, 493 const WallpaperFilesId& wallpaper_files_id,
494 const base::FilePath& original_path, 494 const base::FilePath& original_path,
495 WallpaperLayout layout, 495 WallpaperLayout layout,
496 scoped_ptr<gfx::ImageSkia> image) { 496 std::unique_ptr<gfx::ImageSkia> image) {
497 base::DeleteFile(GetCustomWallpaperDir(kOriginalWallpaperSubDir) 497 base::DeleteFile(GetCustomWallpaperDir(kOriginalWallpaperSubDir)
498 .Append(wallpaper_files_id.id()), 498 .Append(wallpaper_files_id.id()),
499 true /* recursive */); 499 true /* recursive */);
500 base::DeleteFile(GetCustomWallpaperDir(kSmallWallpaperSubDir) 500 base::DeleteFile(GetCustomWallpaperDir(kSmallWallpaperSubDir)
501 .Append(wallpaper_files_id.id()), 501 .Append(wallpaper_files_id.id()),
502 true /* recursive */); 502 true /* recursive */);
503 base::DeleteFile(GetCustomWallpaperDir(kLargeWallpaperSubDir) 503 base::DeleteFile(GetCustomWallpaperDir(kLargeWallpaperSubDir)
504 .Append(wallpaper_files_id.id()), 504 .Append(wallpaper_files_id.id()),
505 true /* recursive */); 505 true /* recursive */);
506 EnsureCustomWallpaperDirectories(wallpaper_files_id); 506 EnsureCustomWallpaperDirectories(wallpaper_files_id);
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 if (interval > delay) 903 if (interval > delay)
904 delay = base::TimeDelta::FromMilliseconds(0); 904 delay = base::TimeDelta::FromMilliseconds(0);
905 else if (interval > base::TimeDelta::FromMilliseconds(0)) 905 else if (interval > base::TimeDelta::FromMilliseconds(0))
906 delay -= interval; 906 delay -= interval;
907 } 907 }
908 return delay; 908 return delay;
909 } 909 }
910 910
911 void WallpaperManagerBase::OnCustomizedDefaultWallpaperDecoded( 911 void WallpaperManagerBase::OnCustomizedDefaultWallpaperDecoded(
912 const GURL& wallpaper_url, 912 const GURL& wallpaper_url,
913 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, 913 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
914 scoped_ptr<user_manager::UserImage> wallpaper) { 914 std::unique_ptr<user_manager::UserImage> wallpaper) {
915 DCHECK(thread_checker_.CalledOnValidThread()); 915 DCHECK(thread_checker_.CalledOnValidThread());
916 916
917 // If decoded wallpaper is empty, we have probably failed to decode the file. 917 // If decoded wallpaper is empty, we have probably failed to decode the file.
918 if (wallpaper->image().isNull()) { 918 if (wallpaper->image().isNull()) {
919 LOG(WARNING) << "Failed to decode customized wallpaper."; 919 LOG(WARNING) << "Failed to decode customized wallpaper.";
920 return; 920 return;
921 } 921 }
922 922
923 wallpaper->image().EnsureRepsForSupportedScales(); 923 wallpaper->image().EnsureRepsForSupportedScales();
924 // TODO(crbug.com/593251): DeepCopy() may be unnecessary as this function 924 // TODO(crbug.com/593251): DeepCopy() may be unnecessary as this function
925 // owns |wallpaper| as scoped_ptr whereas it used to be a const reference. 925 // owns |wallpaper| as scoped_ptr whereas it used to be a const reference.
926 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper->image().DeepCopy()); 926 std::unique_ptr<gfx::ImageSkia> deep_copy(wallpaper->image().DeepCopy());
927 927
928 scoped_ptr<bool> success(new bool(false)); 928 std::unique_ptr<bool> success(new bool(false));
929 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia); 929 std::unique_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia);
930 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia); 930 std::unique_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia);
931 931
932 // TODO(bshe): This may break if Bytes becomes RefCountedMemory. 932 // TODO(bshe): This may break if Bytes becomes RefCountedMemory.
933 base::Closure resize_closure = base::Bind( 933 base::Closure resize_closure = base::Bind(
934 &WallpaperManagerBase::ResizeCustomizedDefaultWallpaper, 934 &WallpaperManagerBase::ResizeCustomizedDefaultWallpaper,
935 base::Passed(&deep_copy), 935 base::Passed(&deep_copy),
936 base::Unretained(rescaled_files.get()), base::Unretained(success.get()), 936 base::Unretained(rescaled_files.get()), base::Unretained(success.get()),
937 base::Unretained(small_wallpaper_image.get()), 937 base::Unretained(small_wallpaper_image.get()),
938 base::Unretained(large_wallpaper_image.get())); 938 base::Unretained(large_wallpaper_image.get()));
939 base::Closure on_resized_closure = base::Bind( 939 base::Closure on_resized_closure = base::Bind(
940 &WallpaperManagerBase::OnCustomizedDefaultWallpaperResized, 940 &WallpaperManagerBase::OnCustomizedDefaultWallpaperResized,
941 weak_factory_.GetWeakPtr(), wallpaper_url, 941 weak_factory_.GetWeakPtr(), wallpaper_url,
942 base::Passed(std::move(rescaled_files)), base::Passed(std::move(success)), 942 base::Passed(std::move(rescaled_files)), base::Passed(std::move(success)),
943 base::Passed(std::move(small_wallpaper_image)), 943 base::Passed(std::move(small_wallpaper_image)),
944 base::Passed(std::move(large_wallpaper_image))); 944 base::Passed(std::move(large_wallpaper_image)));
945 945
946 if (!task_runner_->PostTaskAndReply(FROM_HERE, resize_closure, 946 if (!task_runner_->PostTaskAndReply(FROM_HERE, resize_closure,
947 on_resized_closure)) { 947 on_resized_closure)) {
948 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; 948 LOG(WARNING) << "Failed to start Customized Wallpaper resize.";
949 } 949 }
950 } 950 }
951 951
952 void WallpaperManagerBase::ResizeCustomizedDefaultWallpaper( 952 void WallpaperManagerBase::ResizeCustomizedDefaultWallpaper(
953 scoped_ptr<gfx::ImageSkia> image, 953 std::unique_ptr<gfx::ImageSkia> image,
954 const CustomizedWallpaperRescaledFiles* rescaled_files, 954 const CustomizedWallpaperRescaledFiles* rescaled_files,
955 bool* success, 955 bool* success,
956 gfx::ImageSkia* small_wallpaper_image, 956 gfx::ImageSkia* small_wallpaper_image,
957 gfx::ImageSkia* large_wallpaper_image) { 957 gfx::ImageSkia* large_wallpaper_image) {
958 *success = true; 958 *success = true;
959 959
960 *success &= ResizeAndSaveWallpaper( 960 *success &= ResizeAndSaveWallpaper(
961 *image, rescaled_files->path_rescaled_small(), WALLPAPER_LAYOUT_STRETCH, 961 *image, rescaled_files->path_rescaled_small(), WALLPAPER_LAYOUT_STRETCH,
962 kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight, small_wallpaper_image); 962 kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight, small_wallpaper_image);
963 963
964 *success &= ResizeAndSaveWallpaper( 964 *success &= ResizeAndSaveWallpaper(
965 *image, rescaled_files->path_rescaled_large(), WALLPAPER_LAYOUT_STRETCH, 965 *image, rescaled_files->path_rescaled_large(), WALLPAPER_LAYOUT_STRETCH,
966 kLargeWallpaperMaxWidth, kLargeWallpaperMaxHeight, large_wallpaper_image); 966 kLargeWallpaperMaxWidth, kLargeWallpaperMaxHeight, large_wallpaper_image);
967 } 967 }
968 968
969 void WallpaperManagerBase::SetCustomizedDefaultWallpaper( 969 void WallpaperManagerBase::SetCustomizedDefaultWallpaper(
970 const GURL& wallpaper_url, 970 const GURL& wallpaper_url,
971 const base::FilePath& downloaded_file, 971 const base::FilePath& downloaded_file,
972 const base::FilePath& resized_directory) { 972 const base::FilePath& resized_directory) {
973 // Should fail if this ever happens in tests. 973 // Should fail if this ever happens in tests.
974 DCHECK(wallpaper_url.is_valid()); 974 DCHECK(wallpaper_url.is_valid());
975 if (!wallpaper_url.is_valid()) { 975 if (!wallpaper_url.is_valid()) {
976 if (!wallpaper_url.is_empty()) { 976 if (!wallpaper_url.is_empty()) {
977 LOG(WARNING) << "Invalid Customized Wallpaper URL '" 977 LOG(WARNING) << "Invalid Customized Wallpaper URL '"
978 << wallpaper_url.spec() << "'"; 978 << wallpaper_url.spec() << "'";
979 } 979 }
980 return; 980 return;
981 } 981 }
982 std::string downloaded_file_name = downloaded_file.BaseName().value(); 982 std::string downloaded_file_name = downloaded_file.BaseName().value();
983 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( 983 std::unique_ptr<CustomizedWallpaperRescaledFiles> rescaled_files(
984 new CustomizedWallpaperRescaledFiles( 984 new CustomizedWallpaperRescaledFiles(
985 downloaded_file, resized_directory.Append(downloaded_file_name + 985 downloaded_file, resized_directory.Append(downloaded_file_name +
986 kSmallWallpaperSuffix), 986 kSmallWallpaperSuffix),
987 resized_directory.Append(downloaded_file_name + 987 resized_directory.Append(downloaded_file_name +
988 kLargeWallpaperSuffix))); 988 kLargeWallpaperSuffix)));
989 989
990 base::Closure check_file_exists = rescaled_files->CreateCheckerClosure(); 990 base::Closure check_file_exists = rescaled_files->CreateCheckerClosure();
991 base::Closure on_checked_closure = 991 base::Closure on_checked_closure =
992 base::Bind(&WallpaperManagerBase::SetCustomizedDefaultWallpaperAfterCheck, 992 base::Bind(&WallpaperManagerBase::SetCustomizedDefaultWallpaperAfterCheck,
993 weak_factory_.GetWeakPtr(), wallpaper_url, downloaded_file, 993 weak_factory_.GetWeakPtr(), wallpaper_url, downloaded_file,
(...skipping 14 matching lines...) Expand all
1008 void WallpaperManagerBase::CreateSolidDefaultWallpaper() { 1008 void WallpaperManagerBase::CreateSolidDefaultWallpaper() {
1009 loaded_wallpapers_for_test_++; 1009 loaded_wallpapers_for_test_++;
1010 SkBitmap bitmap; 1010 SkBitmap bitmap;
1011 bitmap.allocN32Pixels(1, 1); 1011 bitmap.allocN32Pixels(1, 1);
1012 bitmap.eraseColor(kDefaultWallpaperColor); 1012 bitmap.eraseColor(kDefaultWallpaperColor);
1013 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1013 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1014 default_wallpaper_image_.reset(new user_manager::UserImage(image)); 1014 default_wallpaper_image_.reset(new user_manager::UserImage(image));
1015 } 1015 }
1016 1016
1017 } // namespace wallpaper 1017 } // namespace wallpaper
OLDNEW
« no previous file with comments | « components/wallpaper/wallpaper_manager_base.h ('k') | components/wallpaper/wallpaper_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698