| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_ARC_SERVICE_MANAGER_H_ | 5 #ifndef COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ |
| 6 #define COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ | 6 #define COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/observer_list.h" |
| 13 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "components/arc/intent_helper/activity_icon_loader.h" | 16 #include "components/arc/intent_helper/activity_icon_loader.h" |
| 17 #include "components/arc/intent_helper/arc_intent_helper_observer.h" |
| 16 #include "components/arc/intent_helper/local_activity_resolver.h" | 18 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 17 | 19 |
| 18 namespace arc { | 20 namespace arc { |
| 19 | 21 |
| 20 class ArcBridgeService; | 22 class ArcBridgeService; |
| 21 class ArcService; | 23 class ArcService; |
| 22 | 24 |
| 23 // Manages creation and destruction of services that communicate with the ARC | 25 // Manages creation and destruction of services that communicate with the ARC |
| 24 // instance via the ArcBridgeService. | 26 // instance via the ArcBridgeService. |
| 25 class ArcServiceManager { | 27 class ArcServiceManager : public arc::ArcIntentHelperObserver { |
| 26 public: | 28 public: |
| 29 class Observer { |
| 30 public: |
| 31 // Called when app's intent filter is updated. |
| 32 virtual void OnAppsUpdated() = 0; |
| 33 |
| 34 protected: |
| 35 virtual ~Observer() = default; |
| 36 }; |
| 37 |
| 27 explicit ArcServiceManager( | 38 explicit ArcServiceManager( |
| 28 scoped_refptr<base::TaskRunner> blocking_task_runner); | 39 scoped_refptr<base::TaskRunner> blocking_task_runner); |
| 29 virtual ~ArcServiceManager(); | 40 ~ArcServiceManager() override; |
| 30 | 41 |
| 31 // |arc_bridge_service| can only be accessed on the thread that this | 42 // |arc_bridge_service| can only be accessed on the thread that this |
| 32 // class was created on. | 43 // class was created on. |
| 33 ArcBridgeService* arc_bridge_service(); | 44 ArcBridgeService* arc_bridge_service(); |
| 34 | 45 |
| 35 // Adds a service to the managed services list. | 46 // Adds a service to the managed services list. |
| 36 void AddService(std::unique_ptr<ArcService> service); | 47 void AddService(std::unique_ptr<ArcService> service); |
| 37 | 48 |
| 38 // Gets the global instance of the ARC Service Manager. This can only be | 49 // Gets the global instance of the ARC Service Manager. This can only be |
| 39 // called on the thread that this class was created on. | 50 // called on the thread that this class was created on. |
| 40 static ArcServiceManager* Get(); | 51 static ArcServiceManager* Get(); |
| 41 | 52 |
| 53 // Returns if the ARC Service Manager instance exists. |
| 54 static bool IsInitialized(); |
| 55 |
| 56 void AddObserver(Observer* observer); |
| 57 void RemoveObserver(Observer* observer); |
| 58 |
| 59 // arc::ArcIntentHelperObserver overrides. |
| 60 void OnAppsUpdated() override; |
| 61 |
| 42 // Called to shut down all ARC services. | 62 // Called to shut down all ARC services. |
| 43 void Shutdown(); | 63 void Shutdown(); |
| 44 | 64 |
| 45 scoped_refptr<base::TaskRunner> blocking_task_runner() const { | 65 scoped_refptr<base::TaskRunner> blocking_task_runner() const { |
| 46 return blocking_task_runner_; | 66 return blocking_task_runner_; |
| 47 } | 67 } |
| 48 | 68 |
| 49 // Set ArcBridgeService instance for testing. Call before ArcServiceManager | 69 // Set ArcBridgeService instance for testing. Call before ArcServiceManager |
| 50 // creation. ArcServiceManager owns |arc_bridge_service|. | 70 // creation. ArcServiceManager owns |arc_bridge_service|. |
| 51 static void SetArcBridgeServiceForTesting( | 71 static void SetArcBridgeServiceForTesting( |
| 52 std::unique_ptr<ArcBridgeService> arc_bridge_service); | 72 std::unique_ptr<ArcBridgeService> arc_bridge_service); |
| 53 | 73 |
| 54 // Returns the icon loader owned by ArcServiceManager and shared by services. | 74 // Returns the icon loader owned by ArcServiceManager and shared by services. |
| 55 scoped_refptr<ActivityIconLoader> icon_loader() { return icon_loader_; } | 75 scoped_refptr<ActivityIconLoader> icon_loader() { return icon_loader_; } |
| 56 | 76 |
| 57 // Returns the activity resolver owned by ArcServiceManager. | 77 // Returns the activity resolver owned by ArcServiceManager. |
| 58 scoped_refptr<LocalActivityResolver> activity_resolver() { | 78 scoped_refptr<LocalActivityResolver> activity_resolver() { |
| 59 return activity_resolver_; | 79 return activity_resolver_; |
| 60 } | 80 } |
| 61 | 81 |
| 62 private: | 82 private: |
| 63 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
| 64 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 84 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 65 | 85 |
| 66 std::unique_ptr<ArcBridgeService> arc_bridge_service_; | 86 std::unique_ptr<ArcBridgeService> arc_bridge_service_; |
| 67 std::vector<std::unique_ptr<ArcService>> services_; | 87 std::vector<std::unique_ptr<ArcService>> services_; |
| 68 scoped_refptr<ActivityIconLoader> icon_loader_; | 88 scoped_refptr<ActivityIconLoader> icon_loader_; |
| 69 scoped_refptr<LocalActivityResolver> activity_resolver_; | 89 scoped_refptr<LocalActivityResolver> activity_resolver_; |
| 70 | 90 |
| 91 base::ObserverList<Observer> observer_list_; |
| 92 |
| 71 DISALLOW_COPY_AND_ASSIGN(ArcServiceManager); | 93 DISALLOW_COPY_AND_ASSIGN(ArcServiceManager); |
| 72 }; | 94 }; |
| 73 | 95 |
| 74 } // namespace arc | 96 } // namespace arc |
| 75 | 97 |
| 76 #endif // COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ | 98 #endif // COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ |
| OLD | NEW |