Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 #include <utility> | |
| 7 #include <vector> | 9 #include <vector> |
| 8 | 10 |
| 9 #include "ash/desktop_background/user_wallpaper_delegate.h" | 11 #include "ash/desktop_background/user_wallpaper_delegate.h" |
| 10 #include "ash/new_window_delegate.h" | 12 #include "ash/new_window_delegate.h" |
| 11 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 12 #include "ash/shell_delegate.h" | 14 #include "ash/shell_delegate.h" |
| 15 #include "base/bind.h" | |
| 13 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/task_runner_util.h" | |
| 14 #include "components/arc/intent_helper/activity_icon_loader.h" | 18 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 15 #include "components/arc/intent_helper/link_handler_model_impl.h" | 19 #include "components/arc/intent_helper/link_handler_model_impl.h" |
| 20 #include "components/arc/set_wallpaper_delegate.h" | |
| 21 #include "content/public/browser/browser_thread.h" | |
| 16 #include "ui/base/layout.h" | 22 #include "ui/base/layout.h" |
| 23 #include "ui/gfx/codec/jpeg_codec.h" | |
| 17 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 18 | 25 |
| 19 namespace arc { | 26 namespace arc { |
| 20 | 27 |
| 28 namespace { | |
| 29 | |
| 30 gfx::ImageSkia DecodeJpegImage(mojo::Array<uint8_t> jpeg_data) { | |
| 31 std::unique_ptr<SkBitmap> bitmap = gfx::JPEGCodec::Decode( | |
| 32 static_cast<const unsigned char*>(&jpeg_data.storage()[0]), | |
| 33 jpeg_data.size()); | |
| 34 bitmap->setImmutable(); | |
| 35 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap); | |
| 36 image.MakeThreadSafe(); | |
| 37 return std::move(image); | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 21 ArcIntentHelperBridge::ArcIntentHelperBridge( | 42 ArcIntentHelperBridge::ArcIntentHelperBridge( |
| 22 ArcBridgeService* bridge_service, | 43 ArcBridgeService* bridge_service, |
| 23 const scoped_refptr<ActivityIconLoader>& icon_loader) | 44 const scoped_refptr<ActivityIconLoader>& icon_loader, |
| 24 : ArcService(bridge_service), binding_(this), icon_loader_(icon_loader) { | 45 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 46 std::unique_ptr<SetWallpaperDelegate> set_wallpaper_delegate) | |
| 47 : ArcService(bridge_service), | |
| 48 binding_(this), | |
| 49 icon_loader_(icon_loader), | |
| 50 blocking_task_runner_(blocking_task_runner), | |
| 51 set_wallpaper_delegate_(std::move(set_wallpaper_delegate)), | |
| 52 weak_factory_(this) { | |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 25 arc_bridge_service()->AddObserver(this); | 54 arc_bridge_service()->AddObserver(this); |
| 26 } | 55 } |
| 27 | 56 |
| 28 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 57 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| 58 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.
| |
| 29 arc_bridge_service()->RemoveObserver(this); | 59 arc_bridge_service()->RemoveObserver(this); |
| 30 } | 60 } |
| 31 | 61 |
| 32 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { | 62 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { |
| 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 33 ash::Shell::GetInstance()->set_link_handler_model_factory(this); | 64 ash::Shell::GetInstance()->set_link_handler_model_factory(this); |
| 34 arc_bridge_service()->intent_helper_instance()->Init( | 65 arc_bridge_service()->intent_helper_instance()->Init( |
| 35 binding_.CreateInterfacePtrAndBind()); | 66 binding_.CreateInterfacePtrAndBind()); |
| 36 } | 67 } |
| 37 | 68 |
| 38 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { | 69 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { |
| 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 39 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); | 71 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); |
| 40 } | 72 } |
| 41 | 73 |
| 42 void ArcIntentHelperBridge::OnIconInvalidated( | 74 void ArcIntentHelperBridge::OnIconInvalidated( |
| 43 const mojo::String& package_name) { | 75 const mojo::String& package_name) { |
| 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 44 icon_loader_->InvalidateIcons(package_name); | 77 icon_loader_->InvalidateIcons(package_name); |
| 45 } | 78 } |
| 46 | 79 |
| 47 void ArcIntentHelperBridge::OnOpenDownloads() { | 80 void ArcIntentHelperBridge::OnOpenDownloads() { |
| 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 48 // TODO(607411): If the FileManager is not yet open this will open to | 82 // TODO(607411): If the FileManager is not yet open this will open to |
| 49 // downloads by default, which is what we want. However if it is open it will | 83 // downloads by default, which is what we want. However if it is open it will |
| 50 // simply be brought to the forgeground without forcibly being navigated to | 84 // simply be brought to the forgeground without forcibly being navigated to |
| 51 // downloads, which is probably not ideal. | 85 // downloads, which is probably not ideal. |
| 52 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager(); | 86 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager(); |
| 53 } | 87 } |
| 54 | 88 |
| 55 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { | 89 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 56 GURL gurl(url.get()); | 91 GURL gurl(url.get()); |
| 57 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); | 92 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); |
| 58 } | 93 } |
| 59 | 94 |
| 60 void ArcIntentHelperBridge::OpenWallpaperPicker() { | 95 void ArcIntentHelperBridge::OpenWallpaperPicker() { |
| 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 61 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); | 97 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); |
| 62 } | 98 } |
| 63 | 99 |
| 100 void ArcIntentHelperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) { | |
| 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 102 base::PostTaskAndReplyWithResult( | |
| 103 blocking_task_runner_.get(), FROM_HERE, | |
| 104 base::Bind(&DecodeJpegImage, base::Passed(std::move(jpeg_data))), | |
| 105 base::Bind(&ArcIntentHelperBridge::SetImageAsWallpaper, | |
| 106 weak_factory_.GetWeakPtr())); | |
| 107 } | |
| 108 | |
| 64 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( | 109 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( |
| 65 const GURL& url) { | 110 const GURL& url) { |
| 66 std::unique_ptr<LinkHandlerModelImpl> impl( | 111 std::unique_ptr<LinkHandlerModelImpl> impl( |
| 67 new LinkHandlerModelImpl(icon_loader_)); | 112 new LinkHandlerModelImpl(icon_loader_)); |
| 68 if (!impl->Init(url)) | 113 if (!impl->Init(url)) |
| 69 return nullptr; | 114 return nullptr; |
| 70 return std::move(impl); | 115 return std::move(impl); |
| 71 } | 116 } |
| 72 | 117 |
| 118 void ArcIntentHelperBridge::SetImageAsWallpaper(gfx::ImageSkia image) { | |
| 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 120 set_wallpaper_delegate_->SetWallpaper(image); | |
| 121 } | |
| 122 | |
| 73 } // namespace arc | 123 } // namespace arc |
| OLD | NEW |