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

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..0ab80feef58c339ad842ce43af9450b5790d4840 100644
--- a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
+++ b/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
@@ -8,15 +8,21 @@
#include <utility>
#include <vector>
+#include "ash/shell.h"
+#include "ash/wallpaper/wallpaper_controller.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "base/task_runner_util.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
#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 +62,12 @@ void SetBitmapAsWallpaper(const SkBitmap& bitmap) {
// wallpaper_private_api.cc.
}
+std::vector<uint8_t> EncodeImageJPEG(const gfx::Image image) {
+ std::vector<uint8_t> result;
+ gfx::JPEG1xEncodedDataFromImage(image, 100, &result);
+ return result;
+}
+
} // namespace
ArcWallpaperHandler::ArcWallpaperHandler() = default;
@@ -67,7 +79,7 @@ ArcWallpaperHandler::~ArcWallpaperHandler() {
ImageDecoder::Cancel(this);
}
-void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
+void ArcWallpaperHandler::SetWallpaper(const std::vector<uint8_t>& jpeg_data) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If there is an in-flight request, cancel it. It is safe to call Cancel()
// even when there is no in-flight request.
@@ -76,6 +88,18 @@ void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
ImageDecoder::ROBUST_JPEG_CODEC, true);
}
+void ArcWallpaperHandler::GetWallpaper(
+ const base::Callback<void(const std::vector<uint8_t>& image)>& callback)
+ const {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ash::WallpaperController* wc =
+ ash::Shell::GetInstance()->wallpaper_controller();
+ gfx::Image wallpaper(wc->GetWallpaper());
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&EncodeImageJPEG, wallpaper), callback);
+}
+
void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetBitmapAsWallpaper(bitmap);

Powered by Google App Engine
This is Rietveld 408576698