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

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

Issue 2623273003: arc: Remove ArcServiceManager::Observer (Closed)
Patch Set: Moved Get() to the manager class per (verbal) feedback from Luis 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/task_runner.h" 9 #include "base/task_runner.h"
10 #include "components/arc/arc_bridge_service.h" 10 #include "components/arc/arc_bridge_service.h"
11 #include "components/arc/arc_session.h" 11 #include "components/arc/arc_session.h"
12 #include "components/arc/arc_session_runner.h" 12 #include "components/arc/arc_session_runner.h"
13 #include "components/arc/intent_helper/arc_intent_helper_observer.h" 13 #include "components/arc/intent_helper/arc_intent_helper_observer.h"
14 14
15 namespace arc { 15 namespace arc {
16 namespace { 16 namespace {
17 17
18 // Weak pointer. This class is owned by arc::ArcServiceLauncher. 18 // Weak pointer. This class is owned by arc::ArcServiceLauncher.
19 ArcServiceManager* g_arc_service_manager = nullptr; 19 ArcServiceManager* g_arc_service_manager = nullptr;
20 20
21 } // namespace 21 } // namespace
22 22
23 class ArcServiceManager::IntentHelperObserverImpl
24 : public ArcIntentHelperObserver {
25 public:
26 explicit IntentHelperObserverImpl(ArcServiceManager* manager);
27 ~IntentHelperObserverImpl() override = default;
28
29 private:
30 void OnIntentFiltersUpdated() override;
31 ArcServiceManager* const manager_;
32
33 DISALLOW_COPY_AND_ASSIGN(IntentHelperObserverImpl);
34 };
35
36 ArcServiceManager::IntentHelperObserverImpl::IntentHelperObserverImpl(
37 ArcServiceManager* manager)
38 : manager_(manager) {}
39
40 void ArcServiceManager::IntentHelperObserverImpl::OnIntentFiltersUpdated() {
41 DCHECK(manager_->thread_checker_.CalledOnValidThread());
42 for (auto& observer : manager_->observer_list_)
43 observer.OnIntentFiltersUpdated();
44 }
45
46 ArcServiceManager::ArcServiceManager( 23 ArcServiceManager::ArcServiceManager(
47 scoped_refptr<base::TaskRunner> blocking_task_runner) 24 scoped_refptr<base::TaskRunner> blocking_task_runner)
48 : blocking_task_runner_(blocking_task_runner), 25 : blocking_task_runner_(blocking_task_runner),
49 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)),
50 arc_bridge_service_(base::MakeUnique<ArcBridgeService>()), 26 arc_bridge_service_(base::MakeUnique<ArcBridgeService>()),
51 icon_loader_(new ActivityIconLoader()), 27 icon_loader_(new ActivityIconLoader()),
52 activity_resolver_(new LocalActivityResolver()) { 28 activity_resolver_(new LocalActivityResolver()) {
53 DCHECK(!g_arc_service_manager); 29 DCHECK(!g_arc_service_manager);
54 g_arc_service_manager = this; 30 g_arc_service_manager = this;
55 } 31 }
56 32
57 ArcServiceManager::~ArcServiceManager() { 33 ArcServiceManager::~ArcServiceManager() {
58 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
59 DCHECK_EQ(g_arc_service_manager, this); 35 DCHECK_EQ(g_arc_service_manager, this);
60 g_arc_service_manager = nullptr; 36 g_arc_service_manager = nullptr;
61 } 37 }
62 38
63 // static 39 // static
64 ArcServiceManager* ArcServiceManager::Get() { 40 ArcServiceManager* ArcServiceManager::Get() {
65 if (!g_arc_service_manager) 41 if (!g_arc_service_manager)
66 return nullptr; 42 return nullptr;
67 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread()); 43 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread());
68 return g_arc_service_manager; 44 return g_arc_service_manager;
69 } 45 }
70 46
71 // static
72 bool ArcServiceManager::IsInitialized() {
73 if (!g_arc_service_manager)
74 return false;
75 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread());
76 return true;
77 }
78
79 ArcBridgeService* ArcServiceManager::arc_bridge_service() { 47 ArcBridgeService* ArcServiceManager::arc_bridge_service() {
80 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
81 return arc_bridge_service_.get(); 49 return arc_bridge_service_.get();
82 } 50 }
83 51
84 bool ArcServiceManager::AddServiceInternal( 52 bool ArcServiceManager::AddServiceInternal(
85 const std::string& name, 53 const std::string& name,
86 std::unique_ptr<ArcService> service) { 54 std::unique_ptr<ArcService> service) {
87 DCHECK(thread_checker_.CalledOnValidThread()); 55 DCHECK(thread_checker_.CalledOnValidThread());
88 if (!name.empty() && services_.count(name) != 0) { 56 if (!name.empty() && services_.count(name) != 0) {
(...skipping 13 matching lines...) Expand all
102 return nullptr; 70 return nullptr;
103 } 71 }
104 auto service = services_.find(name); 72 auto service = services_.find(name);
105 if (service == services_.end()) { 73 if (service == services_.end()) {
106 LOG(ERROR) << "Named service " << name << " not found"; 74 LOG(ERROR) << "Named service " << name << " not found";
107 return nullptr; 75 return nullptr;
108 } 76 }
109 return service->second.get(); 77 return service->second.get();
110 } 78 }
111 79
112 void ArcServiceManager::AddObserver(Observer* observer) {
113 DCHECK(thread_checker_.CalledOnValidThread());
114 observer_list_.AddObserver(observer);
115 }
116
117 void ArcServiceManager::RemoveObserver(Observer* observer) {
118 DCHECK(thread_checker_.CalledOnValidThread());
119 observer_list_.RemoveObserver(observer);
120 }
121
122 void ArcServiceManager::Shutdown() { 80 void ArcServiceManager::Shutdown() {
123 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
124 icon_loader_ = nullptr; 82 icon_loader_ = nullptr;
125 activity_resolver_ = nullptr; 83 activity_resolver_ = nullptr;
126 services_.clear(); 84 services_.clear();
127 } 85 }
128 86
129 } // namespace arc 87 } // 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