Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 if (state() != State::READY) { |
| 104 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; | 104 LOG(ERROR) << "Called RegisterInputDevice when the service is not ready"; |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( | 107 return ipc_channel_->Send(new ArcInstanceMsg_RegisterInputDevice( |
| 108 name, device_type, base::FileDescriptor(fd.Pass()))); | 108 name, device_type, base::FileDescriptor(fd.Pass()))); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool ArcBridgeServiceImpl::RefreshApps() { | |
| 112 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | |
| 113 if (state() != State::READY) { | |
| 114 LOG(ERROR) << "Called RefreshApps when the service is not ready"; | |
| 115 return false; | |
| 116 } | |
| 117 return ipc_channel_->Send(new ArcInstanceMsg_RefreshApps()); | |
| 118 } | |
| 119 | |
| 120 bool ArcBridgeServiceImpl::LaunchApp(const std::string& package, | |
| 121 const std::string& activity) { | |
| 122 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | |
| 123 if (state() != State::READY) { | |
| 124 LOG(ERROR) << "Called LaunchApp when the service is not ready"; | |
| 125 return false; | |
| 126 } | |
| 127 | |
|
hidehiko
2015/12/01 08:18:25
nit: no empty line please, for consistency.
khmel1
2015/12/01 09:49:32
Done.
| |
| 128 return ipc_channel_->Send(new ArcInstanceMsg_LaunchApp(package, activity)); | |
| 129 } | |
| 130 | |
| 131 bool ArcBridgeServiceImpl::RequestIcon(const std::string& package, | |
| 132 const std::string& activity, | |
| 133 int scale_factor) { | |
| 134 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | |
| 135 if (state() != State::READY) { | |
| 136 LOG(ERROR) << "Called RequestIcon when the service is not ready"; | |
| 137 return false; | |
| 138 } | |
| 139 return ipc_channel_->Send(new ArcInstanceMsg_RequestIcon(package, | |
| 140 activity, | |
| 141 scale_factor)); | |
| 142 } | |
| 143 | |
| 111 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) { | 144 void ArcBridgeServiceImpl::SocketConnect(const base::FilePath& socket_path) { |
| 112 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 145 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 113 if (state() != State::STOPPED) { | 146 if (state() != State::STOPPED) { |
| 114 VLOG(1) << "SocketConnect() called when instance is not stopped"; | 147 VLOG(1) << "SocketConnect() called when instance is not stopped"; |
| 115 return; | 148 return; |
| 116 } | 149 } |
| 117 SetState(State::CONNECTING); | 150 SetState(State::CONNECTING); |
| 118 base::PostTaskAndReplyWithResult( | 151 base::PostTaskAndReplyWithResult( |
| 119 file_task_runner_.get(), FROM_HERE, | 152 file_task_runner_.get(), FROM_HERE, |
| 120 base::Bind(&base::CreateDirectory, socket_path.DirName()), | 153 base::Bind(&base::CreateDirectory, socket_path.DirName()), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); | 252 FOR_EACH_OBSERVER(Observer, observer_list(), OnInstanceBootPhase(phase)); |
| 220 } | 253 } |
| 221 | 254 |
| 222 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { | 255 bool ArcBridgeServiceImpl::OnMessageReceived(const IPC::Message& message) { |
| 223 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 256 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 224 bool handled = true; | 257 bool handled = true; |
| 225 | 258 |
| 226 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) | 259 IPC_BEGIN_MESSAGE_MAP(ArcBridgeServiceImpl, message) |
| 227 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, | 260 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_InstanceBootPhase, |
| 228 OnInstanceBootPhase) | 261 OnInstanceBootPhase) |
| 262 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppsRefreshed, OnAppsRefreshed) | |
| 263 IPC_MESSAGE_HANDLER(ArcInstanceHostMsg_AppIcon, OnAppIcon) | |
| 229 IPC_MESSAGE_UNHANDLED(handled = false) | 264 IPC_MESSAGE_UNHANDLED(handled = false) |
| 230 IPC_END_MESSAGE_MAP() | 265 IPC_END_MESSAGE_MAP() |
| 231 | 266 |
| 232 if (!handled) | 267 if (!handled) |
| 233 LOG(ERROR) << "Invalid message with type = " << message.type(); | 268 LOG(ERROR) << "Invalid message with type = " << message.type(); |
| 234 return handled; | 269 return handled; |
| 235 } | 270 } |
| 236 | 271 |
| 272 void ArcBridgeServiceImpl::OnAppsRefreshed( | |
| 273 const std::vector<arc::AppInfo>& apps) { | |
| 274 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | |
| 275 FOR_EACH_OBSERVER(AppsObserver, apps_observer_list(), OnAppsRefreshed(apps)); | |
| 276 } | |
| 277 | |
| 278 void ArcBridgeServiceImpl::OnAppIcon(const std::string& package, | |
| 279 const std::string& activity, | |
| 280 int scale_factor, | |
| 281 const std::vector<uint8_t>& icon_png_data) { | |
| 282 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | |
| 283 FOR_EACH_OBSERVER(AppsObserver, | |
| 284 apps_observer_list(), | |
| 285 OnAppIcon(package, activity, scale_factor, icon_png_data)); | |
| 286 } | |
| 287 | |
| 237 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { | 288 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { |
| 238 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 289 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 239 if (available() == arc_available) | 290 if (available() == arc_available) |
| 240 return; | 291 return; |
| 241 SetAvailable(arc_available); | 292 SetAvailable(arc_available); |
| 242 PrerequisitesChanged(); | 293 PrerequisitesChanged(); |
| 243 } | 294 } |
| 244 | 295 |
| 245 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { | 296 void ArcBridgeServiceImpl::OnInstanceStopped(bool success) { |
| 246 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); | 297 DCHECK(origin_task_runner()->RunsTasksOnCurrentThread()); |
| 247 // STOPPING is the only valid state for this function. | 298 // STOPPING is the only valid state for this function. |
| 248 // DCHECK on enum classes not supported. | 299 // DCHECK on enum classes not supported. |
| 249 DCHECK(state() == State::STOPPING); | 300 DCHECK(state() == State::STOPPING); |
| 250 ipc_channel_.reset(); | 301 ipc_channel_.reset(); |
| 251 SetState(State::STOPPED); | 302 SetState(State::STOPPED); |
| 252 } | 303 } |
| 253 | 304 |
| 254 } // namespace arc | 305 } // namespace arc |
| OLD | NEW |