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

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

Issue 1523643002: arc-bridge: Move most methods to Mojo interfaces (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Fixed unit tests Created 5 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_bridge_service_impl.h" 5 #include "components/arc/arc_bridge_service_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "chromeos/chromeos_switches.h" 16 #include "chromeos/chromeos_switches.h"
17 #include "chromeos/dbus/dbus_method_call_status.h" 17 #include "chromeos/dbus/dbus_method_call_status.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/session_manager_client.h" 19 #include "chromeos/dbus/session_manager_client.h"
20 #include "mojo/public/cpp/bindings/array.h"
21 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
22
23 namespace mojo {
24
25 template <>
26 struct TypeConverter<arc::AppInfo, arc::AppInfoPtr> {
27 static arc::AppInfo Convert(const arc::AppInfoPtr& app_info_ptr) {
28 return *app_info_ptr;
29 }
30 };
31
32 } // namespace mojo
33 20
34 namespace arc { 21 namespace arc {
35 22
36 ArcBridgeServiceImpl::ArcBridgeServiceImpl( 23 ArcBridgeServiceImpl::ArcBridgeServiceImpl(
37 scoped_ptr<ArcBridgeBootstrap> bootstrap) 24 scoped_ptr<ArcBridgeBootstrap> bootstrap)
38 : bootstrap_(std::move(bootstrap)), 25 : bootstrap_(std::move(bootstrap)),
39 binding_(this), 26 binding_(this),
40 session_started_(false), 27 session_started_(false),
41 weak_factory_(this) { 28 weak_factory_(this) {
42 bootstrap_->set_delegate(this); 29 bootstrap_->set_delegate(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
83 if (state() == State::STOPPED || state() == State::STOPPING) { 70 if (state() == State::STOPPED || state() == State::STOPPING) {
84 VLOG(1) << "StopInstance() called when ARC is not running"; 71 VLOG(1) << "StopInstance() called when ARC is not running";
85 return; 72 return;
86 } 73 }
87 74
88 SetState(State::STOPPING); 75 SetState(State::STOPPING);
89 bootstrap_->Stop(); 76 bootstrap_->Stop();
90 } 77 }
91 78
92 bool ArcBridgeServiceImpl::RegisterInputDevice(const std::string& name, 79 void ArcBridgeServiceImpl::OnAppInstanceReady(AppInstancePtr app_ptr) {
93 const std::string& device_type,
94 base::ScopedFD fd) {
95 DCHECK(CalledOnValidThread()); 80 DCHECK(CalledOnValidThread());
96 if (state() != State::READY) { 81 if (state() != State::READY) {
97 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; 82 VLOG(1) << "StopInstance() called";
98 return false; 83 return;
99 } 84 }
100 MojoHandle wrapped_handle; 85 app_ptr_ = std::move(app_ptr);
101 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( 86 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceReady());
102 mojo::embedder::ScopedPlatformHandle(
103 mojo::embedder::PlatformHandle(fd.release())),
104 &wrapped_handle);
105 if (wrap_result != MOJO_RESULT_OK) {
106 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result;
107 return false;
108 }
109 instance_ptr_->RegisterInputDevice(
110 name, device_type, mojo::ScopedHandle(mojo::Handle(wrapped_handle)));
111 return true;
112 } 87 }
113 88
114 bool ArcBridgeServiceImpl::SendNotificationEventToAndroid( 89 void ArcBridgeServiceImpl::OnInputInstanceReady(InputInstancePtr input_ptr) {
115 const std::string& key, ArcNotificationEvent event) {
116 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
117 if (key.empty()) { 91 if (state() != State::READY) {
118 LOG(ERROR) << "SendNotificationToAndroid failed: Wrong parameter"; 92 VLOG(1) << "StopInstance() called";
119 return false; 93 return;
120 } 94 }
121 if (state() != State::READY) { 95 input_ptr_ = std::move(input_ptr);
122 LOG(ERROR) << "Called SendNotificationEventToAndroid when the service is" 96 FOR_EACH_OBSERVER(Observer, observer_list(), OnInputInstanceReady());
123 << "not ready";
124 return false;
125 }
126 instance_ptr_->SendNotificationEventToAndroid(key, event);
127 return true;
128 } 97 }
129 98
130 bool ArcBridgeServiceImpl::RefreshAppList() { 99 void ArcBridgeServiceImpl::OnNotificationsInstanceReady(
100 NotificationsInstancePtr notifications_ptr) {
131 DCHECK(CalledOnValidThread()); 101 DCHECK(CalledOnValidThread());
132 if (state() != State::READY) { 102 if (state() != State::READY) {
133 LOG(ERROR) << "Called RefreshAppList when the service is not ready"; 103 VLOG(1) << "StopInstance() called";
134 return false; 104 return;
135 } 105 }
136 instance_ptr_->RefreshAppList(); 106 notifications_ptr_ = std::move(notifications_ptr);
137 return true; 107 FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceReady());
138 } 108 }
139 109
140 bool ArcBridgeServiceImpl::LaunchApp(const std::string& package, 110 void ArcBridgeServiceImpl::OnPowerInstanceReady(PowerInstancePtr power_ptr) {
141 const std::string& activity) {
142 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
143 if (state() != State::READY) { 112 if (state() != State::READY) {
144 LOG(ERROR) << "Called LaunchApp when the service is not ready"; 113 VLOG(1) << "StopInstance() called";
145 return false; 114 return;
146 } 115 }
147 instance_ptr_->LaunchApp(package, activity); 116 power_ptr_ = std::move(power_ptr);
148 return true; 117 FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceReady());
149 } 118 }
150 119
151 bool ArcBridgeServiceImpl::RequestAppIcon(const std::string& package, 120 void ArcBridgeServiceImpl::OnProcessListInstanceReady(
152 const std::string& activity, 121 ProcessListInstancePtr process_list_ptr) {
153 ScaleFactor scale_factor) {
154 DCHECK(CalledOnValidThread()); 122 DCHECK(CalledOnValidThread());
155 if (state() != State::READY) { 123 if (state() != State::READY) {
156 LOG(ERROR) << "Called RequestAppIcon when the service is not ready"; 124 VLOG(1) << "StopInstance() called";
157 return false;
158 }
159 instance_ptr_->RequestAppIcon(package, activity, scale_factor);
160 return true;
161 }
162
163 void ArcBridgeServiceImpl::OnInstanceBootPhase(InstanceBootPhase phase) {
164 DCHECK(CalledOnValidThread());
165 // The state can be CONNECTED the first time this is called, and will then
166 // transition to READY after BRIDGE_READY has been passed.
167 if (state() != State::CONNECTED && state() != State::READY) {
168 VLOG(1) << "StopInstance() called while connecting";
169 return; 125 return;
170 } 126 }
171 if (phase == INSTANCE_BOOT_PHASE_BRIDGE_READY) { 127 process_list_ptr_ = std::move(process_list_ptr);
172 SetState(State::READY); 128 FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessListInstanceReady());
173 }
174 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase));
175 }
176
177 void ArcBridgeServiceImpl::OnNotificationPosted(ArcNotificationDataPtr data) {
178 DCHECK(CalledOnValidThread());
179 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(),
180 OnNotificationPostedFromAndroid(*data.get()));
181 }
182
183 void ArcBridgeServiceImpl::OnNotificationRemoved(const mojo::String& key) {
184 DCHECK(CalledOnValidThread());
185 FOR_EACH_OBSERVER(NotificationObserver, notification_observer_list(),
186 OnNotificationRemovedFromAndroid(key));
187 }
188
189 void ArcBridgeServiceImpl::OnAppListRefreshed(
190 mojo::Array<arc::AppInfoPtr> apps_ptr) {
191 DCHECK(CalledOnValidThread());
192 std::vector<arc::AppInfo> apps(apps_ptr.To<std::vector<arc::AppInfo>>());
193 FOR_EACH_OBSERVER(AppObserver, app_observer_list(), OnAppListRefreshed(apps));
194 }
195
196 void ArcBridgeServiceImpl::OnAppIcon(const mojo::String& package,
197 const mojo::String& activity,
198 ScaleFactor scale_factor,
199 mojo::Array<uint8_t> icon_png_data) {
200 DCHECK(CalledOnValidThread());
201 FOR_EACH_OBSERVER(
202 AppObserver, app_observer_list(),
203 OnAppIcon(package, activity, scale_factor, icon_png_data.storage()));
204 }
205
206 void ArcBridgeServiceImpl::OnAcquireDisplayWakeLock(DisplayWakeLockType type) {
207 DCHECK(CalledOnValidThread());
208 // TODO(ejcaruso): Implement.
209 VLOG(1) << "OnAcquireDisplayWakeLock";
210 }
211
212 void ArcBridgeServiceImpl::OnReleaseDisplayWakeLock(DisplayWakeLockType type) {
213 DCHECK(CalledOnValidThread());
214 // TODO(ejcaruso): Implement.
215 VLOG(1) << "OnReleaseDisplayWakeLock";
216 } 129 }
217 130
218 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { 131 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) {
219 DCHECK(CalledOnValidThread()); 132 DCHECK(CalledOnValidThread());
220 if (available() == arc_available) 133 if (available() == arc_available)
221 return; 134 return;
222 SetAvailable(arc_available); 135 SetAvailable(arc_available);
223 PrerequisitesChanged(); 136 PrerequisitesChanged();
224 } 137 }
225 138
226 void ArcBridgeServiceImpl::OnConnectionEstablished( 139 void ArcBridgeServiceImpl::OnConnectionEstablished(
227 ArcBridgeInstancePtr instance) { 140 ArcBridgeInstancePtr instance) {
228 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
229 if (state() != State::CONNECTING) { 142 if (state() != State::CONNECTING) {
230 VLOG(1) << "StopInstance() called while connecting"; 143 VLOG(1) << "StopInstance() called while connecting";
231 return; 144 return;
232 } 145 }
233 146
234 instance_ptr_ = std::move(instance); 147 instance_ptr_ = std::move(instance);
235 148
236 ArcBridgeHostPtr host; 149 ArcBridgeHostPtr host;
237 binding_.Bind(GetProxy(&host)); 150 binding_.Bind(GetProxy(&host));
238 instance_ptr_->Init(std::move(host)); 151 instance_ptr_->Init(std::move(host));
239 152
240 SetState(State::CONNECTED); 153 SetState(State::READY);
241 } 154 }
242 155
243 void ArcBridgeServiceImpl::OnStopped() { 156 void ArcBridgeServiceImpl::OnStopped() {
244 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
245 SetState(State::STOPPED); 158 SetState(State::STOPPED);
246 } 159 }
247 160
248 } // namespace arc 161 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698