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