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> | |
8 | |
9 #include "base/logging.h" | 7 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
11 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
12 #include "components/arc/arc_bridge_service.h" | 10 #include "components/arc/arc_bridge_service.h" |
13 #include "components/arc/arc_session.h" | 11 #include "components/arc/arc_session.h" |
14 #include "components/arc/arc_session_runner.h" | 12 #include "components/arc/arc_session_runner.h" |
15 #include "components/arc/intent_helper/arc_intent_helper_observer.h" | 13 #include "components/arc/intent_helper/arc_intent_helper_observer.h" |
16 | 14 |
17 namespace arc { | 15 namespace arc { |
18 namespace { | 16 namespace { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 return nullptr; | 66 return nullptr; |
69 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread()); | 67 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread()); |
70 return g_arc_service_manager; | 68 return g_arc_service_manager; |
71 } | 69 } |
72 | 70 |
73 ArcBridgeService* ArcServiceManager::arc_bridge_service() { | 71 ArcBridgeService* ArcServiceManager::arc_bridge_service() { |
74 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
75 return arc_bridge_service_.get(); | 73 return arc_bridge_service_.get(); |
76 } | 74 } |
77 | 75 |
78 void ArcServiceManager::AddService(std::unique_ptr<ArcService> service) { | 76 bool ArcServiceManager::AddServiceInternal( |
77 const std::string& name, | |
78 std::unique_ptr<ArcService> service) { | |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 79 DCHECK(thread_checker_.CalledOnValidThread()); |
80 services_.emplace_back(std::move(service)); | 80 if (!name.empty() && services_.count(name) != 0) { |
81 LOG(ERROR) << "Ignoring registration of service with duplicate name: " | |
82 << name; | |
83 return false; | |
84 } | |
85 services_.insert(std::make_pair(name, std::move(service))); | |
86 return true; | |
87 } | |
88 | |
89 ArcService* ArcServiceManager::GetNamedServiceInternal( | |
90 const std::string& name) { | |
91 DCHECK(thread_checker_.CalledOnValidThread()); | |
92 DCHECK(!name.empty()); | |
Yusuke Sato
2017/01/10 19:30:57
This may actually happen by developer's mistake. L
Luis Héctor Chávez
2017/01/10 23:48:09
The only way that is possible is if they would set
| |
93 auto service = services_.find(name); | |
94 if (service == services_.end()) { | |
95 LOG(ERROR) << "Named service " << name << " not found"; | |
96 return nullptr; | |
97 } | |
98 return service->second.get(); | |
81 } | 99 } |
82 | 100 |
83 void ArcServiceManager::AddObserver(Observer* observer) { | 101 void ArcServiceManager::AddObserver(Observer* observer) { |
84 DCHECK(thread_checker_.CalledOnValidThread()); | 102 DCHECK(thread_checker_.CalledOnValidThread()); |
85 observer_list_.AddObserver(observer); | 103 observer_list_.AddObserver(observer); |
86 } | 104 } |
87 | 105 |
88 void ArcServiceManager::RemoveObserver(Observer* observer) { | 106 void ArcServiceManager::RemoveObserver(Observer* observer) { |
89 DCHECK(thread_checker_.CalledOnValidThread()); | 107 DCHECK(thread_checker_.CalledOnValidThread()); |
90 observer_list_.RemoveObserver(observer); | 108 observer_list_.RemoveObserver(observer); |
91 } | 109 } |
92 | 110 |
93 void ArcServiceManager::Shutdown() { | 111 void ArcServiceManager::Shutdown() { |
94 DCHECK(thread_checker_.CalledOnValidThread()); | 112 DCHECK(thread_checker_.CalledOnValidThread()); |
95 | 113 |
96 // Before actual shutdown, notify observers for clean up. | 114 // Before actual shutdown, notify observers for clean up. |
97 for (auto& observer : observer_list_) | 115 for (auto& observer : observer_list_) |
98 observer.OnArcShutdown(); | 116 observer.OnArcShutdown(); |
99 | 117 |
100 icon_loader_ = nullptr; | 118 icon_loader_ = nullptr; |
101 activity_resolver_ = nullptr; | 119 activity_resolver_ = nullptr; |
102 services_.clear(); | 120 services_.clear(); |
103 } | 121 } |
104 | 122 |
105 } // namespace arc | 123 } // namespace arc |
OLD | NEW |