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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/new_window_controller.h" | 9 #include "ash/common/new_window_controller.h" |
| 10 #include "ash/common/shell_delegate.h" | 10 #include "ash/common/shell_delegate.h" |
| 11 #include "ash/common/wallpaper/wallpaper_controller.h" | 11 #include "ash/common/wallpaper/wallpaper_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/arc/arc_bridge_service.h" | 16 #include "components/arc/arc_bridge_service.h" |
| 17 #include "components/arc/arc_service_manager.h" | 17 #include "components/arc/arc_service_manager.h" |
| 18 #include "components/arc/intent_helper/activity_icon_loader.h" | |
| 19 #include "components/arc/intent_helper/link_handler_model_impl.h" | 18 #include "components/arc/intent_helper/link_handler_model_impl.h" |
| 20 #include "components/arc/intent_helper/local_activity_resolver.h" | 19 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 21 #include "ui/base/layout.h" | 20 #include "ui/base/layout.h" |
| 22 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 23 | 22 |
| 24 namespace arc { | 23 namespace arc { |
| 25 | 24 |
| 26 // static | 25 // static |
| 27 const char ArcIntentHelperBridge::kArcServiceName[] = | 26 const char ArcIntentHelperBridge::kArcServiceName[] = |
| 28 "arc::ArcIntentHelperBridge"; | 27 "arc::ArcIntentHelperBridge"; |
| 29 | 28 |
| 30 // static | 29 // static |
| 31 const char ArcIntentHelperBridge::kArcIntentHelperPackageName[] = | 30 const char ArcIntentHelperBridge::kArcIntentHelperPackageName[] = |
| 32 "org.chromium.arc.intent_helper"; | 31 "org.chromium.arc.intent_helper"; |
| 33 | 32 |
| 34 ArcIntentHelperBridge::ArcIntentHelperBridge( | 33 ArcIntentHelperBridge::ArcIntentHelperBridge( |
| 35 ArcBridgeService* bridge_service, | 34 ArcBridgeService* bridge_service, |
| 36 const scoped_refptr<ActivityIconLoader>& icon_loader, | |
| 37 const scoped_refptr<LocalActivityResolver>& activity_resolver) | 35 const scoped_refptr<LocalActivityResolver>& activity_resolver) |
| 38 : ArcService(bridge_service), | 36 : ArcService(bridge_service), |
| 39 binding_(this), | 37 binding_(this), |
| 40 icon_loader_(icon_loader), | |
| 41 activity_resolver_(activity_resolver) { | 38 activity_resolver_(activity_resolver) { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 arc_bridge_service()->intent_helper()->AddObserver(this); | 40 arc_bridge_service()->intent_helper()->AddObserver(this); |
| 44 } | 41 } |
| 45 | 42 |
| 46 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 43 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 arc_bridge_service()->intent_helper()->RemoveObserver(this); | 45 arc_bridge_service()->intent_helper()->RemoveObserver(this); |
| 49 } | 46 } |
| 50 | 47 |
| 51 void ArcIntentHelperBridge::OnInstanceReady() { | 48 void ArcIntentHelperBridge::OnInstanceReady() { |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 ash::Shell::GetInstance()->set_link_handler_model_factory(this); | 50 ash::Shell::GetInstance()->set_link_handler_model_factory(this); |
| 54 auto* instance = | 51 auto* instance = |
| 55 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->intent_helper(), Init); | 52 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->intent_helper(), Init); |
| 56 DCHECK(instance); | 53 DCHECK(instance); |
| 57 instance->Init(binding_.CreateInterfacePtrAndBind()); | 54 instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 58 } | 55 } |
| 59 | 56 |
| 60 void ArcIntentHelperBridge::OnInstanceClosed() { | 57 void ArcIntentHelperBridge::OnInstanceClosed() { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); | 59 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); |
| 63 } | 60 } |
| 64 | 61 |
| 65 void ArcIntentHelperBridge::OnIconInvalidated(const std::string& package_name) { | 62 void ArcIntentHelperBridge::OnIconInvalidated(const std::string& package_name) { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 icon_loader_->InvalidateIcons(package_name); | 64 icon_loader_.InvalidateIcons(package_name); |
| 68 } | 65 } |
| 69 | 66 |
| 70 void ArcIntentHelperBridge::OnOpenDownloads() { | 67 void ArcIntentHelperBridge::OnOpenDownloads() { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 // TODO(607411): If the FileManager is not yet open this will open to | 69 // TODO(607411): If the FileManager is not yet open this will open to |
| 73 // downloads by default, which is what we want. However if it is open it will | 70 // downloads by default, which is what we want. However if it is open it will |
| 74 // simply be brought to the forgeground without forcibly being navigated to | 71 // simply be brought to the forgeground without forcibly being navigated to |
| 75 // downloads, which is probably not ideal. | 72 // downloads, which is probably not ideal. |
| 76 ash::WmShell::Get()->new_window_controller()->OpenFileManager(); | 73 ash::WmShell::Get()->new_window_controller()->OpenFileManager(); |
| 77 } | 74 } |
| 78 | 75 |
| 79 void ArcIntentHelperBridge::OnOpenUrl(const std::string& url) { | 76 void ArcIntentHelperBridge::OnOpenUrl(const std::string& url) { |
| 80 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 81 ash::WmShell::Get()->delegate()->OpenUrlFromArc(GURL(url)); | 78 ash::WmShell::Get()->delegate()->OpenUrlFromArc(GURL(url)); |
| 82 } | 79 } |
| 83 | 80 |
| 84 void ArcIntentHelperBridge::OpenWallpaperPicker() { | 81 void ArcIntentHelperBridge::OpenWallpaperPicker() { |
| 85 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 ash::WmShell::Get()->wallpaper_controller()->OpenSetWallpaperPage(); | 83 ash::WmShell::Get()->wallpaper_controller()->OpenSetWallpaperPage(); |
| 87 } | 84 } |
| 88 | 85 |
| 89 void ArcIntentHelperBridge::SetWallpaperDeprecated( | 86 void ArcIntentHelperBridge::SetWallpaperDeprecated( |
| 90 const std::vector<uint8_t>& jpeg_data) { | 87 const std::vector<uint8_t>& jpeg_data) { |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 92 LOG(ERROR) << "IntentHelper.SetWallpaper is deprecated"; | 89 LOG(ERROR) << "IntentHelper.SetWallpaper is deprecated"; |
| 93 } | 90 } |
| 94 | 91 |
| 92 ArcIntentHelperBridge::GetResult ArcIntentHelperBridge::GetActivityIcons( | |
| 93 const std::vector<ActivityName>& activities, | |
| 94 const OnIconsReadyCallback& callback) { | |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 96 return icon_loader_.GetActivityIcons(activities, callback); | |
| 97 } | |
| 98 | |
| 95 void ArcIntentHelperBridge::AddObserver(ArcIntentHelperObserver* observer) { | 99 void ArcIntentHelperBridge::AddObserver(ArcIntentHelperObserver* observer) { |
| 96 observer_list_.AddObserver(observer); | 100 observer_list_.AddObserver(observer); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void ArcIntentHelperBridge::RemoveObserver(ArcIntentHelperObserver* observer) { | 103 void ArcIntentHelperBridge::RemoveObserver(ArcIntentHelperObserver* observer) { |
| 100 observer_list_.RemoveObserver(observer); | 104 observer_list_.RemoveObserver(observer); |
| 101 } | 105 } |
| 102 | 106 |
| 103 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( | 107 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( |
| 104 const GURL& url) { | 108 const GURL& url) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 std::unique_ptr<LinkHandlerModelImpl> impl( | 110 auto impl = base::MakeUnique<LinkHandlerModelImpl>(); |
| 107 new LinkHandlerModelImpl(icon_loader_)); | |
| 108 if (!impl->Init(url)) | 111 if (!impl->Init(url)) |
| 109 return nullptr; | 112 return nullptr; |
| 110 return std::move(impl); | 113 return std::move(impl); |
| 111 } | 114 } |
| 112 | 115 |
| 113 // static | 116 // static |
| 114 bool ArcIntentHelperBridge::IsIntentHelperPackage( | 117 bool ArcIntentHelperBridge::IsIntentHelperPackage( |
| 115 const std::string& package_name) { | 118 const std::string& package_name) { |
| 116 return package_name == kArcIntentHelperPackageName; | 119 return package_name == kArcIntentHelperPackageName; |
| 117 } | 120 } |
| 118 | 121 |
| 119 // static | 122 // static |
| 120 std::vector<mojom::IntentHandlerInfoPtr> | 123 std::vector<mojom::IntentHandlerInfoPtr> |
| 121 ArcIntentHelperBridge::FilterOutIntentHelper( | 124 ArcIntentHelperBridge::FilterOutIntentHelper( |
| 122 std::vector<mojom::IntentHandlerInfoPtr> handlers) { | 125 std::vector<mojom::IntentHandlerInfoPtr> handlers) { |
| 123 std::vector<mojom::IntentHandlerInfoPtr> handlers_filtered; | 126 std::vector<mojom::IntentHandlerInfoPtr> handlers_filtered; |
| 124 for (auto& handler : handlers) { | 127 for (auto& handler : handlers) { |
| 125 if (IsIntentHelperPackage(handler->package_name)) | 128 if (IsIntentHelperPackage(handler->package_name)) |
| 126 continue; | 129 continue; |
| 127 handlers_filtered.push_back(std::move(handler)); | 130 handlers_filtered.push_back(std::move(handler)); |
| 128 } | 131 } |
| 129 return handlers_filtered; | 132 return handlers_filtered; |
| 130 } | 133 } |
| 131 | 134 |
| 132 // static | |
| 133 bool ArcIntentHelperBridge::IsIntentHelperAvailable(GetResult* out_error_code) { | |
|
hidehiko
2017/01/30 17:04:03
Merged into GetInstanceForRequestActivityIcons() i
| |
| 134 auto* arc_service_manager = ArcServiceManager::Get(); | |
| 135 if (!arc_service_manager) { | |
| 136 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { | |
| 137 VLOG(2) << "ARC bridge is not supported."; | |
| 138 if (out_error_code) | |
| 139 *out_error_code = GetResult::FAILED_ARC_NOT_SUPPORTED; | |
| 140 } else { | |
| 141 VLOG(2) << "ARC bridge is not ready."; | |
| 142 if (out_error_code) | |
| 143 *out_error_code = GetResult::FAILED_ARC_NOT_READY; | |
| 144 } | |
| 145 return false; | |
| 146 } | |
| 147 | |
| 148 auto* intent_helper_holder = | |
| 149 arc_service_manager->arc_bridge_service()->intent_helper(); | |
| 150 if (!intent_helper_holder->has_instance()) { | |
| 151 VLOG(2) << "ARC intent helper instance is not ready."; | |
| 152 if (out_error_code) | |
| 153 *out_error_code = GetResult::FAILED_ARC_NOT_READY; | |
| 154 return false; | |
| 155 } | |
| 156 | |
| 157 return true; | |
| 158 } | |
| 159 | |
| 160 void ArcIntentHelperBridge::OnIntentFiltersUpdated( | 135 void ArcIntentHelperBridge::OnIntentFiltersUpdated( |
| 161 std::vector<IntentFilter> filters) { | 136 std::vector<IntentFilter> filters) { |
| 162 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
| 163 activity_resolver_->UpdateIntentFilters(std::move(filters)); | 138 activity_resolver_->UpdateIntentFilters(std::move(filters)); |
| 164 | 139 |
| 165 for (auto& observer : observer_list_) | 140 for (auto& observer : observer_list_) |
| 166 observer.OnIntentFiltersUpdated(); | 141 observer.OnIntentFiltersUpdated(); |
| 167 } | 142 } |
| 168 | 143 |
| 169 } // namespace arc | 144 } // namespace arc |
| OLD | NEW |