Chromium Code Reviews| 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..c63e08acdc64591b9117bf68933d8c9d5d3931af 100644 |
| --- a/components/arc/intent_helper/arc_intent_helper_bridge.cc |
| +++ b/components/arc/intent_helper/arc_intent_helper_bridge.cc |
| @@ -4,47 +4,81 @@ |
| #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 "content/public/browser/browser_thread.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_CURRENTLY_ON(content::BrowserThread::UI); |
| arc_bridge_service()->AddObserver(this); |
| } |
| ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
|
hidehiko
2016/06/14 13:44:16
Could you use ThreadChecker instead? Ditto for bel
Shuhei Takahashi
2016/06/14 14:08:39
Done.
|
| arc_bridge_service()->RemoveObserver(this); |
| } |
| void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| ash::Shell::GetInstance()->set_link_handler_model_factory(this); |
| arc_bridge_service()->intent_helper_instance()->Init( |
| binding_.CreateInterfacePtrAndBind()); |
| } |
| void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); |
| } |
| void ArcIntentHelperBridge::OnIconInvalidated( |
| const mojo::String& package_name) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| icon_loader_->InvalidateIcons(package_name); |
| } |
| void ArcIntentHelperBridge::OnOpenDownloads() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| // 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 +87,25 @@ void ArcIntentHelperBridge::OnOpenDownloads() { |
| } |
| void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| GURL gurl(url.get()); |
| ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); |
| } |
| void ArcIntentHelperBridge::OpenWallpaperPicker() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); |
| } |
| +void ArcIntentHelperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + 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 +115,9 @@ std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( |
| return std::move(impl); |
| } |
| +void ArcIntentHelperBridge::SetImageAsWallpaper(gfx::ImageSkia image) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + set_wallpaper_delegate_->SetWallpaper(image); |
| +} |
| + |
| } // namespace arc |