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

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

Issue 2622843002: arc: Provide a per-service getter for ArcServiceManager (Closed)
Patch Set: Added a comment. Created 3 years, 11 months 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
« no previous file with comments | « components/arc/arc_service_manager.h ('k') | components/arc/arc_service_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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 if (name.empty()) {
93 LOG(ERROR) << "kArcServiceName[] should be a fully-qualified class name.";
94 return nullptr;
95 }
96 auto service = services_.find(name);
97 if (service == services_.end()) {
98 LOG(ERROR) << "Named service " << name << " not found";
99 return nullptr;
100 }
101 return service->second.get();
81 } 102 }
82 103
83 void ArcServiceManager::AddObserver(Observer* observer) { 104 void ArcServiceManager::AddObserver(Observer* observer) {
84 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
85 observer_list_.AddObserver(observer); 106 observer_list_.AddObserver(observer);
86 } 107 }
87 108
88 void ArcServiceManager::RemoveObserver(Observer* observer) { 109 void ArcServiceManager::RemoveObserver(Observer* observer) {
89 DCHECK(thread_checker_.CalledOnValidThread()); 110 DCHECK(thread_checker_.CalledOnValidThread());
90 observer_list_.RemoveObserver(observer); 111 observer_list_.RemoveObserver(observer);
91 } 112 }
92 113
93 void ArcServiceManager::Shutdown() { 114 void ArcServiceManager::Shutdown() {
94 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
95 116
96 // Before actual shutdown, notify observers for clean up. 117 // Before actual shutdown, notify observers for clean up.
97 for (auto& observer : observer_list_) 118 for (auto& observer : observer_list_)
98 observer.OnArcShutdown(); 119 observer.OnArcShutdown();
99 120
100 icon_loader_ = nullptr; 121 icon_loader_ = nullptr;
101 activity_resolver_ = nullptr; 122 activity_resolver_ = nullptr;
102 services_.clear(); 123 services_.clear();
103 } 124 }
104 125
105 } // namespace arc 126 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_service_manager.h ('k') | components/arc/arc_service_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698