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

Unified Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 12334030: New custom wallpaper picker UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add bug reference Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/wallpaper_private_api.cc
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index 420d44793505c7ebe2e32d08c9324586d7706dfb..86671e94f8e5cff749e87522245ed1c8af4baa96 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -524,6 +524,11 @@ bool WallpaperPrivateSetCustomWallpaperFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(!layout_string.empty());
layout_ = GetLayoutEnum(layout_string);
+ EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(2, &generate_thumbnail_));
+
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &file_name_));
+ EXTENSION_FUNCTION_VALIDATE(!file_name_.empty());
+
// Gets email address while at UI thread.
email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
@@ -540,9 +545,8 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
chromeos::UserImage::RawImage raw_image(image_data_.begin(),
image_data_.end());
chromeos::UserImage image(wallpaper, raw_image);
- std::string file = base::Int64ToString(base::Time::Now().ToInternalValue());
base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
- chromeos::kThumbnailWallpaperSubDir, email_, file);
+ chromeos::kThumbnailWallpaperSubDir, email_, file_name_);
sequence_token_ = BrowserThread::GetBlockingPool()->
GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
@@ -551,20 +555,25 @@ void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
base::SequencedWorkerPool::BLOCK_SHUTDOWN);
- wallpaper.EnsureRepsForSupportedScaleFactors();
- scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
- // Generates thumbnail before call api function callback. We can then request
- // thumbnail in the javascript callback.
- task_runner->PostTask(FROM_HERE,
- base::Bind(&WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail,
- this, thumbnail_path, base::Passed(&deep_copy)));
-
// In the new wallpaper picker UI, we do not depend on WallpaperDelegate
// to refresh thumbnail. Uses a null delegate here.
- wallpaper_manager->SetCustomWallpaper(email_, file, layout_,
+ wallpaper_manager->SetCustomWallpaper(email_, file_name_, layout_,
chromeos::User::CUSTOMIZED,
image);
wallpaper_decoder_ = NULL;
+
+ if (generate_thumbnail_) {
+ wallpaper.EnsureRepsForSupportedScaleFactors();
+ scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy());
+ // Generates thumbnail before call api function callback. We can then
+ // request thumbnail in the javascript callback.
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(
+ &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail,
+ this, thumbnail_path, base::Passed(&deep_copy)));
+ } else {
+ SendResponse(true);
+ }
}
void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
@@ -575,23 +584,25 @@ void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
if (!file_util::PathExists(thumbnail_path.DirName()))
file_util::CreateDirectory(thumbnail_path.DirName());
- chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
+ scoped_refptr<base::RefCountedBytes> data;
+ chromeos::WallpaperManager::Get()->ResizeWallpaper(
wallpaper,
- thumbnail_path,
ash::WALLPAPER_LAYOUT_STRETCH,
ash::kWallpaperThumbnailWidth,
- ash::kWallpaperThumbnailHeight);
- std::string file_name = thumbnail_path.BaseName().value();
+ ash::kWallpaperThumbnailHeight,
+ &data);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
&WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated,
- this, file_name));
+ this, data));
}
void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated(
- const std::string& file_name) {
- SetResult(new base::StringValue(file_name));
+ base::RefCountedBytes* data) {
+ BinaryValue* result = BinaryValue::CreateWithCopiedBuffer(
+ reinterpret_cast<const char*>(data->front()), data->size());
+ SetResult(result);
SendResponse(true);
}
« no previous file with comments | « chrome/browser/chromeos/extensions/wallpaper_private_api.h ('k') | chrome/browser/chromeos/login/wallpaper_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698