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

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: minor edits on coding style in response to comment 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
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_service.h ('k') | components/arc/common/wallpaper.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f1306afc06aae076e30dc1c8813820db2fd72844 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.
@@ -69,6 +70,14 @@ std::vector<uint8_t> EncodeImagePng(const gfx::ImageSkia image) {
return result;
}
+ash::WallpaperController* GetWallpaperController() {
+ ash::WmShell* wm_shell = ash::WmShell::Get();
+ if (wm_shell && wm_shell->wallpaper_controller()) {
Luis Héctor Chávez 2016/09/16 21:23:16 Forgot this one too: In general you want to do i
Yusuke Sato 2016/09/16 21:23:50 no {}
Muyuan 2016/09/16 21:38:48 Done.
+ return wm_shell->wallpaper_controller();
+ }
+ return nullptr;
+}
+
} // namespace
ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service)
@@ -81,6 +90,9 @@ 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 +106,14 @@ 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 +142,32 @@ 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) {
Yusuke Sato 2016/09/16 21:23:50 same
+ return;
+ }
+ instance->OnWallpaperChanged();
+}
+
+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) {
Yusuke Sato 2016/09/16 21:23:50 same
Muyuan 2016/09/16 21:38:49 Done.
+ VLOG(2) << "ARC wallpaper instance is not ready.";
+ }
+
+ return instance;
+}
+
} // namespace arc
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_service.h ('k') | components/arc/common/wallpaper.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698