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

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

Issue 1475583002: Add IPC messages for ARC notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed the 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.h" 5 #include "components/arc/arc_bridge_service.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 base::ScopedFD fd) { 127 base::ScopedFD fd) {
128 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread()); 128 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread());
129 if (state_ != State::READY) { 129 if (state_ != State::READY) {
130 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; 130 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready";
131 return false; 131 return false;
132 } 132 }
133 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( 133 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice(
134 name, device_type, base::FileDescriptor(fd.Pass()))); 134 name, device_type, base::FileDescriptor(fd.Pass())));
135 } 135 }
136 136
137 bool ArcBridgeService::NotifyNotificationEvent(const std::string& key,
elijahtaylor1 2015/11/27 05:42:49 "NotifyNotification" is kind of confusing to put t
yoshiki 2015/11/27 10:48:06 Done.
138 NotificationEvent event) {
139 DCHECK(ipc_task_runner_->RunsTasksOnCurrentThread());
140 if (state_ != State::READY) {
141 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready";
elijahtaylor1 2015/11/27 05:42:49 copy/paste error with RegisterInputDevice Maybe w
yoshiki 2015/11/27 10:48:06 I created a SendMessageIfReady(Message*) method, w
142 return false;
143 }
144 if (key.empty()) {
145 LOG(ERROR) << "NotifyNotificationEvent failed: Wrong parameter";
146 return false;
147 }
148 return ipc_channel_->Send(
149 new ArcInstanceMsg_NotifyNotificationEvent(key, event));
150 }
151
137 void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) { 152 void ArcBridgeService::SocketConnect(const base::FilePath& socket_path) {
138 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 153 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
139 if (state_ != State::STOPPED) { 154 if (state_ != State::STOPPED) {
140 VLOG(1) << "SocketConnect() called when instance is not stopped"; 155 VLOG(1) << "SocketConnect() called when instance is not stopped";
141 return; 156 return;
142 } 157 }
143 SetState(State::CONNECTING); 158 SetState(State::CONNECTING);
144 base::PostTaskAndReplyWithResult( 159 base::PostTaskAndReplyWithResult(
145 file_task_runner_.get(), FROM_HERE, 160 file_task_runner_.get(), FROM_HERE,
146 base::Bind(&base::CreateDirectory, socket_path.DirName()), 161 base::Bind(&base::CreateDirectory, socket_path.DirName()),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 248
234 void ArcBridgeService::OnInstanceReady() { 249 void ArcBridgeService::OnInstanceReady() {
235 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 250 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
236 if (state_ != State::STARTING) { 251 if (state_ != State::STARTING) {
237 VLOG(1) << "StopInstance() called while connecting"; 252 VLOG(1) << "StopInstance() called while connecting";
238 return; 253 return;
239 } 254 }
240 SetState(State::READY); 255 SetState(State::READY);
241 } 256 }
242 257
258 void ArcBridgeService::OnNotificationPosted(
259 const arc::ArcNotificationData& data) {
260 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
261 FOR_EACH_OBSERVER(Observer, observer_list_,
262 OnNotificationPostedFromAndroid(data));
263 }
264
265 void ArcBridgeService::OnNotificationRemoved(const std::string& key) {
266 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
267 FOR_EACH_OBSERVER(Observer, observer_list_,
268 OnNotificationRemovedFromAndroid(key));
269 }
270
243 void ArcBridgeService::SetState(State state) { 271 void ArcBridgeService::SetState(State state) {
244 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 272 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
245 // DCHECK on enum classes not supported. 273 // DCHECK on enum classes not supported.
246 DCHECK(state_ != state); 274 DCHECK(state_ != state);
247 state_ = state; 275 state_ = state;
248 FOR_EACH_OBSERVER(Observer, observer_list_, OnStateChanged(state_)); 276 FOR_EACH_OBSERVER(Observer, observer_list_, OnStateChanged(state_));
249 } 277 }
250 278
251 bool ArcBridgeService::OnMessageReceived(const IPC::Message& message) { 279 bool ArcBridgeService::OnMessageReceived(const IPC::Message& message) {
252 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 280 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
253 bool handled = true; 281 bool handled = true;
254 282
255 IPC_BEGIN_MESSAGE_MAP(ArcBridgeService, message) 283 IPC_BEGIN_MESSAGE_MAP(ArcBridgeService, message)
256 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceReady, OnInstanceReady) 284 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceReady, OnInstanceReady)
285 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationPosted,
286 OnNotificationPosted)
287 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_NotificationRemoved,
288 OnNotificationRemoved)
257 IPC_MESSAGE_UNHANDLED(handled = false) 289 IPC_MESSAGE_UNHANDLED(handled = false)
258 IPC_END_MESSAGE_MAP() 290 IPC_END_MESSAGE_MAP()
259 291
260 if (!handled) 292 if (!handled)
261 LOG(ERROR) << "Invalid message with type = " << message.type(); 293 LOG(ERROR) << "Invalid message with type = " << message.type();
262 return handled; 294 return handled;
263 } 295 }
264 296
265 void ArcBridgeService::OnArcAvailable(bool available) { 297 void ArcBridgeService::OnArcAvailable(bool available) {
266 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 298 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
267 if (available_ == available) 299 if (available_ == available)
268 return; 300 return;
269 available_ = available; 301 available_ = available;
270 FOR_EACH_OBSERVER(Observer, observer_list_, OnAvailableChanged(available_)); 302 FOR_EACH_OBSERVER(Observer, observer_list_, OnAvailableChanged(available_));
271 PrerequisitesChanged(); 303 PrerequisitesChanged();
272 } 304 }
273 305
274 void ArcBridgeService::OnInstanceStopped(bool success) { 306 void ArcBridgeService::OnInstanceStopped(bool success) {
275 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); 307 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
276 // STOPPING is the only valid state for this function. 308 // STOPPING is the only valid state for this function.
277 // DCHECK on enum classes not supported. 309 // DCHECK on enum classes not supported.
278 DCHECK(state_ == State::STOPPING); 310 DCHECK(state_ == State::STOPPING);
279 ipc_channel_.reset(); 311 ipc_channel_.reset();
280 SetState(State::STOPPED); 312 SetState(State::STOPPED);
281 } 313 }
282 314
283 } // namespace arc 315 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698