Chromium Code Reviews| 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..5cb7a9dfd26c3138d964f40471edf3f51c4c7fce 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::WmShell* wm_shell = ash::WmShell::Get(); |
| + if (wm_shell && wm_shell->wallpaper_controller()) { |
| + wm_shell->wallpaper_controller()->RemoveObserver(this); |
| + } |
| arc_bridge_service()->wallpaper()->RemoveObserver(this); |
| } |
| @@ -94,6 +99,7 @@ void ArcWallpaperService::OnInstanceReady() { |
| return; |
| } |
| wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| + ash::WmShell::Get()->wallpaper_controller()->AddObserver(this); |
| } |
| void ArcWallpaperService::SetWallpaper(mojo::Array<uint8_t> png_data) { |
| @@ -122,4 +128,33 @@ 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) { |
| + ash::WmShell::Get()->wallpaper_controller()->RemoveObserver(this); |
|
Luis Héctor Chávez
2016/09/16 19:58:11
It's better to do this in the OnInstanceClosed() r
Muyuan
2016/09/16 20:19:08
I see. So here is a question:
Is there a guarantee
Luis Héctor Chávez
2016/09/16 20:27:37
There are cases where Android outlives Chrome, but
Muyuan
2016/09/16 20:48:56
Done.
|
| + 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) { |
| + VLOG(2) << "ARC wallpaper instance is not ready."; |
| + } |
| + |
| + return instance; |
| +} |
| + |
| } // namespace arc |