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 #include "components/arc/arc_service_manager.h" | 5 #include "components/arc/arc_service_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/arc_bridge_service.h" |
13 #include "components/arc/arc_bridge_service_impl.h" | 13 #include "components/arc/arc_bridge_service_impl.h" |
14 #include "components/arc/intent_helper/arc_intent_helper_observer.h" | |
14 | 15 |
15 namespace arc { | 16 namespace arc { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Weak pointer. This class is owned by arc::ArcServiceLauncher. | 20 // Weak pointer. This class is owned by arc::ArcServiceLauncher. |
20 ArcServiceManager* g_arc_service_manager = nullptr; | 21 ArcServiceManager* g_arc_service_manager = nullptr; |
21 | 22 |
22 // This pointer is owned by ArcServiceManager. | 23 // This pointer is owned by ArcServiceManager. |
23 ArcBridgeService* g_arc_bridge_service_for_testing = nullptr; | 24 ArcBridgeService* g_arc_bridge_service_for_testing = nullptr; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
28 class ArcServiceManager::IntentHelperObserverImpl | |
29 : public ArcIntentHelperObserver { | |
30 public: | |
31 explicit IntentHelperObserverImpl(ArcServiceManager* manager); | |
32 ~IntentHelperObserverImpl() override = default; | |
33 | |
34 private: | |
35 void OnAppsUpdated() override; | |
36 ArcServiceManager* const manager_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(IntentHelperObserverImpl); | |
39 }; | |
40 | |
41 ArcServiceManager::IntentHelperObserverImpl::IntentHelperObserverImpl( | |
42 ArcServiceManager* manager) | |
43 : manager_(manager) {} | |
44 | |
45 void ArcServiceManager::IntentHelperObserverImpl::OnAppsUpdated() { | |
46 for (auto& observer : manager_->observer_list_) | |
hidehiko
2016/12/14 09:06:08
In C++, it is not allowed to access a private memb
hidehiko
2016/12/14 09:11:01
On, wait. My knowledge was old. I've just learnt C
| |
47 observer.OnAppsUpdated(); | |
48 } | |
49 | |
27 ArcServiceManager::ArcServiceManager( | 50 ArcServiceManager::ArcServiceManager( |
28 scoped_refptr<base::TaskRunner> blocking_task_runner) | 51 scoped_refptr<base::TaskRunner> blocking_task_runner) |
29 : blocking_task_runner_(blocking_task_runner), | 52 : blocking_task_runner_(blocking_task_runner), |
53 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)), | |
30 icon_loader_(new ActivityIconLoader()), | 54 icon_loader_(new ActivityIconLoader()), |
31 activity_resolver_(new LocalActivityResolver()) { | 55 activity_resolver_(new LocalActivityResolver()) { |
32 DCHECK(!g_arc_service_manager); | 56 DCHECK(!g_arc_service_manager); |
33 g_arc_service_manager = this; | 57 g_arc_service_manager = this; |
34 | 58 |
35 if (g_arc_bridge_service_for_testing) { | 59 if (g_arc_bridge_service_for_testing) { |
36 arc_bridge_service_.reset(g_arc_bridge_service_for_testing); | 60 arc_bridge_service_.reset(g_arc_bridge_service_for_testing); |
37 g_arc_bridge_service_for_testing = nullptr; | 61 g_arc_bridge_service_for_testing = nullptr; |
38 } else { | 62 } else { |
39 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner)); | 63 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 } | 96 } |
73 | 97 |
74 void ArcServiceManager::AddObserver(Observer* observer) { | 98 void ArcServiceManager::AddObserver(Observer* observer) { |
75 observer_list_.AddObserver(observer); | 99 observer_list_.AddObserver(observer); |
76 } | 100 } |
77 | 101 |
78 void ArcServiceManager::RemoveObserver(Observer* observer) { | 102 void ArcServiceManager::RemoveObserver(Observer* observer) { |
79 observer_list_.RemoveObserver(observer); | 103 observer_list_.RemoveObserver(observer); |
80 } | 104 } |
81 | 105 |
82 void ArcServiceManager::OnAppsUpdated() { | |
83 for (auto& observer : observer_list_) | |
84 observer.OnAppsUpdated(); | |
85 } | |
86 | |
87 void ArcServiceManager::Shutdown() { | 106 void ArcServiceManager::Shutdown() { |
88 icon_loader_ = nullptr; | 107 icon_loader_ = nullptr; |
89 activity_resolver_ = nullptr; | 108 activity_resolver_ = nullptr; |
90 services_.clear(); | 109 services_.clear(); |
91 arc_bridge_service_->OnShutdown(); | 110 arc_bridge_service_->OnShutdown(); |
92 } | 111 } |
93 | 112 |
94 // static | 113 // static |
95 void ArcServiceManager::SetArcBridgeServiceForTesting( | 114 void ArcServiceManager::SetArcBridgeServiceForTesting( |
96 std::unique_ptr<ArcBridgeService> arc_bridge_service) { | 115 std::unique_ptr<ArcBridgeService> arc_bridge_service) { |
97 if (g_arc_bridge_service_for_testing) | 116 if (g_arc_bridge_service_for_testing) |
98 delete g_arc_bridge_service_for_testing; | 117 delete g_arc_bridge_service_for_testing; |
99 g_arc_bridge_service_for_testing = arc_bridge_service.release(); | 118 g_arc_bridge_service_for_testing = arc_bridge_service.release(); |
100 } | 119 } |
101 | 120 |
102 } // namespace arc | 121 } // namespace arc |
OLD | NEW |