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

Unified Diff: chrome/browser/chromeos/arc/arc_wallpaper_handler.cc

Issue 2264743002: cheets: implement cros side of WallpaperManagerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cheets: implement cros side of WallpaperManagerService. Created 4 years, 4 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/arc/arc_wallpaper_handler.cc
diff --git a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc b/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
index 238a9837e121ffe019e3e1076c9429b7ff177420..9039d506f1f9d1fe7eeafdb98a2d17154093b7a0 100644
--- a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
+++ b/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
@@ -8,6 +8,9 @@
#include <utility>
#include <vector>
+#include "ash/desktop_background/desktop_background_controller.h"
+#include "ash/shell.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
@@ -16,7 +19,9 @@
#include "components/wallpaper/wallpaper_files_id.h"
#include "components/wallpaper/wallpaper_layout.h"
#include "content/public/browser/browser_thread.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_util.h"
using user_manager::UserManager;
@@ -56,6 +61,17 @@ void SetBitmapAsWallpaper(const SkBitmap& bitmap) {
// wallpaper_private_api.cc.
}
+void EncodeImageJPEG(const gfx::Image image,
+ std::shared_ptr<std::vector<uint8_t>> result) {
+ gfx::JPEG1xEncodedDataFromImage(image, 100, result.get());
+}
+
+void OnImageEncoded(
+ std::shared_ptr<std::vector<uint8_t>> result,
+ const base::Callback<void(std::vector<uint8_t> image)>& callback) {
+ callback.Run(*result.get());
+}
+
} // namespace
ArcWallpaperHandler::ArcWallpaperHandler() = default;
@@ -76,6 +92,18 @@ void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
ImageDecoder::ROBUST_JPEG_CODEC, true);
}
+void ArcWallpaperHandler::GetWallpaper(
+ const base::Callback<void(std::vector<uint8_t> image)>& callback) const {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ash::DesktopBackgroundController* dbc =
+ ash::Shell::GetInstance()->desktop_background_controller();
+ gfx::Image wallpaper(dbc->GetWallpaper());
+ std::shared_ptr<std::vector<uint8_t>> buffer(new std::vector<uint8_t>());
xiyuan 2016/08/23 20:43:47 I would avoid shared_ptr. Either use PostTaskAndRe
Muyuan 2016/08/23 21:20:38 Thx
+ content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
+ FROM_HERE, base::Bind(&EncodeImageJPEG, std::move(wallpaper), buffer),
xiyuan 2016/08/23 20:43:47 nit: std::move is not necessary, gfx::Image assign
Muyuan 2016/08/23 21:20:38 Done.
+ base::Bind(&OnImageEncoded, buffer, callback));
+}
+
void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetBitmapAsWallpaper(bitmap);

Powered by Google App Engine
This is Rietveld 408576698