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..b9e7879e79be30fe48be6e7e67df01b93a0913e1 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/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 "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) { |
hidehiko
2016/08/24 16:22:18
const ref to avoid the copy?
|
+ std::vector<uint8_t> result; |
+ gfx::JPEG1xEncodedDataFromImage(image, 100, &result); |
+ return result; |
+} |
+ |
} // namespace |
ArcWallpaperHandler::ArcWallpaperHandler() = default; |
@@ -76,6 +88,17 @@ 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()); |
+ base::PostTaskAndReplyWithResult( |
+ content::BrowserThread::GetBlockingPool(), FROM_HERE, |
+ base::Bind(&EncodeImageJPEG, wallpaper), callback); |
hidehiko
2016/08/24 16:22:18
std::move is needed to avoid the copy?
xiyuan
2016/08/24 17:16:29
gfx::Image is cheap to copy since it only incremen
|
+} |
+ |
void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
SetBitmapAsWallpaper(bitmap); |