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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 void ArcBridgeService::AddObserver(Observer* observer) { | 54 void ArcBridgeService::AddObserver(Observer* observer) { |
55 DCHECK(CalledOnValidThread()); | 55 DCHECK(CalledOnValidThread()); |
56 observer_list_.AddObserver(observer); | 56 observer_list_.AddObserver(observer); |
57 | 57 |
58 // If any of the instances were ready before the call to AddObserver(), the | 58 // If any of the instances were ready before the call to AddObserver(), the |
59 // |observer| won't get any readiness events. For such cases, we have to call | 59 // |observer| won't get any readiness events. For such cases, we have to call |
60 // them explicitly now to avoid a race. | 60 // them explicitly now to avoid a race. |
61 if (app_instance()) | 61 if (app_instance()) |
62 observer->OnAppInstanceReady(); | 62 observer->OnAppInstanceReady(); |
| 63 if (audio_instance()) |
| 64 observer->OnAudioInstanceReady(); |
63 if (auth_instance()) | 65 if (auth_instance()) |
64 observer->OnAuthInstanceReady(); | 66 observer->OnAuthInstanceReady(); |
65 if (clipboard_instance()) | 67 if (clipboard_instance()) |
66 observer->OnClipboardInstanceReady(); | 68 observer->OnClipboardInstanceReady(); |
67 if (crash_collector_instance()) | 69 if (crash_collector_instance()) |
68 observer->OnCrashCollectorInstanceReady(); | 70 observer->OnCrashCollectorInstanceReady(); |
69 if (ime_instance()) | 71 if (ime_instance()) |
70 observer->OnImeInstanceReady(); | 72 observer->OnImeInstanceReady(); |
71 if (input_instance()) | 73 if (input_instance()) |
72 observer->OnInputInstanceReady(); | 74 observer->OnInputInstanceReady(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 108 |
107 void ArcBridgeService::CloseAppChannel() { | 109 void ArcBridgeService::CloseAppChannel() { |
108 DCHECK(CalledOnValidThread()); | 110 DCHECK(CalledOnValidThread()); |
109 if (!app_ptr_) | 111 if (!app_ptr_) |
110 return; | 112 return; |
111 | 113 |
112 app_ptr_.reset(); | 114 app_ptr_.reset(); |
113 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); | 115 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); |
114 } | 116 } |
115 | 117 |
| 118 void ArcBridgeService::OnAudioInstanceReady(AudioInstancePtr audio_ptr) { |
| 119 DCHECK(CalledOnValidThread()); |
| 120 temporary_audio_ptr_ = std::move(audio_ptr); |
| 121 temporary_audio_ptr_.QueryVersion(base::Bind( |
| 122 &ArcBridgeService::OnAudioVersionReady, weak_factory_.GetWeakPtr())); |
| 123 } |
| 124 |
| 125 void ArcBridgeService::OnAudioVersionReady(int32_t version) { |
| 126 DCHECK(CalledOnValidThread()); |
| 127 audio_ptr_ = std::move(temporary_audio_ptr_); |
| 128 audio_ptr_.set_connection_error_handler(base::Bind( |
| 129 &ArcBridgeService::CloseAudioChannel, weak_factory_.GetWeakPtr())); |
| 130 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceReady()); |
| 131 } |
| 132 |
| 133 void ArcBridgeService::CloseAudioChannel() { |
| 134 if (!audio_ptr_) |
| 135 return; |
| 136 |
| 137 audio_ptr_.reset(); |
| 138 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceClosed()); |
| 139 } |
| 140 |
116 void ArcBridgeService::OnAuthInstanceReady(AuthInstancePtr auth_ptr) { | 141 void ArcBridgeService::OnAuthInstanceReady(AuthInstancePtr auth_ptr) { |
117 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
118 temporary_auth_ptr_ = std::move(auth_ptr); | 143 temporary_auth_ptr_ = std::move(auth_ptr); |
119 temporary_auth_ptr_.QueryVersion(base::Bind( | 144 temporary_auth_ptr_.QueryVersion(base::Bind( |
120 &ArcBridgeService::OnAuthVersionReady, weak_factory_.GetWeakPtr())); | 145 &ArcBridgeService::OnAuthVersionReady, weak_factory_.GetWeakPtr())); |
121 } | 146 } |
122 | 147 |
123 void ArcBridgeService::OnAuthVersionReady(int32_t version) { | 148 void ArcBridgeService::OnAuthVersionReady(int32_t version) { |
124 DCHECK(CalledOnValidThread()); | 149 DCHECK(CalledOnValidThread()); |
125 auth_ptr_ = std::move(temporary_auth_ptr_); | 150 auth_ptr_ = std::move(temporary_auth_ptr_); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 452 } |
428 | 453 |
429 bool ArcBridgeService::CalledOnValidThread() { | 454 bool ArcBridgeService::CalledOnValidThread() { |
430 return thread_checker_.CalledOnValidThread(); | 455 return thread_checker_.CalledOnValidThread(); |
431 } | 456 } |
432 | 457 |
433 void ArcBridgeService::CloseAllChannels() { | 458 void ArcBridgeService::CloseAllChannels() { |
434 // Call all the error handlers of all the channels to both close the channel | 459 // Call all the error handlers of all the channels to both close the channel |
435 // and notify any observers that the channel is closed. | 460 // and notify any observers that the channel is closed. |
436 CloseAppChannel(); | 461 CloseAppChannel(); |
| 462 CloseAudioChannel(); |
437 CloseAuthChannel(); | 463 CloseAuthChannel(); |
438 CloseClipboardChannel(); | 464 CloseClipboardChannel(); |
439 CloseCrashCollectorChannel(); | 465 CloseCrashCollectorChannel(); |
440 CloseImeChannel(); | 466 CloseImeChannel(); |
441 CloseInputChannel(); | 467 CloseInputChannel(); |
442 CloseIntentHelperChannel(); | 468 CloseIntentHelperChannel(); |
443 CloseNetChannel(); | 469 CloseNetChannel(); |
444 CloseNotificationsChannel(); | 470 CloseNotificationsChannel(); |
445 ClosePolicyChannel(); | 471 ClosePolicyChannel(); |
446 ClosePowerChannel(); | 472 ClosePowerChannel(); |
447 CloseProcessChannel(); | 473 CloseProcessChannel(); |
448 CloseVideoChannel(); | 474 CloseVideoChannel(); |
449 } | 475 } |
450 | 476 |
451 } // namespace arc | 477 } // namespace arc |
OLD | NEW |