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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/arc/arc_wallpaper_handler.h" 5 #include "chrome/browser/chromeos/arc/arc_wallpaper_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/desktop_background/desktop_background_controller.h"
12 #include "ash/shell.h"
13 #include "base/bind.h"
11 #include "base/logging.h" 14 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 16 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
14 #include "components/signin/core/account_id/account_id.h" 17 #include "components/signin/core/account_id/account_id.h"
15 #include "components/user_manager/user_manager.h" 18 #include "components/user_manager/user_manager.h"
16 #include "components/wallpaper/wallpaper_files_id.h" 19 #include "components/wallpaper/wallpaper_files_id.h"
17 #include "components/wallpaper/wallpaper_layout.h" 20 #include "components/wallpaper/wallpaper_layout.h"
18 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/image/image_util.h"
20 25
21 using user_manager::UserManager; 26 using user_manager::UserManager;
22 27
23 namespace arc { 28 namespace arc {
24 29
25 namespace { 30 namespace {
26 31
27 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; 32 constexpr char kAndroidWallpaperFilename[] = "android.jpg";
28 33
29 // Sets a decoded bitmap as the wallpaper. 34 // Sets a decoded bitmap as the wallpaper.
(...skipping 19 matching lines...) Expand all
49 account_id, wallpaper_files_id, kAndroidWallpaperFilename, 54 account_id, wallpaper_files_id, kAndroidWallpaperFilename,
50 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, 55 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED,
51 image, update_wallpaper); 56 image, update_wallpaper);
52 57
53 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper 58 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper
54 // picker. Currently the new wallpaper does not appear there. The best way to 59 // picker. Currently the new wallpaper does not appear there. The best way to
55 // make this happen seems to do the same things as wallpaper_api.cc and 60 // make this happen seems to do the same things as wallpaper_api.cc and
56 // wallpaper_private_api.cc. 61 // wallpaper_private_api.cc.
57 } 62 }
58 63
64 void EncodeImageJPEG(const gfx::Image image,
65 std::shared_ptr<std::vector<uint8_t>> result) {
66 gfx::JPEG1xEncodedDataFromImage(image, 100, result.get());
67 }
68
69 void OnImageEncoded(
70 std::shared_ptr<std::vector<uint8_t>> result,
71 const base::Callback<void(std::vector<uint8_t> image)>& callback) {
72 callback.Run(*result.get());
73 }
74
59 } // namespace 75 } // namespace
60 76
61 ArcWallpaperHandler::ArcWallpaperHandler() = default; 77 ArcWallpaperHandler::ArcWallpaperHandler() = default;
62 78
63 ArcWallpaperHandler::~ArcWallpaperHandler() { 79 ArcWallpaperHandler::~ArcWallpaperHandler() {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 // Make sure the callback is never called after destruction. It is safe to 81 // Make sure the callback is never called after destruction. It is safe to
66 // call Cancel() even when there is no in-flight request. 82 // call Cancel() even when there is no in-flight request.
67 ImageDecoder::Cancel(this); 83 ImageDecoder::Cancel(this);
68 } 84 }
69 85
70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { 86 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 // If there is an in-flight request, cancel it. It is safe to call Cancel() 88 // If there is an in-flight request, cancel it. It is safe to call Cancel()
73 // even when there is no in-flight request. 89 // even when there is no in-flight request.
74 ImageDecoder::Cancel(this); 90 ImageDecoder::Cancel(this);
75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), 91 ImageDecoder::StartWithOptions(this, std::move(jpeg_data),
76 ImageDecoder::ROBUST_JPEG_CODEC, true); 92 ImageDecoder::ROBUST_JPEG_CODEC, true);
77 } 93 }
78 94
95 void ArcWallpaperHandler::GetWallpaper(
96 const base::Callback<void(std::vector<uint8_t> image)>& callback) const {
97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
98 ash::DesktopBackgroundController* dbc =
99 ash::Shell::GetInstance()->desktop_background_controller();
100 gfx::Image wallpaper(dbc->GetWallpaper());
101 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
102 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
103 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.
104 base::Bind(&OnImageEncoded, buffer, callback));
105 }
106
79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { 107 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
81 SetBitmapAsWallpaper(bitmap); 109 SetBitmapAsWallpaper(bitmap);
82 } 110 }
83 111
84 void ArcWallpaperHandler::OnDecodeImageFailed() { 112 void ArcWallpaperHandler::OnDecodeImageFailed() {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 113 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 LOG(ERROR) << "Failed to decode wallpaper image."; 114 LOG(ERROR) << "Failed to decode wallpaper image.";
87 } 115 }
88 116
89 } // namespace arc 117 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698