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

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(
65 const gfx::Image image,
66 const base::Callback<void(std::vector<uint8_t> result)>& callback) {
67 std::vector<uint8_t> result;
68 gfx::JPEG1xEncodedDataFromImage(image, 100, &result);
69 callback.Run(result);
Shuhei Takahashi 2016/08/23 09:34:21 We must invoke |callback| on UI thread. Please use
Muyuan 2016/08/23 19:45:49 Acknowledged.
70 }
71
59 } // namespace 72 } // namespace
60 73
61 ArcWallpaperHandler::ArcWallpaperHandler() = default; 74 ArcWallpaperHandler::ArcWallpaperHandler() = default;
62 75
63 ArcWallpaperHandler::~ArcWallpaperHandler() { 76 ArcWallpaperHandler::~ArcWallpaperHandler() {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 // Make sure the callback is never called after destruction. It is safe to 78 // Make sure the callback is never called after destruction. It is safe to
66 // call Cancel() even when there is no in-flight request. 79 // call Cancel() even when there is no in-flight request.
67 ImageDecoder::Cancel(this); 80 ImageDecoder::Cancel(this);
68 } 81 }
69 82
70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { 83 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 // If there is an in-flight request, cancel it. It is safe to call Cancel() 85 // If there is an in-flight request, cancel it. It is safe to call Cancel()
73 // even when there is no in-flight request. 86 // even when there is no in-flight request.
74 ImageDecoder::Cancel(this); 87 ImageDecoder::Cancel(this);
75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), 88 ImageDecoder::StartWithOptions(this, std::move(jpeg_data),
76 ImageDecoder::ROBUST_JPEG_CODEC, true); 89 ImageDecoder::ROBUST_JPEG_CODEC, true);
77 } 90 }
78 91
92 void ArcWallpaperHandler::GetWallpaper(
93 const base::Callback<void(std::vector<uint8_t> image)>& callback) const {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
95 ash::DesktopBackgroundController* dbc =
96 ash::Shell::GetInstance()->desktop_background_controller();
97 gfx::Image wallpaper(dbc->GetWallpaper());
Shuhei Takahashi 2016/08/23 09:34:21 I know gfx::JPEG1xEncodedDataFromImage() actually
Muyuan 2016/08/23 19:45:49 DesktopBackgroundController::GetWallpaper() will r
98 content::BrowserThread::PostTask(
99 content::BrowserThread::IO, FROM_HERE,
xiyuan 2016/08/22 22:49:41 IO thread is for network IO etc. Maybe do the job
Muyuan 2016/08/22 23:48:19 Acknowledged.
Shuhei Takahashi 2016/08/23 09:34:21 As xiyuan said, please avoid doing CPU-intensive t
Muyuan 2016/08/23 19:45:49 Acknowledged.
100 base::Bind(&EncodeImageJPEG, wallpaper, callback));
101 }
102
79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { 103 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
81 SetBitmapAsWallpaper(bitmap); 105 SetBitmapAsWallpaper(bitmap);
82 } 106 }
83 107
84 void ArcWallpaperHandler::OnDecodeImageFailed() { 108 void ArcWallpaperHandler::OnDecodeImageFailed() {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 LOG(ERROR) << "Failed to decode wallpaper image."; 110 LOG(ERROR) << "Failed to decode wallpaper image.";
87 } 111 }
88 112
89 } // namespace arc 113 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698