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

Unified Diff: chrome/browser/chromeos/arc/arc_wallpaper_service.cc

Issue 2345153002: cheets: add wallpaper observer to arc_wallpaper_service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete wallpaper observer in OnInstanceClosed() and ~ArcWallpaperService 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/arc_wallpaper_service.cc
diff --git a/chrome/browser/chromeos/arc/arc_wallpaper_service.cc b/chrome/browser/chromeos/arc/arc_wallpaper_service.cc
index f6a12cdb5a1eaba07ac09ec039de27a4aba85917..90cab970db1f5459a605aaf247c57b5b96287416 100644
--- a/chrome/browser/chromeos/arc/arc_wallpaper_service.cc
+++ b/chrome/browser/chromeos/arc/arc_wallpaper_service.cc
@@ -31,6 +31,7 @@ namespace arc {
namespace {
+constexpr uint32_t kMinOnWallpaperChangedVersion = 1;
constexpr char kAndroidWallpaperFilename[] = "android.jpg";
// Sets a decoded bitmap as the wallpaper.
@@ -81,6 +82,10 @@ ArcWallpaperService::~ArcWallpaperService() {
// Make sure the callback is never called after destruction. It is safe to
// call Cancel() even when there is no in-flight request.
ImageDecoder::Cancel(this);
+ ash::WallpaperController* wc = GetWallpaperController();
+ if (wc) {
+ wc->RemoveObserver(this);
+ }
arc_bridge_service()->wallpaper()->RemoveObserver(this);
}
@@ -94,6 +99,15 @@ void ArcWallpaperService::OnInstanceReady() {
return;
}
wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind());
+ ash::WmShell::Get()->wallpaper_controller()->AddObserver(this);
+}
+
+void ArcWallpaperService::OnInstanceClosed() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ash::WallpaperController* wc = GetWallpaperController();
+ if (wc) {
+ wc->RemoveObserver(this);
+ }
}
void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) {
@@ -122,4 +136,40 @@ void ArcWallpaperService::OnDecodeImageFailed() {
LOG(ERROR) << "Failed to decode wallpaper image.";
}
+void ArcWallpaperService::OnWallpaperDataChanged() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::WallpaperInstance* instance =
+ GetWallpaperInstance(kMinOnWallpaperChangedVersion);
+ if (!instance) {
Luis Héctor Chávez 2016/09/16 21:05:56 nit: you can elide the braces. Same in all the oth
Muyuan 2016/09/16 21:21:09 Done.
+ return;
+ }
+ instance->OnWallpaperChanged();
+}
+
+ash::WallpaperController* ArcWallpaperService::GetWallpaperController() {
Luis Héctor Chávez 2016/09/16 21:05:56 This doesn't need to be a method. A standalone fun
Muyuan 2016/09/16 21:21:09 Done.
+ ash::WmShell* wm_shell = ash::WmShell::Get();
+ if (wm_shell && wm_shell->wallpaper_controller()) {
+ return wm_shell->wallpaper_controller();
+ }
+ return nullptr;
+}
+
+mojom::WallpaperInstance* ArcWallpaperService::GetWallpaperInstance(
+ uint32_t min_version) {
+ uint32_t version = arc_bridge_service()->wallpaper()->version();
+ if (version < min_version) {
+ VLOG(1) << "ARC wallpaper instance is too old. required: " << min_version
+ << ", actual: " << version;
+ return nullptr;
+ }
+
+ mojom::WallpaperInstance* instance =
+ arc_bridge_service()->wallpaper()->instance();
+ if (!instance) {
+ VLOG(2) << "ARC wallpaper instance is not ready.";
+ }
+
+ return instance;
+}
+
} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698