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

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, 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 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"
16 #include "base/task_runner_util.h"
13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
14 #include "components/signin/core/account_id/account_id.h" 18 #include "components/signin/core/account_id/account_id.h"
15 #include "components/user_manager/user_manager.h" 19 #include "components/user_manager/user_manager.h"
16 #include "components/wallpaper/wallpaper_files_id.h" 20 #include "components/wallpaper/wallpaper_files_id.h"
17 #include "components/wallpaper/wallpaper_layout.h" 21 #include "components/wallpaper/wallpaper_layout.h"
18 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/image/image_util.h"
20 26
21 using user_manager::UserManager; 27 using user_manager::UserManager;
22 28
23 namespace arc { 29 namespace arc {
24 30
25 namespace { 31 namespace {
26 32
27 constexpr char kAndroidWallpaperFilename[] = "android.jpg"; 33 constexpr char kAndroidWallpaperFilename[] = "android.jpg";
28 34
29 // Sets a decoded bitmap as the wallpaper. 35 // Sets a decoded bitmap as the wallpaper.
(...skipping 19 matching lines...) Expand all
49 account_id, wallpaper_files_id, kAndroidWallpaperFilename, 55 account_id, wallpaper_files_id, kAndroidWallpaperFilename,
50 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, 56 wallpaper::WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED,
51 image, update_wallpaper); 57 image, update_wallpaper);
52 58
53 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper 59 // 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 60 // 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 61 // make this happen seems to do the same things as wallpaper_api.cc and
56 // wallpaper_private_api.cc. 62 // wallpaper_private_api.cc.
57 } 63 }
58 64
65 std::vector<uint8_t> EncodeImageJPEG(const gfx::Image image) {
hidehiko 2016/08/24 16:22:18 const ref to avoid the copy?
66 std::vector<uint8_t> result;
67 gfx::JPEG1xEncodedDataFromImage(image, 100, &result);
68 return result;
69 }
70
59 } // namespace 71 } // namespace
60 72
61 ArcWallpaperHandler::ArcWallpaperHandler() = default; 73 ArcWallpaperHandler::ArcWallpaperHandler() = default;
62 74
63 ArcWallpaperHandler::~ArcWallpaperHandler() { 75 ArcWallpaperHandler::~ArcWallpaperHandler() {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 // Make sure the callback is never called after destruction. It is safe to 77 // Make sure the callback is never called after destruction. It is safe to
66 // call Cancel() even when there is no in-flight request. 78 // call Cancel() even when there is no in-flight request.
67 ImageDecoder::Cancel(this); 79 ImageDecoder::Cancel(this);
68 } 80 }
69 81
70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { 82 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 // If there is an in-flight request, cancel it. It is safe to call Cancel() 84 // If there is an in-flight request, cancel it. It is safe to call Cancel()
73 // even when there is no in-flight request. 85 // even when there is no in-flight request.
74 ImageDecoder::Cancel(this); 86 ImageDecoder::Cancel(this);
75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), 87 ImageDecoder::StartWithOptions(this, std::move(jpeg_data),
76 ImageDecoder::ROBUST_JPEG_CODEC, true); 88 ImageDecoder::ROBUST_JPEG_CODEC, true);
77 } 89 }
78 90
91 void ArcWallpaperHandler::GetWallpaper(
92 const base::Callback<void(std::vector<uint8_t> image)>& callback) const {
93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
94 ash::DesktopBackgroundController* dbc =
95 ash::Shell::GetInstance()->desktop_background_controller();
96 gfx::Image wallpaper(dbc->GetWallpaper());
97 base::PostTaskAndReplyWithResult(
98 content::BrowserThread::GetBlockingPool(), FROM_HERE,
99 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
100 }
101
79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { 102 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
81 SetBitmapAsWallpaper(bitmap); 104 SetBitmapAsWallpaper(bitmap);
82 } 105 }
83 106
84 void ArcWallpaperHandler::OnDecodeImageFailed() { 107 void ArcWallpaperHandler::OnDecodeImageFailed() {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 LOG(ERROR) << "Failed to decode wallpaper image."; 109 LOG(ERROR) << "Failed to decode wallpaper image.";
87 } 110 }
88 111
89 } // namespace arc 112 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698