Chromium Code Reviews| Index: components/arc/wallpaper/arc_wallpaper_bridge.cc |
| diff --git a/components/arc/wallpaper/arc_wallpaper_bridge.cc b/components/arc/wallpaper/arc_wallpaper_bridge.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2490d45070726462438021912a820183bfdf494a |
| --- /dev/null |
| +++ b/components/arc/wallpaper/arc_wallpaper_bridge.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/arc/wallpaper/arc_wallpaper_bridge.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "components/arc/arc_bridge_service.h" |
| +#include "components/arc/set_wallpaper_delegate.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +void HandleWallpaperResult( |
| + const base::Callback<void(mojo::Array<uint8_t>)>& callback, |
| + const std::vector<uint8_t>& image) { |
| + callback.Run(std::move(image)); |
| +} |
| + |
| +} // namespace |
| + |
| +ArcWallpaperBridge::ArcWallpaperBridge(ArcBridgeService* bridge_service, |
| + SetWallpaperDelegate* delegate) |
| + : ArcService(bridge_service), |
| + wallpaper_delegate_(delegate), |
| + binding_(this) { |
| + arc_bridge_service()->wallpaper()->AddObserver(this); |
| +} |
| + |
| +ArcWallpaperBridge::~ArcWallpaperBridge() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + arc_bridge_service()->wallpaper()->RemoveObserver(this); |
| +} |
| + |
| +void ArcWallpaperBridge::OnInstanceReady() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + mojom::WallpaperInstance* wallpaper_instance = |
| + arc_bridge_service()->wallpaper()->instance(); |
| + if (!wallpaper_instance) { |
| + LOG(ERROR) << "OnWallpaperInstanceReady called, " |
| + << "but no wallpaper instance found"; |
| + return; |
| + } |
| + wallpaper_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| +} |
| + |
| +void ArcWallpaperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + wallpaper_delegate_->SetWallpaper(jpeg_data.PassStorage()); |
| +} |
| + |
| +void ArcWallpaperBridge::GetWallpaper( |
| + const base::Callback<void(mojo::Array<uint8_t>)>& callback) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + wallpaper_delegate_->GetWallpaper( |
| + base::Bind(&HandleWallpaperResult, callback)); |
|
dcheng
2016/08/29 20:33:19
FWIW, mojo::Array and stuff are deprecated. If we
Muyuan
2016/08/30 01:02:33
Added a TODO in the source. I'll fix that in the f
|
| +} |
| + |
| +} // namespace arc |