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

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

Issue 2264743002: cheets: implement cros side of WallpaperManagerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add DCHECK with static instance and fixed other minor issues. Created 4 years, 3 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_service.cc
diff --git a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc b/chrome/browser/chromeos/arc/arc_wallpaper_service.cc
similarity index 54%
rename from chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
rename to chrome/browser/chromeos/arc/arc_wallpaper_service.cc
index 238a9837e121ffe019e3e1076c9429b7ff177420..2aa33ae02233a0161aab0da26fa15a2328b03c8d 100644
--- a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
+++ b/chrome/browser/chromeos/arc/arc_wallpaper_service.cc
@@ -2,21 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/arc/arc_wallpaper_handler.h"
+#include "chrome/browser/chromeos/arc/arc_wallpaper_service.h"
#include <string>
#include <utility>
#include <vector>
+#include "ash/shell.h"
+#include "ash/wallpaper/wallpaper_controller.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/arc/arc_bridge_service.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/codec/png_codec.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,18 +63,67 @@ void SetBitmapAsWallpaper(const SkBitmap& bitmap) {
// wallpaper_private_api.cc.
}
+std::vector<uint8_t> EncodeImagePNG(const gfx::ImageSkia image) {
hidehiko 2016/09/07 01:16:25 nit: EncodeImagePng. cf) https://google.github.io
Muyuan 2016/09/07 02:50:47 Acknowledged.
+ std::vector<uint8_t> result;
+ gfx::PNGCodec::FastEncodeBGRASkBitmap(*image.bitmap(), true, &result);
+ return result;
+}
+
} // namespace
-ArcWallpaperHandler::ArcWallpaperHandler() = default;
+// TODO(muyuanli): This will be removed once SetWallpaperDelegate class is
+// removed.
+SetWallpaperDelegate* SetWallpaperDelegate::instance_ = nullptr;
hidehiko 2016/09/07 01:16:25 Could you define this as a part of components/arc/
Muyuan 2016/09/07 02:50:47 OK. Made it part of ArcIntentHelper temporarily.
+
+ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), binding_(this) {
+ arc_bridge_service()->wallpaper()->AddObserver(this);
+ DCHECK(!instance_);
+ instance_ = this;
+}
-ArcWallpaperHandler::~ArcWallpaperHandler() {
+ArcWallpaperService::~ArcWallpaperService() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Make sure the callback is never called after destruction. It is safe to
// call Cancel() even when there is no in-flight request.
ImageDecoder::Cancel(this);
+ arc_bridge_service()->wallpaper()->RemoveObserver(this);
+ DCHECK(instance_ == this);
+ instance_ = nullptr;
+}
+
+void ArcWallpaperService::OnInstanceReady() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::WallpaperInstance* wallpaper_instance =
+ arc_bridge_service()->wallpaper()->instance();
+ if (!wallpaper_instance) {
+ LOG(ERROR) << "OnWallpaperInstanceReady called, "
hidehiko 2016/09/07 01:16:25 Could you use LOG(DFATAL) instead? This is unexpec
Muyuan 2016/09/07 02:50:47 Acknowledged.
+ << "but no wallpaper instance found";
+ return;
+ }
+ wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind());
+}
+
+void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ImageDecoder::Cancel(this);
+ ImageDecoder::StartWithOptions(this, png_data.PassStorage(),
+ ImageDecoder::ROBUST_PNG_CODEC, true);
+}
+
+void ArcWallpaperService::GetWallpaper(
+ const base::Callback<void(mojo::Array<uint8_t>)>& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ash::WallpaperController* wc =
+ ash::Shell::GetInstance()->wallpaper_controller();
+ gfx::ImageSkia wallpaper = wc->GetWallpaper();
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&EncodeImagePNG, wallpaper), callback);
}
-void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
+void ArcWallpaperService::SetWallpaperJPEG(
hidehiko 2016/09/07 01:16:25 Ditto. "SetWallpaperJpeg"
Muyuan 2016/09/07 02:50:47 Acknowledged.
+ 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,12 +132,12 @@ void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
ImageDecoder::ROBUST_JPEG_CODEC, true);
}
-void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
+void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetBitmapAsWallpaper(bitmap);
}
-void ArcWallpaperHandler::OnDecodeImageFailed() {
+void ArcWallpaperService::OnDecodeImageFailed() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
LOG(ERROR) << "Failed to decode wallpaper image.";
}

Powered by Google App Engine
This is Rietveld 408576698