Index: chrome/browser/chromeos/login/wallpaper_manager.cc |
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc |
index aa549bbe501ec2c407658c3736e8e4d984893554..0ada22c18f80b9fde129913b38e28a0e60bb068f 100644 |
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc |
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc |
@@ -328,8 +328,7 @@ void WallpaperManager::RemoveUserWallpaperInfo(const std::string& email) { |
DeleteUserWallpapers(email); |
} |
-void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
- const base::FilePath& path, |
+std::string WallpaperManager::ResizeWallpaper(const UserImage& wallpaper, |
ash::WallpaperLayout layout, |
int preferred_width, |
int preferred_height) { |
@@ -343,7 +342,7 @@ void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { |
// Do not resize custom wallpaper if it is smaller than preferred size. |
if (!(width > preferred_width && height > preferred_height)) |
- return; |
+ return std::string(); |
double horizontal_ratio = static_cast<double>(preferred_width) / width; |
double vertical_ratio = static_cast<double>(preferred_height) / height; |
@@ -360,10 +359,8 @@ void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
resized_width = preferred_width; |
resized_height = preferred_height; |
} else { |
- // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
- if (file_util::PathExists(path)) |
- file_util::Delete(path, false); |
- return; |
+ resized_width = width; |
+ resized_height = height; |
} |
gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( |
@@ -381,9 +378,28 @@ void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
image.height(), |
image.width() * image.bytesPerPixel(), |
kDefaultEncodingQuality, &data->data()); |
- SaveWallpaperInternal(path, |
- reinterpret_cast<const char*>(data->front()), |
- data->size()); |
+ return std::string(reinterpret_cast<const char*>(data->front()), |
Nikita (slow)
2013/03/06 16:51:17
Is this the only way to return resized Wallpaper?
flackr
2013/03/06 18:22:24
But we don't know in advance the size of the resiz
bshe
2013/03/07 05:34:35
I changed the signature according to nikita's sugg
|
+ data->size()); |
+} |
+ |
+void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
+ const base::FilePath& path, |
+ ash::WallpaperLayout layout, |
+ int preferred_width, |
+ int preferred_height) { |
+ if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
+ // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
+ if (file_util::PathExists(path)) |
+ file_util::Delete(path, false); |
+ return; |
+ } |
+ std::string resized_wallpaper_string = |
+ ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height); |
+ if (!resized_wallpaper_string.empty()) { |
+ SaveWallpaperInternal(path, |
+ resized_wallpaper_string.c_str(), |
+ resized_wallpaper_string.size()); |
+ } |
} |
void WallpaperManager::RestartTimer() { |
@@ -561,6 +577,11 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) { |
desktop_background_controller()->GetAppropriateResolution(); |
const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? |
kSmallWallpaperSubDir : kLargeWallpaperSubDir; |
+ // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. |
+ // Original wallpaper should be used in this case. |
+ // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
+ if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) |
+ sub_dir = kOriginalWallpaperSubDir; |
base::FilePath wallpaper_path = GetCustomWallpaperPath(sub_dir, email, |
info.file); |
if (current_wallpaper_path_ == wallpaper_path) |
@@ -659,6 +680,19 @@ void WallpaperManager::ClearObsoleteWallpaperPrefs() { |
wallpapers_pref->Clear(); |
} |
+void WallpaperManager::DeleteAllExcept(const base::FilePath& path) { |
+ base::FilePath dir = path.DirName(); |
+ if (file_util::DirectoryExists(dir)) { |
+ file_util::FileEnumerator files(dir, false, |
+ file_util::FileEnumerator::FILES); |
+ for (base::FilePath current = files.Next(); !current.empty(); |
+ current = files.Next()) { |
+ if (current != path) |
+ file_util::Delete(current, false); |
+ } |
+ } |
+} |
+ |
void WallpaperManager::DeleteWallpaperInList( |
const std::vector<base::FilePath>& file_list) { |
for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); |
@@ -1030,13 +1064,16 @@ void WallpaperManager::SaveCustomWallpaper(const std::string& email, |
SaveWallpaperInternal(original_path, |
reinterpret_cast<char*>(&*image_data.begin()), |
image_data.size()); |
+ DeleteAllExcept(original_path); |
ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, |
ash::kSmallWallpaperMaxWidth, |
ash::kSmallWallpaperMaxHeight); |
+ DeleteAllExcept(small_wallpaper_path); |
ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, |
ash::kLargeWallpaperMaxWidth, |
ash::kLargeWallpaperMaxHeight); |
+ DeleteAllExcept(large_wallpaper_path); |
} |
void WallpaperManager::RecordUma(User::WallpaperType type, int index) { |