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

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 <cstdlib>
hidehiko 2016/08/22 02:30:10 Clarification: for what?
7 #include <string> 8 #include <string>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
12 #include "ash/desktop_background/desktop_background_controller.h"
13 #include "ash/shell.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"
25
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 30 matching lines...) Expand all
60 66
61 ArcWallpaperHandler::ArcWallpaperHandler() = default; 67 ArcWallpaperHandler::ArcWallpaperHandler() = default;
62 68
63 ArcWallpaperHandler::~ArcWallpaperHandler() { 69 ArcWallpaperHandler::~ArcWallpaperHandler() {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 // Make sure the callback is never called after destruction. It is safe to 71 // Make sure the callback is never called after destruction. It is safe to
66 // call Cancel() even when there is no in-flight request. 72 // call Cancel() even when there is no in-flight request.
67 ImageDecoder::Cancel(this); 73 ImageDecoder::Cancel(this);
68 } 74 }
69 75
76 std::shared_ptr<ArcWallpaperHandler> ArcWallpaperHandler::Get() {
77 static std::shared_ptr<ArcWallpaperHandler> instance(new ArcWallpaperHandler);
xiyuan 2016/08/19 23:04:07 We might want to use CR_DEFINE_STATIC_LOCAL or a L
Luis Héctor Chávez 2016/08/19 23:22:56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
hidehiko 2016/08/22 02:30:10 Could you get rid of Singleton? Instead, ArcLaunch
Muyuan 2016/08/22 22:25:00 It sounds better :) thx.
78 return instance;
79 }
80
70 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) { 81 void ArcWallpaperHandler::SetWallpaper(std::vector<uint8_t> jpeg_data) {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 // If there is an in-flight request, cancel it. It is safe to call Cancel() 83 // If there is an in-flight request, cancel it. It is safe to call Cancel()
73 // even when there is no in-flight request. 84 // even when there is no in-flight request.
74 ImageDecoder::Cancel(this); 85 ImageDecoder::Cancel(this);
75 ImageDecoder::StartWithOptions(this, std::move(jpeg_data), 86 ImageDecoder::StartWithOptions(this, std::move(jpeg_data),
76 ImageDecoder::ROBUST_JPEG_CODEC, true); 87 ImageDecoder::ROBUST_JPEG_CODEC, true);
77 } 88 }
78 89
90 std::vector<uint8_t> ArcWallpaperHandler::GetWallpaper() const {
Luis Héctor Chávez 2016/08/19 23:22:56 DCHECK_CURRENTLY_ON(...); Note that we should not
Muyuan 2016/08/22 22:25:00 Done.
91 ash::DesktopBackgroundController* dbc =
92 ash::Shell::GetInstance()->desktop_background_controller();
93 gfx::Image wallpaper(dbc->GetWallpaper());
94 std::vector<uint8_t> result;
95 gfx::JPEG1xEncodedDataFromImage(wallpaper, 100, &result);
xiyuan 2016/08/19 23:04:07 What happens if there is no wallpaper and JPEG1xEn
Muyuan 2016/08/22 22:25:00 When there is no wallpaper, JPEG1xEncodedDataFromI
96 return std::move(result);
Luis Héctor Chávez 2016/08/19 23:22:56 Can you run trybots? The compiler will complain ab
Muyuan 2016/08/22 22:25:00 Acknowledged.
97 }
98
79 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) { 99 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
81 SetBitmapAsWallpaper(bitmap); 101 SetBitmapAsWallpaper(bitmap);
82 } 102 }
83 103
84 void ArcWallpaperHandler::OnDecodeImageFailed() { 104 void ArcWallpaperHandler::OnDecodeImageFailed() {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 LOG(ERROR) << "Failed to decode wallpaper image."; 106 LOG(ERROR) << "Failed to decode wallpaper image.";
87 } 107 }
88 108
89 } // namespace arc 109 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698