| Index: components/arc/intent_helper/arc_intent_helper_bridge.cc
|
| diff --git a/components/arc/intent_helper/arc_intent_helper_bridge.cc b/components/arc/intent_helper/arc_intent_helper_bridge.cc
|
| index dd326fcfe3ab74f92443c1bdc54402e365066fc4..b929ccdcf6c53cc0675533fd30becfa7ef7d9549 100644
|
| --- a/components/arc/intent_helper/arc_intent_helper_bridge.cc
|
| +++ b/components/arc/intent_helper/arc_intent_helper_bridge.cc
|
| @@ -4,47 +4,80 @@
|
|
|
| #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
|
|
|
| +#include <memory>
|
| +#include <utility>
|
| #include <vector>
|
|
|
| #include "ash/desktop_background/user_wallpaper_delegate.h"
|
| #include "ash/new_window_delegate.h"
|
| #include "ash/shell.h"
|
| #include "ash/shell_delegate.h"
|
| +#include "base/bind.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/task_runner_util.h"
|
| #include "components/arc/intent_helper/activity_icon_loader.h"
|
| #include "components/arc/intent_helper/link_handler_model_impl.h"
|
| +#include "components/arc/set_wallpaper_delegate.h"
|
| #include "ui/base/layout.h"
|
| +#include "ui/gfx/codec/jpeg_codec.h"
|
| #include "url/gurl.h"
|
|
|
| namespace arc {
|
|
|
| +namespace {
|
| +
|
| +gfx::ImageSkia DecodeJpegImage(mojo::Array<uint8_t> jpeg_data) {
|
| + std::unique_ptr<SkBitmap> bitmap = gfx::JPEGCodec::Decode(
|
| + static_cast<const unsigned char*>(&jpeg_data.storage()[0]),
|
| + jpeg_data.size());
|
| + bitmap->setImmutable();
|
| + gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap);
|
| + image.MakeThreadSafe();
|
| + return std::move(image);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| ArcIntentHelperBridge::ArcIntentHelperBridge(
|
| ArcBridgeService* bridge_service,
|
| - const scoped_refptr<ActivityIconLoader>& icon_loader)
|
| - : ArcService(bridge_service), binding_(this), icon_loader_(icon_loader) {
|
| + const scoped_refptr<ActivityIconLoader>& icon_loader,
|
| + const scoped_refptr<base::TaskRunner>& blocking_task_runner,
|
| + std::unique_ptr<SetWallpaperDelegate> set_wallpaper_delegate)
|
| + : ArcService(bridge_service),
|
| + binding_(this),
|
| + icon_loader_(icon_loader),
|
| + blocking_task_runner_(blocking_task_runner),
|
| + set_wallpaper_delegate_(std::move(set_wallpaper_delegate)),
|
| + weak_factory_(this) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| arc_bridge_service()->AddObserver(this);
|
| }
|
|
|
| ArcIntentHelperBridge::~ArcIntentHelperBridge() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| arc_bridge_service()->RemoveObserver(this);
|
| }
|
|
|
| void ArcIntentHelperBridge::OnIntentHelperInstanceReady() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| ash::Shell::GetInstance()->set_link_handler_model_factory(this);
|
| arc_bridge_service()->intent_helper_instance()->Init(
|
| binding_.CreateInterfacePtrAndBind());
|
| }
|
|
|
| void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr);
|
| }
|
|
|
| void ArcIntentHelperBridge::OnIconInvalidated(
|
| const mojo::String& package_name) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| icon_loader_->InvalidateIcons(package_name);
|
| }
|
|
|
| void ArcIntentHelperBridge::OnOpenDownloads() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| // TODO(607411): If the FileManager is not yet open this will open to
|
| // downloads by default, which is what we want. However if it is open it will
|
| // simply be brought to the forgeground without forcibly being navigated to
|
| @@ -53,14 +86,25 @@ void ArcIntentHelperBridge::OnOpenDownloads() {
|
| }
|
|
|
| void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| GURL gurl(url.get());
|
| ash::Shell::GetInstance()->delegate()->OpenUrl(gurl);
|
| }
|
|
|
| void ArcIntentHelperBridge::OpenWallpaperPicker() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
|
| }
|
|
|
| +void ArcIntentHelperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + base::PostTaskAndReplyWithResult(
|
| + blocking_task_runner_.get(), FROM_HERE,
|
| + base::Bind(&DecodeJpegImage, base::Passed(std::move(jpeg_data))),
|
| + base::Bind(&ArcIntentHelperBridge::SetImageAsWallpaper,
|
| + weak_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel(
|
| const GURL& url) {
|
| std::unique_ptr<LinkHandlerModelImpl> impl(
|
| @@ -70,4 +114,9 @@ std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel(
|
| return std::move(impl);
|
| }
|
|
|
| +void ArcIntentHelperBridge::SetImageAsWallpaper(gfx::ImageSkia image) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + set_wallpaper_delegate_->SetWallpaper(image);
|
| +}
|
| +
|
| } // namespace arc
|
|
|