| 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.h" | 5 #include "components/arc/arc_bridge_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { | 41 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { |
| 42 return command_line->HasSwitch(chromeos::switches::kEnableArc); | 42 return command_line->HasSwitch(chromeos::switches::kEnableArc); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ArcBridgeService::AddObserver(Observer* observer) { | 45 void ArcBridgeService::AddObserver(Observer* observer) { |
| 46 DCHECK(CalledOnValidThread()); | 46 DCHECK(CalledOnValidThread()); |
| 47 observer_list_.AddObserver(observer); | 47 observer_list_.AddObserver(observer); |
| 48 | |
| 49 // If any of the instances were ready before the call to AddObserver(), the | |
| 50 // |observer| won't get any readiness events. For such cases, we have to call | |
| 51 // them explicitly now to avoid a race. | |
| 52 if (app_instance()) | |
| 53 observer->OnAppInstanceReady(); | |
| 54 if (audio_instance()) | |
| 55 observer->OnAudioInstanceReady(); | |
| 56 if (auth_instance()) | |
| 57 observer->OnAuthInstanceReady(); | |
| 58 if (bluetooth_instance()) | |
| 59 observer->OnBluetoothInstanceReady(); | |
| 60 if (clipboard_instance()) | |
| 61 observer->OnClipboardInstanceReady(); | |
| 62 if (crash_collector_instance()) | |
| 63 observer->OnCrashCollectorInstanceReady(); | |
| 64 if (file_system_instance()) | |
| 65 observer->OnFileSystemInstanceReady(); | |
| 66 if (ime_instance()) | |
| 67 observer->OnImeInstanceReady(); | |
| 68 if (metrics_instance()) | |
| 69 observer->OnMetricsInstanceReady(); | |
| 70 if (net_instance()) | |
| 71 observer->OnNetInstanceReady(); | |
| 72 if (notifications_instance()) | |
| 73 observer->OnNotificationsInstanceReady(); | |
| 74 if (obb_mounter_instance()) | |
| 75 observer->OnObbMounterInstanceReady(); | |
| 76 if (policy_instance()) | |
| 77 observer->OnPolicyInstanceReady(); | |
| 78 if (power_instance()) | |
| 79 observer->OnPowerInstanceReady(); | |
| 80 if (process_instance()) | |
| 81 observer->OnProcessInstanceReady(); | |
| 82 if (storage_manager_instance()) | |
| 83 observer->OnStorageManagerInstanceReady(); | |
| 84 if (video_instance()) | |
| 85 observer->OnVideoInstanceReady(); | |
| 86 if (window_manager_instance()) | |
| 87 observer->OnWindowManagerInstanceReady(); | |
| 88 } | 48 } |
| 89 | 49 |
| 90 void ArcBridgeService::RemoveObserver(Observer* observer) { | 50 void ArcBridgeService::RemoveObserver(Observer* observer) { |
| 91 DCHECK(CalledOnValidThread()); | 51 DCHECK(CalledOnValidThread()); |
| 92 observer_list_.RemoveObserver(observer); | 52 observer_list_.RemoveObserver(observer); |
| 93 } | 53 } |
| 94 | 54 |
| 95 void ArcBridgeService::OnAppInstanceReady(mojom::AppInstancePtr app_ptr) { | 55 void ArcBridgeService::OnAppInstanceReady(mojom::AppInstancePtr app_ptr) { |
| 96 DCHECK(CalledOnValidThread()); | 56 DCHECK(CalledOnValidThread()); |
| 97 temporary_app_ptr_ = std::move(app_ptr); | 57 app_.OnInstanceReady(std::move(app_ptr)); |
| 98 temporary_app_ptr_.QueryVersion(base::Bind( | |
| 99 &ArcBridgeService::OnAppVersionReady, weak_factory_.GetWeakPtr())); | |
| 100 } | |
| 101 | |
| 102 void ArcBridgeService::OnAppVersionReady(uint32_t version) { | |
| 103 DCHECK(CalledOnValidThread()); | |
| 104 app_ptr_ = std::move(temporary_app_ptr_); | |
| 105 app_ptr_.set_connection_error_handler(base::Bind( | |
| 106 &ArcBridgeService::CloseAppChannel, weak_factory_.GetWeakPtr())); | |
| 107 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceReady()); | |
| 108 } | |
| 109 | |
| 110 void ArcBridgeService::CloseAppChannel() { | |
| 111 DCHECK(CalledOnValidThread()); | |
| 112 if (!app_ptr_) | |
| 113 return; | |
| 114 | |
| 115 app_ptr_.reset(); | |
| 116 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); | |
| 117 } | 58 } |
| 118 | 59 |
| 119 void ArcBridgeService::OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) { | 60 void ArcBridgeService::OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) { |
| 120 DCHECK(CalledOnValidThread()); | 61 DCHECK(CalledOnValidThread()); |
| 121 temporary_audio_ptr_ = std::move(audio_ptr); | 62 audio_.OnInstanceReady(std::move(audio_ptr)); |
| 122 temporary_audio_ptr_.QueryVersion(base::Bind( | |
| 123 &ArcBridgeService::OnAudioVersionReady, weak_factory_.GetWeakPtr())); | |
| 124 } | |
| 125 | |
| 126 void ArcBridgeService::OnAudioVersionReady(uint32_t version) { | |
| 127 DCHECK(CalledOnValidThread()); | |
| 128 audio_ptr_ = std::move(temporary_audio_ptr_); | |
| 129 audio_ptr_.set_connection_error_handler(base::Bind( | |
| 130 &ArcBridgeService::CloseAudioChannel, weak_factory_.GetWeakPtr())); | |
| 131 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceReady()); | |
| 132 } | |
| 133 | |
| 134 void ArcBridgeService::CloseAudioChannel() { | |
| 135 if (!audio_ptr_) | |
| 136 return; | |
| 137 | |
| 138 audio_ptr_.reset(); | |
| 139 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceClosed()); | |
| 140 } | 63 } |
| 141 | 64 |
| 142 void ArcBridgeService::OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) { | 65 void ArcBridgeService::OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) { |
| 143 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
| 144 temporary_auth_ptr_ = std::move(auth_ptr); | 67 auth_.OnInstanceReady(std::move(auth_ptr)); |
| 145 temporary_auth_ptr_.QueryVersion(base::Bind( | |
| 146 &ArcBridgeService::OnAuthVersionReady, weak_factory_.GetWeakPtr())); | |
| 147 } | |
| 148 | |
| 149 void ArcBridgeService::OnAuthVersionReady(uint32_t version) { | |
| 150 DCHECK(CalledOnValidThread()); | |
| 151 auth_ptr_ = std::move(temporary_auth_ptr_); | |
| 152 auth_ptr_.set_connection_error_handler(base::Bind( | |
| 153 &ArcBridgeService::CloseAuthChannel, weak_factory_.GetWeakPtr())); | |
| 154 FOR_EACH_OBSERVER(Observer, observer_list(), OnAuthInstanceReady()); | |
| 155 } | |
| 156 | |
| 157 void ArcBridgeService::CloseAuthChannel() { | |
| 158 DCHECK(CalledOnValidThread()); | |
| 159 if (!auth_ptr_) | |
| 160 return; | |
| 161 | |
| 162 auth_ptr_.reset(); | |
| 163 FOR_EACH_OBSERVER(Observer, observer_list(), OnAuthInstanceClosed()); | |
| 164 } | 68 } |
| 165 | 69 |
| 166 void ArcBridgeService::OnBluetoothInstanceReady( | 70 void ArcBridgeService::OnBluetoothInstanceReady( |
| 167 mojom::BluetoothInstancePtr bluetooth_ptr) { | 71 mojom::BluetoothInstancePtr bluetooth_ptr) { |
| 168 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 169 temporary_bluetooth_ptr_ = std::move(bluetooth_ptr); | 73 bluetooth_.OnInstanceReady(std::move(bluetooth_ptr)); |
| 170 temporary_bluetooth_ptr_.QueryVersion(base::Bind( | |
| 171 &ArcBridgeService::OnBluetoothVersionReady, weak_factory_.GetWeakPtr())); | |
| 172 } | |
| 173 | |
| 174 void ArcBridgeService::OnBluetoothVersionReady(uint32_t version) { | |
| 175 DCHECK(CalledOnValidThread()); | |
| 176 bluetooth_ptr_ = std::move(temporary_bluetooth_ptr_); | |
| 177 bluetooth_ptr_.set_connection_error_handler(base::Bind( | |
| 178 &ArcBridgeService::CloseBluetoothChannel, weak_factory_.GetWeakPtr())); | |
| 179 FOR_EACH_OBSERVER(Observer, observer_list(), OnBluetoothInstanceReady()); | |
| 180 } | |
| 181 | |
| 182 void ArcBridgeService::CloseBluetoothChannel() { | |
| 183 DCHECK(CalledOnValidThread()); | |
| 184 if (!bluetooth_ptr_) | |
| 185 return; | |
| 186 | |
| 187 bluetooth_ptr_.reset(); | |
| 188 FOR_EACH_OBSERVER(Observer, observer_list(), OnBluetoothInstanceClosed()); | |
| 189 } | 74 } |
| 190 | 75 |
| 191 void ArcBridgeService::OnClipboardInstanceReady( | 76 void ArcBridgeService::OnClipboardInstanceReady( |
| 192 mojom::ClipboardInstancePtr clipboard_ptr) { | 77 mojom::ClipboardInstancePtr clipboard_ptr) { |
| 193 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
| 194 temporary_clipboard_ptr_ = std::move(clipboard_ptr); | 79 clipboard_.OnInstanceReady(std::move(clipboard_ptr)); |
| 195 temporary_clipboard_ptr_.QueryVersion(base::Bind( | |
| 196 &ArcBridgeService::OnClipboardVersionReady, weak_factory_.GetWeakPtr())); | |
| 197 } | |
| 198 | |
| 199 void ArcBridgeService::OnClipboardVersionReady(uint32_t version) { | |
| 200 DCHECK(CalledOnValidThread()); | |
| 201 clipboard_ptr_ = std::move(temporary_clipboard_ptr_); | |
| 202 clipboard_ptr_.set_connection_error_handler(base::Bind( | |
| 203 &ArcBridgeService::CloseClipboardChannel, weak_factory_.GetWeakPtr())); | |
| 204 FOR_EACH_OBSERVER(Observer, observer_list(), OnClipboardInstanceReady()); | |
| 205 } | |
| 206 | |
| 207 void ArcBridgeService::CloseClipboardChannel() { | |
| 208 DCHECK(CalledOnValidThread()); | |
| 209 if (!clipboard_ptr_) | |
| 210 return; | |
| 211 | |
| 212 clipboard_ptr_.reset(); | |
| 213 FOR_EACH_OBSERVER(Observer, observer_list(), OnClipboardInstanceClosed()); | |
| 214 } | 80 } |
| 215 | 81 |
| 216 void ArcBridgeService::OnCrashCollectorInstanceReady( | 82 void ArcBridgeService::OnCrashCollectorInstanceReady( |
| 217 mojom::CrashCollectorInstancePtr crash_collector_ptr) { | 83 mojom::CrashCollectorInstancePtr crash_collector_ptr) { |
| 218 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
| 219 temporary_crash_collector_ptr_ = std::move(crash_collector_ptr); | 85 crash_collector_.OnInstanceReady(std::move(crash_collector_ptr)); |
| 220 temporary_crash_collector_ptr_.QueryVersion( | |
| 221 base::Bind(&ArcBridgeService::OnCrashCollectorVersionReady, | |
| 222 weak_factory_.GetWeakPtr())); | |
| 223 } | |
| 224 | |
| 225 void ArcBridgeService::OnCrashCollectorVersionReady(uint32_t version) { | |
| 226 DCHECK(CalledOnValidThread()); | |
| 227 crash_collector_ptr_ = std::move(temporary_crash_collector_ptr_); | |
| 228 crash_collector_ptr_.set_connection_error_handler( | |
| 229 base::Bind(&ArcBridgeService::CloseCrashCollectorChannel, | |
| 230 weak_factory_.GetWeakPtr())); | |
| 231 FOR_EACH_OBSERVER(Observer, observer_list(), OnCrashCollectorInstanceReady()); | |
| 232 } | |
| 233 | |
| 234 void ArcBridgeService::CloseCrashCollectorChannel() { | |
| 235 DCHECK(CalledOnValidThread()); | |
| 236 if (!crash_collector_ptr_) | |
| 237 return; | |
| 238 | |
| 239 crash_collector_ptr_.reset(); | |
| 240 FOR_EACH_OBSERVER(Observer, observer_list(), | |
| 241 OnCrashCollectorInstanceClosed()); | |
| 242 } | 86 } |
| 243 | 87 |
| 244 void ArcBridgeService::OnFileSystemInstanceReady( | 88 void ArcBridgeService::OnFileSystemInstanceReady( |
| 245 mojom::FileSystemInstancePtr file_system_ptr) { | 89 mojom::FileSystemInstancePtr file_system_ptr) { |
| 246 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 247 temporary_file_system_ptr_ = std::move(file_system_ptr); | 91 file_system_.OnInstanceReady(std::move(file_system_ptr)); |
| 248 temporary_file_system_ptr_.QueryVersion( | |
| 249 base::Bind(&ArcBridgeService::OnFileSystemVersionReady, | |
| 250 weak_factory_.GetWeakPtr())); | |
| 251 } | |
| 252 | |
| 253 void ArcBridgeService::OnFileSystemVersionReady(uint32_t version) { | |
| 254 DCHECK(CalledOnValidThread()); | |
| 255 file_system_ptr_ = std::move(temporary_file_system_ptr_); | |
| 256 file_system_ptr_.set_connection_error_handler( | |
| 257 base::Bind(&ArcBridgeService::CloseFileSystemChannel, | |
| 258 weak_factory_.GetWeakPtr())); | |
| 259 FOR_EACH_OBSERVER(Observer, observer_list(), OnFileSystemInstanceReady()); | |
| 260 } | |
| 261 | |
| 262 void ArcBridgeService::CloseFileSystemChannel() { | |
| 263 DCHECK(CalledOnValidThread()); | |
| 264 if (!file_system_ptr_) | |
| 265 return; | |
| 266 | |
| 267 file_system_ptr_.reset(); | |
| 268 FOR_EACH_OBSERVER(Observer, observer_list(), | |
| 269 OnFileSystemInstanceClosed()); | |
| 270 } | 92 } |
| 271 | 93 |
| 272 void ArcBridgeService::OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) { | 94 void ArcBridgeService::OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) { |
| 273 DCHECK(CalledOnValidThread()); | 95 DCHECK(CalledOnValidThread()); |
| 274 temporary_ime_ptr_ = std::move(ime_ptr); | 96 ime_.OnInstanceReady(std::move(ime_ptr)); |
| 275 temporary_ime_ptr_.QueryVersion(base::Bind( | |
| 276 &ArcBridgeService::OnImeVersionReady, weak_factory_.GetWeakPtr())); | |
| 277 } | |
| 278 | |
| 279 void ArcBridgeService::OnImeVersionReady(uint32_t version) { | |
| 280 DCHECK(CalledOnValidThread()); | |
| 281 ime_ptr_ = std::move(temporary_ime_ptr_); | |
| 282 ime_ptr_.set_connection_error_handler(base::Bind( | |
| 283 &ArcBridgeService::CloseImeChannel, weak_factory_.GetWeakPtr())); | |
| 284 FOR_EACH_OBSERVER(Observer, observer_list(), OnImeInstanceReady()); | |
| 285 } | |
| 286 | |
| 287 void ArcBridgeService::CloseImeChannel() { | |
| 288 DCHECK(CalledOnValidThread()); | |
| 289 if (!ime_ptr_) | |
| 290 return; | |
| 291 | |
| 292 ime_ptr_.reset(); | |
| 293 FOR_EACH_OBSERVER(Observer, observer_list(), OnImeInstanceClosed()); | |
| 294 } | 97 } |
| 295 | 98 |
| 296 void ArcBridgeService::OnIntentHelperInstanceReady( | 99 void ArcBridgeService::OnIntentHelperInstanceReady( |
| 297 mojom::IntentHelperInstancePtr intent_helper_ptr) { | 100 mojom::IntentHelperInstancePtr intent_helper_ptr) { |
| 298 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 299 temporary_intent_helper_ptr_ = std::move(intent_helper_ptr); | 102 intent_helper_.OnInstanceReady(std::move(intent_helper_ptr)); |
| 300 temporary_intent_helper_ptr_.QueryVersion( | |
| 301 base::Bind(&ArcBridgeService::OnIntentHelperVersionReady, | |
| 302 weak_factory_.GetWeakPtr())); | |
| 303 } | |
| 304 | |
| 305 void ArcBridgeService::OnIntentHelperVersionReady(uint32_t version) { | |
| 306 DCHECK(CalledOnValidThread()); | |
| 307 intent_helper_ptr_ = std::move(temporary_intent_helper_ptr_); | |
| 308 intent_helper_ptr_.set_connection_error_handler(base::Bind( | |
| 309 &ArcBridgeService::CloseIntentHelperChannel, weak_factory_.GetWeakPtr())); | |
| 310 FOR_EACH_OBSERVER(Observer, observer_list(), OnIntentHelperInstanceReady()); | |
| 311 } | |
| 312 | |
| 313 void ArcBridgeService::CloseIntentHelperChannel() { | |
| 314 DCHECK(CalledOnValidThread()); | |
| 315 if (!intent_helper_ptr_) | |
| 316 return; | |
| 317 | |
| 318 intent_helper_ptr_.reset(); | |
| 319 FOR_EACH_OBSERVER(Observer, observer_list(), OnIntentHelperInstanceClosed()); | |
| 320 } | 103 } |
| 321 | 104 |
| 322 void ArcBridgeService::OnMetricsInstanceReady( | 105 void ArcBridgeService::OnMetricsInstanceReady( |
| 323 mojom::MetricsInstancePtr metrics_ptr) { | 106 mojom::MetricsInstancePtr metrics_ptr) { |
| 324 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 325 temporary_metrics_ptr_ = std::move(metrics_ptr); | 108 metrics_.OnInstanceReady(std::move(metrics_ptr)); |
| 326 temporary_metrics_ptr_.QueryVersion(base::Bind( | |
| 327 &ArcBridgeService::OnMetricsVersionReady, weak_factory_.GetWeakPtr())); | |
| 328 } | |
| 329 | |
| 330 void ArcBridgeService::OnMetricsVersionReady(uint32_t version) { | |
| 331 DCHECK(CalledOnValidThread()); | |
| 332 metrics_ptr_ = std::move(temporary_metrics_ptr_); | |
| 333 metrics_ptr_.set_connection_error_handler(base::Bind( | |
| 334 &ArcBridgeService::CloseMetricsChannel, weak_factory_.GetWeakPtr())); | |
| 335 FOR_EACH_OBSERVER(Observer, observer_list(), OnMetricsInstanceReady()); | |
| 336 } | |
| 337 | |
| 338 void ArcBridgeService::CloseMetricsChannel() { | |
| 339 DCHECK(CalledOnValidThread()); | |
| 340 if (!metrics_ptr_) | |
| 341 return; | |
| 342 | |
| 343 metrics_ptr_.reset(); | |
| 344 FOR_EACH_OBSERVER(Observer, observer_list(), OnMetricsInstanceClosed()); | |
| 345 } | 109 } |
| 346 | 110 |
| 347 void ArcBridgeService::OnNetInstanceReady(mojom::NetInstancePtr net_ptr) { | 111 void ArcBridgeService::OnNetInstanceReady(mojom::NetInstancePtr net_ptr) { |
| 348 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
| 349 temporary_net_ptr_ = std::move(net_ptr); | 113 net_.OnInstanceReady(std::move(net_ptr)); |
| 350 temporary_net_ptr_.QueryVersion(base::Bind( | |
| 351 &ArcBridgeService::OnNetVersionReady, weak_factory_.GetWeakPtr())); | |
| 352 } | |
| 353 | |
| 354 void ArcBridgeService::OnNetVersionReady(uint32_t version) { | |
| 355 DCHECK(CalledOnValidThread()); | |
| 356 net_ptr_ = std::move(temporary_net_ptr_); | |
| 357 net_ptr_.set_connection_error_handler(base::Bind( | |
| 358 &ArcBridgeService::CloseNetChannel, weak_factory_.GetWeakPtr())); | |
| 359 FOR_EACH_OBSERVER(Observer, observer_list(), OnNetInstanceReady()); | |
| 360 } | |
| 361 | |
| 362 void ArcBridgeService::CloseNetChannel() { | |
| 363 DCHECK(CalledOnValidThread()); | |
| 364 if (!net_ptr_) | |
| 365 return; | |
| 366 | |
| 367 net_ptr_.reset(); | |
| 368 FOR_EACH_OBSERVER(Observer, observer_list(), OnNetInstanceClosed()); | |
| 369 } | 114 } |
| 370 | 115 |
| 371 void ArcBridgeService::OnNotificationsInstanceReady( | 116 void ArcBridgeService::OnNotificationsInstanceReady( |
| 372 mojom::NotificationsInstancePtr notifications_ptr) { | 117 mojom::NotificationsInstancePtr notifications_ptr) { |
| 373 DCHECK(CalledOnValidThread()); | 118 DCHECK(CalledOnValidThread()); |
| 374 temporary_notifications_ptr_ = std::move(notifications_ptr); | 119 notifications_.OnInstanceReady(std::move(notifications_ptr)); |
| 375 temporary_notifications_ptr_.QueryVersion( | |
| 376 base::Bind(&ArcBridgeService::OnNotificationsVersionReady, | |
| 377 weak_factory_.GetWeakPtr())); | |
| 378 } | |
| 379 | |
| 380 void ArcBridgeService::OnNotificationsVersionReady(uint32_t version) { | |
| 381 DCHECK(CalledOnValidThread()); | |
| 382 notifications_ptr_ = std::move(temporary_notifications_ptr_); | |
| 383 notifications_ptr_.set_connection_error_handler( | |
| 384 base::Bind(&ArcBridgeService::CloseNotificationsChannel, | |
| 385 weak_factory_.GetWeakPtr())); | |
| 386 FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceReady()); | |
| 387 } | |
| 388 | |
| 389 void ArcBridgeService::CloseNotificationsChannel() { | |
| 390 DCHECK(CalledOnValidThread()); | |
| 391 if (!notifications_ptr_) | |
| 392 return; | |
| 393 | |
| 394 notifications_ptr_.reset(); | |
| 395 FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceClosed()); | |
| 396 } | 120 } |
| 397 | 121 |
| 398 void ArcBridgeService::OnObbMounterInstanceReady( | 122 void ArcBridgeService::OnObbMounterInstanceReady( |
| 399 mojom::ObbMounterInstancePtr obb_mounter_ptr) { | 123 mojom::ObbMounterInstancePtr obb_mounter_ptr) { |
| 400 DCHECK(CalledOnValidThread()); | 124 DCHECK(CalledOnValidThread()); |
| 401 temporary_obb_mounter_ptr_ = std::move(obb_mounter_ptr); | 125 obb_mounter_.OnInstanceReady(std::move(obb_mounter_ptr)); |
| 402 temporary_obb_mounter_ptr_.QueryVersion(base::Bind( | |
| 403 &ArcBridgeService::OnObbMounterVersionReady, | |
| 404 weak_factory_.GetWeakPtr())); | |
| 405 } | |
| 406 | |
| 407 void ArcBridgeService::OnObbMounterVersionReady(uint32_t version) { | |
| 408 DCHECK(CalledOnValidThread()); | |
| 409 obb_mounter_ptr_ = std::move(temporary_obb_mounter_ptr_); | |
| 410 obb_mounter_ptr_.set_connection_error_handler(base::Bind( | |
| 411 &ArcBridgeService::CloseObbMounterChannel, | |
| 412 weak_factory_.GetWeakPtr())); | |
| 413 FOR_EACH_OBSERVER(Observer, observer_list(), OnObbMounterInstanceReady()); | |
| 414 } | |
| 415 | |
| 416 void ArcBridgeService::CloseObbMounterChannel() { | |
| 417 if (!obb_mounter_ptr_) | |
| 418 return; | |
| 419 | |
| 420 obb_mounter_ptr_.reset(); | |
| 421 FOR_EACH_OBSERVER(Observer, observer_list(), OnObbMounterInstanceClosed()); | |
| 422 } | 126 } |
| 423 | 127 |
| 424 void ArcBridgeService::OnPolicyInstanceReady( | 128 void ArcBridgeService::OnPolicyInstanceReady( |
| 425 mojom::PolicyInstancePtr policy_ptr) { | 129 mojom::PolicyInstancePtr policy_ptr) { |
| 426 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
| 427 temporary_policy_ptr_ = std::move(policy_ptr); | 131 policy_.OnInstanceReady(std::move(policy_ptr)); |
| 428 temporary_policy_ptr_.QueryVersion(base::Bind( | |
| 429 &ArcBridgeService::OnPolicyVersionReady, weak_factory_.GetWeakPtr())); | |
| 430 } | |
| 431 | |
| 432 void ArcBridgeService::OnPolicyVersionReady(uint32_t version) { | |
| 433 DCHECK(CalledOnValidThread()); | |
| 434 policy_ptr_ = std::move(temporary_policy_ptr_); | |
| 435 policy_ptr_.set_connection_error_handler(base::Bind( | |
| 436 &ArcBridgeService::ClosePolicyChannel, weak_factory_.GetWeakPtr())); | |
| 437 FOR_EACH_OBSERVER(Observer, observer_list(), OnPolicyInstanceReady()); | |
| 438 } | |
| 439 | |
| 440 void ArcBridgeService::ClosePolicyChannel() { | |
| 441 DCHECK(CalledOnValidThread()); | |
| 442 if (!policy_ptr_) | |
| 443 return; | |
| 444 | |
| 445 policy_ptr_.reset(); | |
| 446 FOR_EACH_OBSERVER(Observer, observer_list(), OnPolicyInstanceClosed()); | |
| 447 } | 132 } |
| 448 | 133 |
| 449 void ArcBridgeService::OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) { | 134 void ArcBridgeService::OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) { |
| 450 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 451 temporary_power_ptr_ = std::move(power_ptr); | 136 power_.OnInstanceReady(std::move(power_ptr)); |
| 452 temporary_power_ptr_.QueryVersion(base::Bind( | |
| 453 &ArcBridgeService::OnPowerVersionReady, weak_factory_.GetWeakPtr())); | |
| 454 } | |
| 455 | |
| 456 void ArcBridgeService::OnPowerVersionReady(uint32_t version) { | |
| 457 DCHECK(CalledOnValidThread()); | |
| 458 power_ptr_ = std::move(temporary_power_ptr_); | |
| 459 power_ptr_.set_connection_error_handler(base::Bind( | |
| 460 &ArcBridgeService::ClosePowerChannel, weak_factory_.GetWeakPtr())); | |
| 461 FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceReady()); | |
| 462 } | |
| 463 | |
| 464 void ArcBridgeService::ClosePowerChannel() { | |
| 465 DCHECK(CalledOnValidThread()); | |
| 466 if (!power_ptr_) | |
| 467 return; | |
| 468 | |
| 469 power_ptr_.reset(); | |
| 470 FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceClosed()); | |
| 471 } | 137 } |
| 472 | 138 |
| 473 void ArcBridgeService::OnProcessInstanceReady( | 139 void ArcBridgeService::OnProcessInstanceReady( |
| 474 mojom::ProcessInstancePtr process_ptr) { | 140 mojom::ProcessInstancePtr process_ptr) { |
| 475 DCHECK(CalledOnValidThread()); | 141 DCHECK(CalledOnValidThread()); |
| 476 temporary_process_ptr_ = std::move(process_ptr); | 142 process_.OnInstanceReady(std::move(process_ptr)); |
| 477 temporary_process_ptr_.QueryVersion(base::Bind( | |
| 478 &ArcBridgeService::OnProcessVersionReady, weak_factory_.GetWeakPtr())); | |
| 479 } | |
| 480 | |
| 481 void ArcBridgeService::OnProcessVersionReady(uint32_t version) { | |
| 482 DCHECK(CalledOnValidThread()); | |
| 483 process_ptr_ = std::move(temporary_process_ptr_); | |
| 484 process_ptr_.set_connection_error_handler(base::Bind( | |
| 485 &ArcBridgeService::CloseProcessChannel, weak_factory_.GetWeakPtr())); | |
| 486 FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessInstanceReady()); | |
| 487 } | |
| 488 | |
| 489 void ArcBridgeService::CloseProcessChannel() { | |
| 490 DCHECK(CalledOnValidThread()); | |
| 491 if (!process_ptr_) | |
| 492 return; | |
| 493 | |
| 494 process_ptr_.reset(); | |
| 495 FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessInstanceClosed()); | |
| 496 } | 143 } |
| 497 | 144 |
| 498 void ArcBridgeService::OnStorageManagerInstanceReady( | 145 void ArcBridgeService::OnStorageManagerInstanceReady( |
| 499 mojom::StorageManagerInstancePtr storage_manager_ptr) { | 146 mojom::StorageManagerInstancePtr storage_manager_ptr) { |
| 500 DCHECK(CalledOnValidThread()); | 147 DCHECK(CalledOnValidThread()); |
| 501 temporary_storage_manager_ptr_ = std::move(storage_manager_ptr); | 148 storage_manager_.OnInstanceReady(std::move(storage_manager_ptr)); |
| 502 temporary_storage_manager_ptr_.QueryVersion(base::Bind( | |
| 503 &ArcBridgeService::OnStorageManagerVersionReady, | |
| 504 weak_factory_.GetWeakPtr())); | |
| 505 } | |
| 506 | |
| 507 void ArcBridgeService::OnStorageManagerVersionReady(uint32_t version) { | |
| 508 DCHECK(CalledOnValidThread()); | |
| 509 storage_manager_ptr_ = std::move(temporary_storage_manager_ptr_); | |
| 510 storage_manager_ptr_.set_connection_error_handler(base::Bind( | |
| 511 &ArcBridgeService::CloseStorageManagerChannel, | |
| 512 weak_factory_.GetWeakPtr())); | |
| 513 FOR_EACH_OBSERVER( | |
| 514 Observer, observer_list(), OnStorageManagerInstanceReady()); | |
| 515 } | |
| 516 | |
| 517 void ArcBridgeService::CloseStorageManagerChannel() { | |
| 518 DCHECK(CalledOnValidThread()); | |
| 519 if (!storage_manager_ptr_) | |
| 520 return; | |
| 521 | |
| 522 storage_manager_ptr_.reset(); | |
| 523 FOR_EACH_OBSERVER( | |
| 524 Observer, observer_list(), OnStorageManagerInstanceClosed()); | |
| 525 } | 149 } |
| 526 | 150 |
| 527 void ArcBridgeService::OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) { | 151 void ArcBridgeService::OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) { |
| 528 DCHECK(CalledOnValidThread()); | 152 DCHECK(CalledOnValidThread()); |
| 529 temporary_video_ptr_ = std::move(video_ptr); | 153 video_.OnInstanceReady(std::move(video_ptr)); |
| 530 temporary_video_ptr_.QueryVersion(base::Bind( | |
| 531 &ArcBridgeService::OnVideoVersionReady, weak_factory_.GetWeakPtr())); | |
| 532 } | |
| 533 | |
| 534 void ArcBridgeService::OnVideoVersionReady(uint32_t version) { | |
| 535 DCHECK(CalledOnValidThread()); | |
| 536 video_ptr_ = std::move(temporary_video_ptr_); | |
| 537 video_ptr_.set_connection_error_handler(base::Bind( | |
| 538 &ArcBridgeService::CloseVideoChannel, weak_factory_.GetWeakPtr())); | |
| 539 FOR_EACH_OBSERVER(Observer, observer_list(), OnVideoInstanceReady()); | |
| 540 } | |
| 541 | |
| 542 void ArcBridgeService::CloseVideoChannel() { | |
| 543 DCHECK(CalledOnValidThread()); | |
| 544 if (!video_ptr_) | |
| 545 return; | |
| 546 | |
| 547 video_ptr_.reset(); | |
| 548 FOR_EACH_OBSERVER(Observer, observer_list(), OnVideoInstanceClosed()); | |
| 549 } | 154 } |
| 550 | 155 |
| 551 void ArcBridgeService::OnWindowManagerInstanceReady( | 156 void ArcBridgeService::OnWindowManagerInstanceReady( |
| 552 mojom::WindowManagerInstancePtr window_manager_ptr) { | 157 mojom::WindowManagerInstancePtr window_manager_ptr) { |
| 553 DCHECK(CalledOnValidThread()); | 158 DCHECK(CalledOnValidThread()); |
| 554 temporary_window_manager_ptr_ = std::move(window_manager_ptr); | 159 window_manager_.OnInstanceReady(std::move(window_manager_ptr)); |
| 555 temporary_window_manager_ptr_.QueryVersion(base::Bind( | |
| 556 &ArcBridgeService::OnWindowManagerVersionReady, | |
| 557 weak_factory_.GetWeakPtr())); | |
| 558 } | |
| 559 | |
| 560 void ArcBridgeService::OnWindowManagerVersionReady(uint32_t version) { | |
| 561 DCHECK(CalledOnValidThread()); | |
| 562 window_manager_ptr_ = std::move(temporary_window_manager_ptr_); | |
| 563 window_manager_ptr_.set_connection_error_handler(base::Bind( | |
| 564 &ArcBridgeService::CloseWindowManagerChannel, | |
| 565 weak_factory_.GetWeakPtr())); | |
| 566 FOR_EACH_OBSERVER(Observer, observer_list(), OnWindowManagerInstanceReady()); | |
| 567 } | |
| 568 | |
| 569 void ArcBridgeService::CloseWindowManagerChannel() { | |
| 570 if (!window_manager_ptr_) | |
| 571 return; | |
| 572 | |
| 573 window_manager_ptr_.reset(); | |
| 574 FOR_EACH_OBSERVER(Observer, observer_list(), OnWindowManagerInstanceClosed()); | |
| 575 } | 160 } |
| 576 | 161 |
| 577 void ArcBridgeService::SetState(State state) { | 162 void ArcBridgeService::SetState(State state) { |
| 578 DCHECK(CalledOnValidThread()); | 163 DCHECK(CalledOnValidThread()); |
| 579 // DCHECK on enum classes not supported. | 164 // DCHECK on enum classes not supported. |
| 580 DCHECK(state_ != state); | 165 DCHECK(state_ != state); |
| 581 state_ = state; | 166 state_ = state; |
| 582 VLOG(2) << "State: " << static_cast<uint32_t>(state_); | 167 VLOG(2) << "State: " << static_cast<uint32_t>(state_); |
| 583 FOR_EACH_OBSERVER(Observer, observer_list(), OnStateChanged(state_)); | 168 FOR_EACH_OBSERVER(Observer, observer_list(), OnStateChanged(state_)); |
| 584 if (state_ == State::READY) | 169 if (state_ == State::READY) |
| 585 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); | 170 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); |
| 586 else if (state == State::STOPPED) | 171 else if (state == State::STOPPED) |
| 587 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped()); | 172 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped()); |
| 588 } | 173 } |
| 589 | 174 |
| 590 void ArcBridgeService::SetAvailable(bool available) { | 175 void ArcBridgeService::SetAvailable(bool available) { |
| 591 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
| 592 DCHECK(available_ != available); | 177 DCHECK(available_ != available); |
| 593 available_ = available; | 178 available_ = available; |
| 594 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); | 179 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); |
| 595 } | 180 } |
| 596 | 181 |
| 597 bool ArcBridgeService::CalledOnValidThread() { | 182 bool ArcBridgeService::CalledOnValidThread() { |
| 598 return thread_checker_.CalledOnValidThread(); | 183 return thread_checker_.CalledOnValidThread(); |
| 599 } | 184 } |
| 600 | 185 |
| 601 void ArcBridgeService::CloseAllChannels() { | 186 void ArcBridgeService::CloseAllChannels() { |
| 602 // Call all the error handlers of all the channels to both close the channel | 187 // Call all the error handlers of all the channels to both close the channel |
| 603 // and notify any observers that the channel is closed. | 188 // and notify any observers that the channel is closed. |
| 604 CloseAppChannel(); | 189 app_.CloseChannel(); |
| 605 CloseAudioChannel(); | 190 audio_.CloseChannel(); |
| 606 CloseAuthChannel(); | 191 auth_.CloseChannel(); |
| 607 CloseBluetoothChannel(); | 192 bluetooth_.CloseChannel(); |
| 608 CloseClipboardChannel(); | 193 clipboard_.CloseChannel(); |
| 609 CloseCrashCollectorChannel(); | 194 crash_collector_.CloseChannel(); |
| 610 CloseFileSystemChannel(); | 195 file_system_.CloseChannel(); |
| 611 CloseImeChannel(); | 196 ime_.CloseChannel(); |
| 612 CloseIntentHelperChannel(); | 197 intent_helper_.CloseChannel(); |
| 613 CloseMetricsChannel(); | 198 metrics_.CloseChannel(); |
| 614 CloseNetChannel(); | 199 net_.CloseChannel(); |
| 615 CloseNotificationsChannel(); | 200 notifications_.CloseChannel(); |
| 616 CloseObbMounterChannel(); | 201 obb_mounter_.CloseChannel(); |
| 617 ClosePolicyChannel(); | 202 policy_.CloseChannel(); |
| 618 ClosePowerChannel(); | 203 power_.CloseChannel(); |
| 619 CloseProcessChannel(); | 204 process_.CloseChannel(); |
| 620 CloseStorageManagerChannel(); | 205 storage_manager_.CloseChannel(); |
| 621 CloseVideoChannel(); | 206 video_.CloseChannel(); |
| 622 CloseWindowManagerChannel(); | 207 window_manager_.CloseChannel(); |
| 623 } | 208 } |
| 624 | 209 |
| 625 } // namespace arc | 210 } // namespace arc |
| OLD | NEW |