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

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

Issue 2596273002: Move ArcSessionRunner from ArcBridgeService to ArcSessionManager. (Closed)
Patch Set: Rebase and update comments. Created 3 years, 12 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') | no next file » | 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> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/task_runner.h" 11 #include "base/task_runner.h"
12 #include "components/arc/arc_bridge_service.h" 12 #include "components/arc/arc_bridge_service.h"
13 #include "components/arc/arc_session.h" 13 #include "components/arc/arc_session.h"
14 #include "components/arc/arc_session_runner.h" 14 #include "components/arc/arc_session_runner.h"
15 #include "components/arc/intent_helper/arc_intent_helper_observer.h" 15 #include "components/arc/intent_helper/arc_intent_helper_observer.h"
16 16
17 namespace arc { 17 namespace arc {
18 namespace { 18 namespace {
19 19
20 // Weak pointer. This class is owned by arc::ArcServiceLauncher. 20 // Weak pointer. This class is owned by arc::ArcServiceLauncher.
21 ArcServiceManager* g_arc_service_manager = nullptr; 21 ArcServiceManager* g_arc_service_manager = nullptr;
22 22
23 // This pointer is owned by ArcServiceManager.
24 ArcSessionRunner* g_arc_session_runner_for_testing = nullptr;
25
26 } // namespace 23 } // namespace
27 24
28 class ArcServiceManager::IntentHelperObserverImpl 25 class ArcServiceManager::IntentHelperObserverImpl
29 : public ArcIntentHelperObserver { 26 : public ArcIntentHelperObserver {
30 public: 27 public:
31 explicit IntentHelperObserverImpl(ArcServiceManager* manager); 28 explicit IntentHelperObserverImpl(ArcServiceManager* manager);
32 ~IntentHelperObserverImpl() override = default; 29 ~IntentHelperObserverImpl() override = default;
33 30
34 private: 31 private:
35 void OnIntentFiltersUpdated() override; 32 void OnIntentFiltersUpdated() override;
36 ArcServiceManager* const manager_; 33 ArcServiceManager* const manager_;
37 34
38 DISALLOW_COPY_AND_ASSIGN(IntentHelperObserverImpl); 35 DISALLOW_COPY_AND_ASSIGN(IntentHelperObserverImpl);
39 }; 36 };
40 37
41 ArcServiceManager::IntentHelperObserverImpl::IntentHelperObserverImpl( 38 ArcServiceManager::IntentHelperObserverImpl::IntentHelperObserverImpl(
42 ArcServiceManager* manager) 39 ArcServiceManager* manager)
43 : manager_(manager) {} 40 : manager_(manager) {}
44 41
45 void ArcServiceManager::IntentHelperObserverImpl::OnIntentFiltersUpdated() { 42 void ArcServiceManager::IntentHelperObserverImpl::OnIntentFiltersUpdated() {
46 DCHECK(manager_->thread_checker_.CalledOnValidThread()); 43 DCHECK(manager_->thread_checker_.CalledOnValidThread());
47 for (auto& observer : manager_->observer_list_) 44 for (auto& observer : manager_->observer_list_)
48 observer.OnIntentFiltersUpdated(); 45 observer.OnIntentFiltersUpdated();
49 } 46 }
50 47
51 ArcServiceManager::ArcServiceManager( 48 ArcServiceManager::ArcServiceManager(
52 scoped_refptr<base::TaskRunner> blocking_task_runner) 49 scoped_refptr<base::TaskRunner> blocking_task_runner)
53 : blocking_task_runner_(blocking_task_runner), 50 : blocking_task_runner_(blocking_task_runner),
54 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)), 51 intent_helper_observer_(base::MakeUnique<IntentHelperObserverImpl>(this)),
52 arc_bridge_service_(base::MakeUnique<ArcBridgeService>()),
55 icon_loader_(new ActivityIconLoader()), 53 icon_loader_(new ActivityIconLoader()),
56 activity_resolver_(new LocalActivityResolver()) { 54 activity_resolver_(new LocalActivityResolver()) {
57 DCHECK(!g_arc_service_manager); 55 DCHECK(!g_arc_service_manager);
58 g_arc_service_manager = this; 56 g_arc_service_manager = this;
59
60 arc_bridge_service_ = base::MakeUnique<ArcBridgeService>();
61 if (g_arc_session_runner_for_testing) {
62 arc_bridge_service_->InitializeArcSessionRunner(
63 base::WrapUnique(g_arc_session_runner_for_testing));
64 g_arc_session_runner_for_testing = nullptr;
65 } else {
66 arc_bridge_service_->InitializeArcSessionRunner(
67 base::MakeUnique<ArcSessionRunner>(base::Bind(&ArcSession::Create,
68 arc_bridge_service_.get(),
69 blocking_task_runner)));
70 }
71 } 57 }
72 58
73 ArcServiceManager::~ArcServiceManager() { 59 ArcServiceManager::~ArcServiceManager() {
74 DCHECK(thread_checker_.CalledOnValidThread()); 60 DCHECK(thread_checker_.CalledOnValidThread());
75 DCHECK(g_arc_service_manager == this); 61 DCHECK_EQ(g_arc_service_manager, this);
76 g_arc_service_manager = nullptr; 62 g_arc_service_manager = nullptr;
77 if (g_arc_session_runner_for_testing)
78 delete g_arc_session_runner_for_testing;
79 } 63 }
80 64
81 // static 65 // static
82 ArcServiceManager* ArcServiceManager::Get() { 66 ArcServiceManager* ArcServiceManager::Get() {
83 if (!g_arc_service_manager) 67 if (!g_arc_service_manager)
84 return nullptr; 68 return nullptr;
85 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread()); 69 DCHECK(g_arc_service_manager->thread_checker_.CalledOnValidThread());
86 return g_arc_service_manager; 70 return g_arc_service_manager;
87 } 71 }
88 72
(...skipping 20 matching lines...) Expand all
109 void ArcServiceManager::Shutdown() { 93 void ArcServiceManager::Shutdown() {
110 DCHECK(thread_checker_.CalledOnValidThread()); 94 DCHECK(thread_checker_.CalledOnValidThread());
111 95
112 // Before actual shutdown, notify observers for clean up. 96 // Before actual shutdown, notify observers for clean up.
113 for (auto& observer : observer_list_) 97 for (auto& observer : observer_list_)
114 observer.OnArcShutdown(); 98 observer.OnArcShutdown();
115 99
116 icon_loader_ = nullptr; 100 icon_loader_ = nullptr;
117 activity_resolver_ = nullptr; 101 activity_resolver_ = nullptr;
118 services_.clear(); 102 services_.clear();
119 arc_bridge_service_->OnShutdown();
120 }
121
122 // static
123 void ArcServiceManager::SetArcSessionRunnerForTesting(
124 std::unique_ptr<ArcSessionRunner> arc_session_runner) {
125 if (g_arc_session_runner_for_testing)
126 delete g_arc_session_runner_for_testing;
127 g_arc_session_runner_for_testing = arc_session_runner.release();
128 } 103 }
129 104
130 } // namespace arc 105 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_service_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698