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

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

Issue 1566713005: Make the third party wallpaper syncable through different devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a TODO Created 4 years, 11 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_api.cc
diff --git a/chrome/browser/chromeos/extensions/wallpaper_api.cc b/chrome/browser/chromeos/extensions/wallpaper_api.cc
index 64be4aae1c43ff7c1c22cac8da48ddab10af8926..399b846a558a42e0ceef85e51f9fe990e66115c2 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_api.cc
@@ -153,42 +153,31 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
user_manager::User::CUSTOMIZED, image, update_wallpaper);
unsafe_wallpaper_decoder_ = NULL;
- if (params_->details.thumbnail) {
- image.EnsureRepsForSupportedScales();
- scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
- // Generates thumbnail before call api function callback. We can then
- // request thumbnail in the javascript callback.
- task_runner->PostTask(
- FROM_HERE,
- base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this,
- thumbnail_path, base::Passed(std::move(deep_copy))));
+ // Save current extenion name. It will be displayed in the component
+ // wallpaper picker app. If current extension is the component wallpaper
+ // picker, set an empty string.
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ if (extension()->id() == extension_misc::kWallpaperManagerId) {
+ profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
+ std::string());
} else {
- // Save current extenion name. It will be displayed in the component
- // wallpaper picker app. If current extension is the component wallpaper
- // picker, set an empty string.
- Profile* profile = Profile::FromBrowserContext(browser_context());
- if (extension()->id() == extension_misc::kWallpaperManagerId) {
- profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
- std::string());
- } else {
- profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
- extension()->name());
- }
- SendResponse(true);
+ profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
+ extension()->name());
}
- // Inform the native Wallpaper Picker Application that the current wallpaper
- // has been modified by a third party application.
- Profile* profile = Profile::FromBrowserContext(browser_context());
- extensions::EventRouter* event_router = extensions::EventRouter::Get(profile);
- scoped_ptr<base::ListValue> event_args(new base::ListValue());
- scoped_ptr<extensions::Event> event(new extensions::Event(
- extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY,
- extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty::
- kEventName,
- std::move(event_args)));
- event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId,
- std::move(event));
+ if (!params_->details.thumbnail)
+ SendResponse(true);
+
+ // We need to generate thumbnail image anyway to make the current third party
+ // wallpaper syncable through different devices.
+ image.EnsureRepsForSupportedScales();
+ scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy());
+ // Generates thumbnail before call api function callback. We can then
+ // request thumbnail in the javascript callback.
+ task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this,
+ thumbnail_path, base::Passed(std::move(deep_copy))));
}
void WallpaperSetWallpaperFunction::GenerateThumbnail(
@@ -198,24 +187,52 @@ void WallpaperSetWallpaperFunction::GenerateThumbnail(
if (!base::PathExists(thumbnail_path.DirName()))
base::CreateDirectory(thumbnail_path.DirName());
- scoped_refptr<base::RefCountedBytes> data;
+ scoped_refptr<base::RefCountedBytes> original_data;
+ scoped_refptr<base::RefCountedBytes> thumbnail_data;
+ chromeos::WallpaperManager::Get()->ResizeImage(
+ *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(),
+ image->height(), &original_data, NULL);
chromeos::WallpaperManager::Get()->ResizeImage(
*image, wallpaper::WALLPAPER_LAYOUT_STRETCH,
wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight,
- &data, NULL);
+ &thumbnail_data, NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(
- &WallpaperSetWallpaperFunction::ThumbnailGenerated,
- this, data));
+ base::Bind(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this,
+ original_data, thumbnail_data));
}
void WallpaperSetWallpaperFunction::ThumbnailGenerated(
- base::RefCountedBytes* data) {
- BinaryValue* result = BinaryValue::CreateWithCopiedBuffer(
- reinterpret_cast<const char*>(data->front()), data->size());
- SetResult(result);
- SendResponse(true);
+ base::RefCountedBytes* original_data,
+ base::RefCountedBytes* thumbnail_data) {
+ BinaryValue* original_result = BinaryValue::CreateWithCopiedBuffer(
+ reinterpret_cast<const char*>(original_data->front()),
+ original_data->size());
+ BinaryValue* thumbnail_result = BinaryValue::CreateWithCopiedBuffer(
+ reinterpret_cast<const char*>(thumbnail_data->front()),
+ thumbnail_data->size());
+
+ if (params_->details.thumbnail) {
+ SetResult(thumbnail_result);
+ SendResponse(true);
+ }
+
+ // Inform the native Wallpaper Picker Application that the current wallpaper
+ // has been modified by a third party application.
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ extensions::EventRouter* event_router = extensions::EventRouter::Get(profile);
+ scoped_ptr<base::ListValue> event_args(new base::ListValue());
+ event_args->Append(original_result);
+ event_args->Append(thumbnail_result);
+ event_args->Append(new base::StringValue(
+ extensions::api::wallpaper::ToString(params_->details.layout)));
+ scoped_ptr<extensions::Event> event(new extensions::Event(
+ extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY,
+ extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty::
+ kEventName,
+ std::move(event_args)));
+ event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId,
+ std::move(event));
}
void WallpaperSetWallpaperFunction::OnWallpaperFetched(

Powered by Google App Engine
This is Rietveld 408576698