Chromium Code Reviews| Index: components/arc/arc_service_manager.cc |
| diff --git a/components/arc/arc_service_manager.cc b/components/arc/arc_service_manager.cc |
| index 9204fef44844ccd7fc9ea29da2e6ba91aaba29fe..48ffbaa64d32f2f03c202b25afc4b6f55e994f4c 100644 |
| --- a/components/arc/arc_service_manager.cc |
| +++ b/components/arc/arc_service_manager.cc |
| @@ -4,8 +4,6 @@ |
| #include "components/arc/arc_service_manager.h" |
| -#include <utility> |
| - |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/task_runner.h" |
| @@ -75,9 +73,29 @@ ArcBridgeService* ArcServiceManager::arc_bridge_service() { |
| return arc_bridge_service_.get(); |
| } |
| -void ArcServiceManager::AddService(std::unique_ptr<ArcService> service) { |
| +bool ArcServiceManager::AddServiceInternal( |
| + const std::string& name, |
| + std::unique_ptr<ArcService> service) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - services_.emplace_back(std::move(service)); |
| + if (!name.empty() && services_.count(name) != 0) { |
| + LOG(ERROR) << "Ignoring registration of service with duplicate name: " |
| + << name; |
| + return false; |
| + } |
| + services_.insert(std::make_pair(name, std::move(service))); |
| + return true; |
| +} |
| + |
| +ArcService* ArcServiceManager::GetNamedServiceInternal( |
| + const std::string& name) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + 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
|
| + auto service = services_.find(name); |
| + if (service == services_.end()) { |
| + LOG(ERROR) << "Named service " << name << " not found"; |
| + return nullptr; |
| + } |
| + return service->second.get(); |
| } |
| void ArcServiceManager::AddObserver(Observer* observer) { |