| 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 #ifndef COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ | 5 #ifndef COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ |
| 6 #define COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ | 6 #define COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/link_handler_model_factory.h" | 12 #include "ash/link_handler_model_factory.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "components/arc/arc_service.h" | 17 #include "components/arc/arc_service.h" |
| 18 #include "components/arc/common/intent_helper.mojom.h" | 18 #include "components/arc/common/intent_helper.mojom.h" |
| 19 #include "components/arc/instance_holder.h" | 19 #include "components/arc/instance_holder.h" |
| 20 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 20 #include "components/arc/intent_helper/arc_intent_helper_observer.h" | 21 #include "components/arc/intent_helper/arc_intent_helper_observer.h" |
| 21 #include "mojo/public/cpp/bindings/binding.h" | 22 #include "mojo/public/cpp/bindings/binding.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 class LinkHandlerModel; | 26 class LinkHandlerModel; |
| 26 | 27 |
| 27 } // namespace ash | 28 } // namespace ash |
| 28 | 29 |
| 29 namespace arc { | 30 namespace arc { |
| 30 | 31 |
| 31 class ActivityIconLoader; | |
| 32 class ArcBridgeService; | 32 class ArcBridgeService; |
| 33 class IntentFilter; | 33 class IntentFilter; |
| 34 class LocalActivityResolver; | 34 class LocalActivityResolver; |
| 35 | 35 |
| 36 // Receives intents from ARC. | 36 // Receives intents from ARC. |
| 37 class ArcIntentHelperBridge | 37 class ArcIntentHelperBridge |
| 38 : public ArcService, | 38 : public ArcService, |
| 39 public InstanceHolder<mojom::IntentHelperInstance>::Observer, | 39 public InstanceHolder<mojom::IntentHelperInstance>::Observer, |
| 40 public mojom::IntentHelperHost, | 40 public mojom::IntentHelperHost, |
| 41 public ash::LinkHandlerModelFactory { | 41 public ash::LinkHandlerModelFactory { |
| 42 public: | 42 public: |
| 43 enum class GetResult { | |
| 44 // Failed. The intent_helper instance is not yet ready. This is a temporary | |
| 45 // error. | |
| 46 FAILED_ARC_NOT_READY, | |
| 47 // Failed. Either ARC is not supported at all or intent_helper instance | |
| 48 // version is too old. | |
| 49 FAILED_ARC_NOT_SUPPORTED, | |
| 50 }; | |
| 51 | |
| 52 ArcIntentHelperBridge( | 43 ArcIntentHelperBridge( |
| 53 ArcBridgeService* bridge_service, | 44 ArcBridgeService* bridge_service, |
| 54 const scoped_refptr<ActivityIconLoader>& icon_loader, | |
| 55 const scoped_refptr<LocalActivityResolver>& activity_resolver); | 45 const scoped_refptr<LocalActivityResolver>& activity_resolver); |
| 56 ~ArcIntentHelperBridge() override; | 46 ~ArcIntentHelperBridge() override; |
| 57 | 47 |
| 58 void AddObserver(ArcIntentHelperObserver* observer); | 48 void AddObserver(ArcIntentHelperObserver* observer); |
| 59 void RemoveObserver(ArcIntentHelperObserver* observer); | 49 void RemoveObserver(ArcIntentHelperObserver* observer); |
| 60 | 50 |
| 61 // InstanceHolder<mojom::IntentHelperInstance>::Observer | 51 // InstanceHolder<mojom::IntentHelperInstance>::Observer |
| 62 void OnInstanceReady() override; | 52 void OnInstanceReady() override; |
| 63 void OnInstanceClosed() override; | 53 void OnInstanceClosed() override; |
| 64 | 54 |
| 65 // mojom::IntentHelperHost | 55 // mojom::IntentHelperHost |
| 66 void OnIconInvalidated(const std::string& package_name) override; | 56 void OnIconInvalidated(const std::string& package_name) override; |
| 67 void OnIntentFiltersUpdated( | 57 void OnIntentFiltersUpdated( |
| 68 std::vector<IntentFilter> intent_filters) override; | 58 std::vector<IntentFilter> intent_filters) override; |
| 69 void OnOpenDownloads() override; | 59 void OnOpenDownloads() override; |
| 70 void OnOpenUrl(const std::string& url) override; | 60 void OnOpenUrl(const std::string& url) override; |
| 71 void OpenWallpaperPicker() override; | 61 void OpenWallpaperPicker() override; |
| 72 void SetWallpaperDeprecated(const std::vector<uint8_t>& jpeg_data) override; | 62 void SetWallpaperDeprecated(const std::vector<uint8_t>& jpeg_data) override; |
| 73 | 63 |
| 64 // Retrieves icons for the |activities| and calls |callback|. |
| 65 // See ActivityIconLoader::GetActivityIcons() for more details. |
| 66 using ActivityName = internal::ActivityIconLoader::ActivityName; |
| 67 // A part of OnIconsReadyCallback signature. |
| 68 using ActivityToIconsMap = internal::ActivityIconLoader::ActivityToIconsMap; |
| 69 using OnIconsReadyCallback = |
| 70 internal::ActivityIconLoader::OnIconsReadyCallback; |
| 71 using GetResult = internal::ActivityIconLoader::GetResult; |
| 72 GetResult GetActivityIcons(const std::vector<ActivityName>& activities, |
| 73 const OnIconsReadyCallback& callback); |
| 74 |
| 74 // ash::LinkHandlerModelFactory | 75 // ash::LinkHandlerModelFactory |
| 75 std::unique_ptr<ash::LinkHandlerModel> CreateModel(const GURL& url) override; | 76 std::unique_ptr<ash::LinkHandlerModel> CreateModel(const GURL& url) override; |
| 76 | 77 |
| 77 // Returns false if |package_name| is for the intent_helper apk. | 78 // Returns false if |package_name| is for the intent_helper apk. |
| 78 static bool IsIntentHelperPackage(const std::string& package_name); | 79 static bool IsIntentHelperPackage(const std::string& package_name); |
| 79 | 80 |
| 80 // Filters out handlers that belong to the intent_helper apk and returns | 81 // Filters out handlers that belong to the intent_helper apk and returns |
| 81 // a new array. | 82 // a new array. |
| 82 static std::vector<mojom::IntentHandlerInfoPtr> FilterOutIntentHelper( | 83 static std::vector<mojom::IntentHandlerInfoPtr> FilterOutIntentHelper( |
| 83 std::vector<mojom::IntentHandlerInfoPtr> handlers); | 84 std::vector<mojom::IntentHandlerInfoPtr> handlers); |
| 84 | 85 |
| 85 // Checks if the intent helper interface is available. When it is not, returns | |
| 86 // false and updates |out_error_code| if it's not nullptr. | |
| 87 static bool IsIntentHelperAvailable(GetResult* out_error_code); | |
| 88 | |
| 89 // For supporting ArcServiceManager::GetService<T>(). | 86 // For supporting ArcServiceManager::GetService<T>(). |
| 90 static const char kArcServiceName[]; | 87 static const char kArcServiceName[]; |
| 91 | 88 |
| 92 static const char kArcIntentHelperPackageName[]; | 89 static const char kArcIntentHelperPackageName[]; |
| 93 | 90 |
| 94 private: | 91 private: |
| 95 mojo::Binding<mojom::IntentHelperHost> binding_; | 92 mojo::Binding<mojom::IntentHelperHost> binding_; |
| 96 scoped_refptr<ActivityIconLoader> icon_loader_; | 93 internal::ActivityIconLoader icon_loader_; |
| 97 scoped_refptr<LocalActivityResolver> activity_resolver_; | 94 scoped_refptr<LocalActivityResolver> activity_resolver_; |
| 98 | 95 |
| 99 base::ThreadChecker thread_checker_; | 96 base::ThreadChecker thread_checker_; |
| 100 | 97 |
| 101 base::ObserverList<ArcIntentHelperObserver> observer_list_; | 98 base::ObserverList<ArcIntentHelperObserver> observer_list_; |
| 102 | 99 |
| 103 DISALLOW_COPY_AND_ASSIGN(ArcIntentHelperBridge); | 100 DISALLOW_COPY_AND_ASSIGN(ArcIntentHelperBridge); |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 } // namespace arc | 103 } // namespace arc |
| 107 | 104 |
| 108 #endif // COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ | 105 #endif // COMPONENTS_ARC_INTENT_HELPER_ARC_INTENT_HELPER_BRIDGE_H_ |
| OLD | NEW |