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

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

Issue 1475583002: Add IPC messages for ARC notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 chromeos::SessionManagerClient* session_manager_client = 93 chromeos::SessionManagerClient* session_manager_client =
94 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); 94 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
95 session_manager_client->StopArcInstance(base::Bind( 95 session_manager_client->StopArcInstance(base::Bind(
96 &ArcBridgeServiceImpl::OnInstanceStopped, weak_factory_.GetWeakPtr())); 96 &ArcBridgeServiceImpl::OnInstanceStopped, weak_factory_.GetWeakPtr()));
97 } 97 }
98 98
99 bool ArcBridgeServiceImpl::RegisterInputDevice(const std::string& name, 99 bool ArcBridgeServiceImpl::RegisterInputDevice(const std::string& name,
100 const std::string& device_type, 100 const std::string& device_type,
101 base::ScopedFD fd) { 101 base::ScopedFD fd) {
102 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 102 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
103 if (state() != State::READY) { 103 return SendMessageIfReady(new ArcInstanceMsg_RegisterInputDevice(
104 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready";
105 return false;
106 }
107 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice(
108 name, device_type, base::FileDescriptor(fd.Pass()))); 104 name, device_type, base::FileDescriptor(fd.Pass())));
109 } 105 }
110 106
107 bool ArcBridgeServiceImpl::SendNotificationEventToAndroid(
108 const std::string& key, ArcNotificationEvent event) {
109 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread());
110 if (key.empty()) {
111 LOG(ERROR) << "NotifyNotificationEvent failed: Wrong parameter";
elijahtaylor1 2015/12/01 07:02:36 method rename in log message
yoshiki 2015/12/02 02:38:24 Done.
112 return false;
113 }
114 return SendMessageIfReady(
115 new ArcInstanceMsg_NotifyNotificationEvent(key, event));
elijahtaylor1 2015/12/01 07:02:36 I think the method name change should go all the w
yoshiki 2015/12/02 02:38:24 Done.
116 }
117
111 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) { 118 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) {
112 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 119 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
113 if (state() != State::STOPPED) { 120 if (state() != State::STOPPED) {
114 VLOG(1) << "SocketConnect() called when instance is not stopped"; 121 VLOG(1) << "SocketConnect() called when instance is not stopped";
115 return; 122 return;
116 } 123 }
117 SetState(State::CONNECTING); 124 SetState(State::CONNECTING);
118 base::PostTaskAndReplyWithResult( 125 base::PostTaskAndReplyWithResult(
119 file_task_runner_.get(), FROM_HERE, 126 file_task_runner_.get(), FROM_HERE,
120 base::Bind(&base::CreateDirectory, socket_path.DirName()), 127 base::Bind(&base::CreateDirectory, socket_path.DirName()),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 192 }
186 193
187 SetState(State::STARTING); 194 SetState(State::STARTING);
188 chromeos::SessionManagerClient* session_manager_client = 195 chromeos::SessionManagerClient* session_manager_client =
189 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); 196 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
190 session_manager_client->StartArcInstance( 197 session_manager_client->StartArcInstance(
191 socket_path.value(), base::Bind(&ArcBridgeServiceImpl::OnInstanceStarted, 198 socket_path.value(), base::Bind(&ArcBridgeServiceImpl::OnInstanceStarted,
192 weak_factory_.GetWeakPtr())); 199 weak_factory_.GetWeakPtr()));
193 } 200 }
194 201
202 bool ArcBridgeServiceImpl::SendMessageIfReady(IPC::Message* message) {
203 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread());
204 if (state() != State::READY) {
205 LOG(ERROR) << "Tried to send a message but the service is not ready";
elijahtaylor1 2015/12/01 07:02:36 too bad we lose the actual method name here, is th
yoshiki 2015/12/02 02:38:24 Let me revert back here to the original. I think c
206 return false;
207 }
208 return ipc_channel_->Send(message);
209 }
210
195 void ArcBridgeServiceImpl::OnInstanceStarted(bool success) { 211 void ArcBridgeServiceImpl::OnInstanceStarted(bool success) {
196 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 212 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
197 if (state() != State::STARTING) { 213 if (state() != State::STARTING) {
198 VLOG(1) << "StopInstance() called while connecting"; 214 VLOG(1) << "StopInstance() called while connecting";
199 return; 215 return;
200 } 216 }
201 if (!success) { 217 if (!success) {
202 LOG(ERROR) << "ARC instance unable to start. Shutting down the bridge"; 218 LOG(ERROR) << "ARC instance unable to start. Shutting down the bridge";
203 StopInstance(); 219 StopInstance();
204 return; 220 return;
205 } 221 }
206 } 222 }
207 223
208 void ArcBridgeServiceImpl::OnInstanceBootPhase(InstanceBootPhase phase) { 224 void ArcBridgeServiceImpl::OnInstanceBootPhase(InstanceBootPhase phase) {
209 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 225 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
210 // The state can be STARTING the first time this is called, and will then 226 // The state can be STARTING the first time this is called, and will then
211 // transition to READY after BRIDGE_READY has been passed. 227 // transition to READY after BRIDGE_READY has been passed.
212 if (state() != State::STARTING && state() != State::READY) { 228 if (state() != State::STARTING && state() != State::READY) {
213 VLOG(1) << "StopInstance() called while connecting"; 229 VLOG(1) << "StopInstance() called while connecting";
214 return; 230 return;
215 } 231 }
216 if (phase == InstanceBootPhase::BRIDGE_READY) { 232 if (phase == InstanceBootPhase::BRIDGE_READY) {
217 SetState(State::READY); 233 SetState(State::READY);
218 } 234 }
219 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); 235 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase));
220 } 236 }
221 237
238 void ArcBridgeServiceImpl::OnNotificationPostedFromAndroid(
239 const arc::ArcNotificationData& data) {
240 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
241 FOR_EACH_OBSERVER(Observer, observer_list(),
242 OnNotificationPostedFromAndroid(data));
243 }
244
245 void ArcBridgeServiceImpl::OnNotificationRemovedFromAndroid(
246 const std::string& key) {
247 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
248 FOR_EACH_OBSERVER(Observer, observer_list(),
249 OnNotificationRemovedFromAndroid(key));
250 }
251
222 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { 252 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) {
223 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 253 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
224 bool handled = true; 254 bool handled = true;
225 255
226 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) 256 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message)
227 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, 257 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase,
228 OnInstanceBootPhase) 258 OnInstanceBootPhase)
259 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationPosted,
260 OnNotificationPostedFromAndroid)
261 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationRemoved,
262 OnNotificationRemovedFromAndroid)
229 IPC_MESSAGE_UNHANDLED(handled = false) 263 IPC_MESSAGE_UNHANDLED(handled = false)
230 IPC_END_MESSAGE_MAP() 264 IPC_END_MESSAGE_MAP()
231 265
232 if (!handled) 266 if (!handled)
233 LOG(ERROR) << "Invalid message with type = " << message.type(); 267 LOG(ERROR) << "Invalid message with type = " << message.type();
234 return handled; 268 return handled;
235 } 269 }
236 270
237 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { 271 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) {
238 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 272 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
239 if (available() == arc_available) 273 if (available() == arc_available)
240 return; 274 return;
241 SetAvailable(arc_available); 275 SetAvailable(arc_available);
242 PrerequisitesChanged(); 276 PrerequisitesChanged();
243 } 277 }
244 278
245 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { 279 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) {
246 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); 280 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread());
247 // STOPPING is the only valid state for this function. 281 // STOPPING is the only valid state for this function.
248 // DCHECK on enum classes not supported. 282 // DCHECK on enum classes not supported.
249 DCHECK(state() == State::STOPPING); 283 DCHECK(state() == State::STOPPING);
250 ipc_channel_.reset(); 284 ipc_channel_.reset();
251 SetState(State::STOPPED); 285 SetState(State::STOPPED);
252 } 286 }
253 287
254 } // namespace arc 288 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698