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

Side by Side Diff: chrome/browser/chromeos/arc/arc_wallpaper_service.cc

Issue 2332063004: cheets: remove setWallpaper from ArcIntentHelper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_service.h" 5 #include "chrome/browser/chromeos/arc/arc_wallpaper_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::vector<uint8_t> result; 67 std::vector<uint8_t> result;
68 gfx::PNGCodec::FastEncodeBGRASkBitmap(*image.bitmap(), true, &result); 68 gfx::PNGCodec::FastEncodeBGRASkBitmap(*image.bitmap(), true, &result);
69 return result; 69 return result;
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service) 74 ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service)
75 : ArcService(bridge_service), binding_(this) { 75 : ArcService(bridge_service), binding_(this) {
76 arc_bridge_service()->wallpaper()->AddObserver(this); 76 arc_bridge_service()->wallpaper()->AddObserver(this);
77 DCHECK(!ArcWallpaperService::instance());
78 ArcWallpaperService::set_instance(this);
79 } 77 }
80 78
81 ArcWallpaperService::~ArcWallpaperService() { 79 ArcWallpaperService::~ArcWallpaperService() {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 // 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
84 // call Cancel() even when there is no in-flight request. 82 // call Cancel() even when there is no in-flight request.
85 ImageDecoder::Cancel(this); 83 ImageDecoder::Cancel(this);
86 arc_bridge_service()->wallpaper()->RemoveObserver(this); 84 arc_bridge_service()->wallpaper()->RemoveObserver(this);
87 DCHECK(ArcWallpaperService::instance() == this);
88 ArcWallpaperService::set_instance(nullptr);
89 } 85 }
90 86
91 void ArcWallpaperService::OnInstanceReady() { 87 void ArcWallpaperService::OnInstanceReady() {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
93 mojom::WallpaperInstance* wallpaper_instance = 89 mojom::WallpaperInstance* wallpaper_instance =
94 arc_bridge_service()->wallpaper()->instance(); 90 arc_bridge_service()->wallpaper()->instance();
95 if (!wallpaper_instance) { 91 if (!wallpaper_instance) {
96 LOG(DFATAL) << "OnWallpaperInstanceReady called, " 92 LOG(DFATAL) << "OnWallpaperInstanceReady called, "
97 << "but no wallpaper instance found"; 93 << "but no wallpaper instance found";
98 return; 94 return;
(...skipping 10 matching lines...) Expand all
109 105
110 void ArcWallpaperService::GetWallpaper(const GetWallpaperCallback& callback) { 106 void ArcWallpaperService::GetWallpaper(const GetWallpaperCallback& callback) {
111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
112 ash::WallpaperController* wc = ash::WmShell::Get()->wallpaper_controller(); 108 ash::WallpaperController* wc = ash::WmShell::Get()->wallpaper_controller();
113 gfx::ImageSkia wallpaper = wc->GetWallpaper(); 109 gfx::ImageSkia wallpaper = wc->GetWallpaper();
114 base::PostTaskAndReplyWithResult( 110 base::PostTaskAndReplyWithResult(
115 content::BrowserThread::GetBlockingPool(), FROM_HERE, 111 content::BrowserThread::GetBlockingPool(), FROM_HERE,
116 base::Bind(&EncodeImagePng, wallpaper), callback); 112 base::Bind(&EncodeImagePng, wallpaper), callback);
117 } 113 }
118 114
119 void ArcWallpaperService::SetWallpaperJpeg(
120 const std::vector<uint8_t>& jpeg_data) {
121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
122 // If there is an in-flight request, cancel it. It is safe to call Cancel()
123 // even when there is no in-flight request.
124 ImageDecoder::Cancel(this);
125 ImageDecoder::StartWithOptions(this, std::move(jpeg_data),
126 ImageDecoder::ROBUST_JPEG_CODEC, true);
127 }
128
129 void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) { 115 void ArcWallpaperService::OnImageDecoded(const SkBitmap& bitmap) {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
131 SetBitmapAsWallpaper(bitmap); 117 SetBitmapAsWallpaper(bitmap);
132 } 118 }
133 119
134 void ArcWallpaperService::OnDecodeImageFailed() { 120 void ArcWallpaperService::OnDecodeImageFailed() {
135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
136 LOG(ERROR) << "Failed to decode wallpaper image."; 122 LOG(ERROR) << "Failed to decode wallpaper image.";
137 } 123 }
138 124
139 } // namespace arc 125 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698