Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: components/arc/arc_service_manager.h

Issue 2538263005: Simplify ArcServiceManager by stop deriving it from ArcIntentHelperObserver (Closed)
Patch Set: review Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/observer_list.h"
14 #include "base/task_runner.h" 14 #include "base/task_runner.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #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"
18 #include "components/arc/intent_helper/local_activity_resolver.h" 17 #include "components/arc/intent_helper/local_activity_resolver.h"
19 18
20 namespace arc { 19 namespace arc {
21 20
22 class ArcBridgeService; 21 class ArcBridgeService;
22 class ArcIntentHelperObserver;
23 class ArcService; 23 class ArcService;
24 24
25 // Manages creation and destruction of services that communicate with the ARC 25 // Manages creation and destruction of services that communicate with the ARC
26 // instance via the ArcBridgeService. 26 // instance via the ArcBridgeService.
27 class ArcServiceManager : public arc::ArcIntentHelperObserver { 27 class ArcServiceManager {
28 public: 28 public:
29 class Observer { 29 class Observer {
30 public: 30 public:
31 // Called when app's intent filter is updated. 31 // Called when app's intent filter is updated.
32 virtual void OnAppsUpdated() = 0; 32 virtual void OnAppsUpdated() = 0;
33 33
34 protected: 34 protected:
35 virtual ~Observer() = default; 35 virtual ~Observer() = default;
36 }; 36 };
37 37
38 explicit ArcServiceManager( 38 explicit ArcServiceManager(
39 scoped_refptr<base::TaskRunner> blocking_task_runner); 39 scoped_refptr<base::TaskRunner> blocking_task_runner);
40 ~ArcServiceManager() override; 40 ~ArcServiceManager();
41 41
42 // |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
43 // class was created on. 43 // class was created on.
44 ArcBridgeService* arc_bridge_service(); 44 ArcBridgeService* arc_bridge_service();
45 45
46 // Adds a service to the managed services list. 46 // Adds a service to the managed services list.
47 void AddService(std::unique_ptr<ArcService> service); 47 void AddService(std::unique_ptr<ArcService> service);
48 48
49 // 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
50 // called on the thread that this class was created on. 50 // called on the thread that this class was created on.
51 static ArcServiceManager* Get(); 51 static ArcServiceManager* Get();
52 52
53 // Returns if the ARC Service Manager instance exists. 53 // Returns if the ARC Service Manager instance exists.
54 static bool IsInitialized(); 54 static bool IsInitialized();
55 55
56 void AddObserver(Observer* observer); 56 void AddObserver(Observer* observer);
57 void RemoveObserver(Observer* observer); 57 void RemoveObserver(Observer* observer);
58 58
59 // arc::ArcIntentHelperObserver overrides.
60 void OnAppsUpdated() override;
61
62 // Called to shut down all ARC services. 59 // Called to shut down all ARC services.
63 void Shutdown(); 60 void Shutdown();
64 61
65 scoped_refptr<base::TaskRunner> blocking_task_runner() const { 62 scoped_refptr<base::TaskRunner> blocking_task_runner() const {
66 return blocking_task_runner_; 63 return blocking_task_runner_;
67 } 64 }
68 65
69 // Set ArcBridgeService instance for testing. Call before ArcServiceManager 66 // Set ArcBridgeService instance for testing. Call before ArcServiceManager
70 // creation. ArcServiceManager owns |arc_bridge_service|. 67 // creation. ArcServiceManager owns |arc_bridge_service|.
71 static void SetArcBridgeServiceForTesting( 68 static void SetArcBridgeServiceForTesting(
72 std::unique_ptr<ArcBridgeService> arc_bridge_service); 69 std::unique_ptr<ArcBridgeService> arc_bridge_service);
73 70
74 // Returns the icon loader owned by ArcServiceManager and shared by services. 71 // Returns the icon loader owned by ArcServiceManager and shared by services.
75 scoped_refptr<ActivityIconLoader> icon_loader() { return icon_loader_; } 72 scoped_refptr<ActivityIconLoader> icon_loader() { return icon_loader_; }
76 73
77 // Returns the activity resolver owned by ArcServiceManager. 74 // Returns the activity resolver owned by ArcServiceManager.
78 scoped_refptr<LocalActivityResolver> activity_resolver() { 75 scoped_refptr<LocalActivityResolver> activity_resolver() {
79 return activity_resolver_; 76 return activity_resolver_;
80 } 77 }
81 78
79 // Returns the IntentHelperObserver instance owned by ArcServiceManager.
80 ArcIntentHelperObserver* intent_helper_observer() {
81 return intent_helper_observer_.get();
82 }
83
82 private: 84 private:
85 class IntentHelperObserverImpl; // implemented in arc_service_manager.cc.
hidehiko 2016/12/14 09:06:08 This can be just a standalone class in anonymous n
Yusuke Sato 2016/12/15 00:52:33 Based on your second comment on the .cc side, I gu
hidehiko 2016/12/15 00:58:49 Yes, I'm fine to skip this as well.
86
83 base::ThreadChecker thread_checker_; 87 base::ThreadChecker thread_checker_;
84 scoped_refptr<base::TaskRunner> blocking_task_runner_; 88 scoped_refptr<base::TaskRunner> blocking_task_runner_;
85 89
90 // An object for observing the ArcIntentHelper instance in |services_|.
91 std::unique_ptr<ArcIntentHelperObserver> intent_helper_observer_;
92
86 std::unique_ptr<ArcBridgeService> arc_bridge_service_; 93 std::unique_ptr<ArcBridgeService> arc_bridge_service_;
87 std::vector<std::unique_ptr<ArcService>> services_; 94 std::vector<std::unique_ptr<ArcService>> services_;
88 scoped_refptr<ActivityIconLoader> icon_loader_; 95 scoped_refptr<ActivityIconLoader> icon_loader_;
89 scoped_refptr<LocalActivityResolver> activity_resolver_; 96 scoped_refptr<LocalActivityResolver> activity_resolver_;
90 97
91 base::ObserverList<Observer> observer_list_; 98 base::ObserverList<Observer> observer_list_;
92 99
93 DISALLOW_COPY_AND_ASSIGN(ArcServiceManager); 100 DISALLOW_COPY_AND_ASSIGN(ArcServiceManager);
94 }; 101 };
95 102
96 } // namespace arc 103 } // namespace arc
97 104
98 #endif // COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_ 105 #endif // COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698