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" |
hidehiko
2016/12/15 00:58:49
As you're here, could you add #include "base/loggi
Yusuke Sato
2016/12/15 01:06:39
Done.
| |
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 DCHECK(manager_->thread_checker_.CalledOnValidThread()); | |
47 for (auto& observer : manager_->observer_list_) | |
48 observer.OnAppsUpdated(); | |
49 } | |
50 | |
27 ArcServiceManager::ArcServiceManager( | 51 ArcServiceManager::ArcServiceManager( |
28 scoped_refptr<base::TaskRunner> blocking_task_runner) | 52 scoped_refptr<base::TaskRunner> blocking_task_runner) |
29 : blocking_task_runner_(blocking_task_runner), | 53 : blocking_task_runner_(blocking_task_runner), |
54 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)), | |
30 icon_loader_(new ActivityIconLoader()), | 55 icon_loader_(new ActivityIconLoader()), |
31 activity_resolver_(new LocalActivityResolver()) { | 56 activity_resolver_(new LocalActivityResolver()) { |
32 DCHECK(!g_arc_service_manager); | 57 DCHECK(!g_arc_service_manager); |
33 g_arc_service_manager = this; | 58 g_arc_service_manager = this; |
34 | 59 |
35 if (g_arc_bridge_service_for_testing) { | 60 if (g_arc_bridge_service_for_testing) { |
36 arc_bridge_service_.reset(g_arc_bridge_service_for_testing); | 61 arc_bridge_service_.reset(g_arc_bridge_service_for_testing); |
37 g_arc_bridge_service_for_testing = nullptr; | 62 g_arc_bridge_service_for_testing = nullptr; |
38 } else { | 63 } else { |
39 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner)); | 64 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 void ArcServiceManager::AddObserver(Observer* observer) { | 103 void ArcServiceManager::AddObserver(Observer* observer) { |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 104 DCHECK(thread_checker_.CalledOnValidThread()); |
80 observer_list_.AddObserver(observer); | 105 observer_list_.AddObserver(observer); |
81 } | 106 } |
82 | 107 |
83 void ArcServiceManager::RemoveObserver(Observer* observer) { | 108 void ArcServiceManager::RemoveObserver(Observer* observer) { |
84 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
85 observer_list_.RemoveObserver(observer); | 110 observer_list_.RemoveObserver(observer); |
86 } | 111 } |
87 | 112 |
88 void ArcServiceManager::OnAppsUpdated() { | |
89 DCHECK(thread_checker_.CalledOnValidThread()); | |
90 for (auto& observer : observer_list_) | |
91 observer.OnAppsUpdated(); | |
92 } | |
93 | |
94 void ArcServiceManager::Shutdown() { | 113 void ArcServiceManager::Shutdown() { |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
96 icon_loader_ = nullptr; | 115 icon_loader_ = nullptr; |
97 activity_resolver_ = nullptr; | 116 activity_resolver_ = nullptr; |
98 services_.clear(); | 117 services_.clear(); |
99 arc_bridge_service_->OnShutdown(); | 118 arc_bridge_service_->OnShutdown(); |
100 } | 119 } |
101 | 120 |
102 // static | 121 // static |
103 void ArcServiceManager::SetArcBridgeServiceForTesting( | 122 void ArcServiceManager::SetArcBridgeServiceForTesting( |
104 std::unique_ptr<ArcBridgeService> arc_bridge_service) { | 123 std::unique_ptr<ArcBridgeService> arc_bridge_service) { |
105 if (g_arc_bridge_service_for_testing) | 124 if (g_arc_bridge_service_for_testing) |
106 delete g_arc_bridge_service_for_testing; | 125 delete g_arc_bridge_service_for_testing; |
107 g_arc_bridge_service_for_testing = arc_bridge_service.release(); | 126 g_arc_bridge_service_for_testing = arc_bridge_service.release(); |
108 } | 127 } |
109 | 128 |
110 } // namespace arc | 129 } // namespace arc |
OLD | NEW |