Commit 063754cb authored by muyuanli's avatar muyuanli Committed by Commit bot

cheets: add wallpaper observer to arc_wallpaper_service.

ArcWallpaperService now observes wallpaper change
and notifies Android, which will use it to broadcast
ACTION_WALLPAPER_CHANGED.

Test=Change wallpaper with CrOS wallpaper picker
  and verify with Android app that listens wallpaper
  changed broadcast.

Bug=642465

Review-Url: https://codereview.chromium.org/2345153002
Cr-Commit-Position: refs/heads/master@{#419303}
parent ebafc22b
......@@ -4,8 +4,6 @@
#include "chrome/browser/chromeos/arc/arc_wallpaper_service.h"
#include <string>
#include <utility>
#include <vector>
#include "ash/common/wallpaper/wallpaper_controller.h"
......@@ -31,6 +29,7 @@ namespace arc {
namespace {
constexpr uint32_t kMinOnWallpaperChangedVersion = 1;
constexpr char kAndroidWallpaperFilename[] = "android.jpg";
// Sets a decoded bitmap as the wallpaper.
......@@ -69,6 +68,13 @@ std::vector<uint8_t> EncodeImagePng(const gfx::ImageSkia image) {
return result;
}
ash::WallpaperController* GetWallpaperController() {
ash::WmShell* wm_shell = ash::WmShell::Get();
if (!wm_shell)
return nullptr;
return wm_shell->wallpaper_controller();
}
} // namespace
ArcWallpaperService::ArcWallpaperService(ArcBridgeService* bridge_service)
......@@ -81,6 +87,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 +103,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 +139,29 @@ 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)
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
......@@ -7,10 +7,7 @@
#include <stdint.h>
#include <memory>
#include <set>
#include <vector>
#include "ash/common/wallpaper/wallpaper_controller_observer.h"
#include "base/macros.h"
#include "chrome/browser/image_decoder.h"
#include "components/arc/arc_service.h"
......@@ -25,6 +22,7 @@ namespace arc {
// Lives on the UI thread.
class ArcWallpaperService
: public ArcService,
public ash::WallpaperControllerObserver,
public ImageDecoder::ImageRequest,
public InstanceHolder<mojom::WallpaperInstance>::Observer,
public mojom::WallpaperHost {
......@@ -34,6 +32,7 @@ class ArcWallpaperService
// InstanceHolder<mojom::WallpaperInstance>::Observer overrides.
void OnInstanceReady() override;
void OnInstanceClosed() override;
// mojom::WallpaperHost overrides.
// TODO(muyuanli): change callback prototype when use_new_wrapper_types is
......@@ -45,7 +44,12 @@ class ArcWallpaperService
void OnImageDecoded(const SkBitmap& bitmap) override;
void OnDecodeImageFailed() override;
// WallpaperControllerObserver implementation.
void OnWallpaperDataChanged() override;
private:
mojom::WallpaperInstance* GetWallpaperInstance(uint32_t min_version);
mojo::Binding<mojom::WallpaperHost> binding_;
DISALLOW_COPY_AND_ASSIGN(ArcWallpaperService);
};
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Next MinVersion: 1
// Next MinVersion: 2
module arc.mojom;
......@@ -18,8 +18,11 @@ interface WallpaperHost {
};
// Connects with container side to publish wallpaper related intents.
// Next method ID:1
// Next method ID:2
interface WallpaperInstance {
// Establishes communication with the container side.
Init@0(WallpaperHost host_ptr);
// Notifies ArcWallpaperManagerService that wallpaper is changed.
[MinVersion=1] OnWallpaperChanged@1();
};
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment