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

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

Issue 2538263005: Simplify ArcServiceManager by stop deriving it from ArcIntentHelperObserver (Closed)
Patch Set: Address comment Created 4 years 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
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> 7 #include <utility>
8 8
9 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/arc/arc_bridge_service.h" 13 #include "components/arc/arc_bridge_service.h"
13 #include "components/arc/arc_bridge_service_impl.h" 14 #include "components/arc/arc_bridge_service_impl.h"
15 #include "components/arc/intent_helper/arc_intent_helper_observer.h"
14 16
15 namespace arc { 17 namespace arc {
16 18
17 namespace { 19 namespace {
18 20
19 // Weak pointer. This class is owned by arc::ArcServiceLauncher. 21 // Weak pointer. This class is owned by arc::ArcServiceLauncher.
20 ArcServiceManager* g_arc_service_manager = nullptr; 22 ArcServiceManager* g_arc_service_manager = nullptr;
21 23
22 // This pointer is owned by ArcServiceManager. 24 // This pointer is owned by ArcServiceManager.
23 ArcBridgeService* g_arc_bridge_service_for_testing = nullptr; 25 ArcBridgeService* g_arc_bridge_service_for_testing = nullptr;
24 26
25 } // namespace 27 } // namespace
26 28
29 class ArcServiceManager::IntentHelperObserverImpl
30 : public ArcIntentHelperObserver {
31 public:
32 explicit IntentHelperObserverImpl(ArcServiceManager* manager);
33 ~IntentHelperObserverImpl() override = default;
34
35 private:
36 void OnAppsUpdated() override;
37 ArcServiceManager* const manager_;
38
39 DISALLOW_COPY_AND_ASSIGN(IntentHelperObserverImpl);
40 };
41
42 ArcServiceManager::IntentHelperObserverImpl::IntentHelperObserverImpl(
43 ArcServiceManager* manager)
44 : manager_(manager) {}
45
46 void ArcServiceManager::IntentHelperObserverImpl::OnAppsUpdated() {
47 DCHECK(manager_->thread_checker_.CalledOnValidThread());
48 for (auto& observer : manager_->observer_list_)
49 observer.OnAppsUpdated();
50 }
51
27 ArcServiceManager::ArcServiceManager( 52 ArcServiceManager::ArcServiceManager(
28 scoped_refptr<base::TaskRunner> blocking_task_runner) 53 scoped_refptr<base::TaskRunner> blocking_task_runner)
29 : blocking_task_runner_(blocking_task_runner), 54 : blocking_task_runner_(blocking_task_runner),
55 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)),
30 icon_loader_(new ActivityIconLoader()), 56 icon_loader_(new ActivityIconLoader()),
31 activity_resolver_(new LocalActivityResolver()) { 57 activity_resolver_(new LocalActivityResolver()) {
32 DCHECK(!g_arc_service_manager); 58 DCHECK(!g_arc_service_manager);
33 g_arc_service_manager = this; 59 g_arc_service_manager = this;
34 60
35 if (g_arc_bridge_service_for_testing) { 61 if (g_arc_bridge_service_for_testing) {
36 arc_bridge_service_.reset(g_arc_bridge_service_for_testing); 62 arc_bridge_service_.reset(g_arc_bridge_service_for_testing);
37 g_arc_bridge_service_for_testing = nullptr; 63 g_arc_bridge_service_for_testing = nullptr;
38 } else { 64 } else {
39 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner)); 65 arc_bridge_service_.reset(new ArcBridgeServiceImpl(blocking_task_runner));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void ArcServiceManager::AddObserver(Observer* observer) { 104 void ArcServiceManager::AddObserver(Observer* observer) {
79 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
80 observer_list_.AddObserver(observer); 106 observer_list_.AddObserver(observer);
81 } 107 }
82 108
83 void ArcServiceManager::RemoveObserver(Observer* observer) { 109 void ArcServiceManager::RemoveObserver(Observer* observer) {
84 DCHECK(thread_checker_.CalledOnValidThread()); 110 DCHECK(thread_checker_.CalledOnValidThread());
85 observer_list_.RemoveObserver(observer); 111 observer_list_.RemoveObserver(observer);
86 } 112 }
87 113
88 void ArcServiceManager::OnAppsUpdated() {
89 DCHECK(thread_checker_.CalledOnValidThread());
90 for (auto& observer : observer_list_)
91 observer.OnAppsUpdated();
92 }
93
94 void ArcServiceManager::Shutdown() { 114 void ArcServiceManager::Shutdown() {
95 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
96 icon_loader_ = nullptr; 116 icon_loader_ = nullptr;
97 activity_resolver_ = nullptr; 117 activity_resolver_ = nullptr;
98 services_.clear(); 118 services_.clear();
99 arc_bridge_service_->OnShutdown(); 119 arc_bridge_service_->OnShutdown();
100 } 120 }
101 121
102 // static 122 // static
103 void ArcServiceManager::SetArcBridgeServiceForTesting( 123 void ArcServiceManager::SetArcBridgeServiceForTesting(
104 std::unique_ptr<ArcBridgeService> arc_bridge_service) { 124 std::unique_ptr<ArcBridgeService> arc_bridge_service) {
105 if (g_arc_bridge_service_for_testing) 125 if (g_arc_bridge_service_for_testing)
106 delete g_arc_bridge_service_for_testing; 126 delete g_arc_bridge_service_for_testing;
107 g_arc_bridge_service_for_testing = arc_bridge_service.release(); 127 g_arc_bridge_service_for_testing = arc_bridge_service.release();
108 } 128 }
109 129
110 } // namespace arc 130 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_service_manager.h ('k') | components/arc/intent_helper/arc_intent_helper_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698