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 (ime_instance()) | 69 if (ime_instance()) |
68 observer->OnImeInstanceReady(); | 70 observer->OnImeInstanceReady(); |
69 if (input_instance()) | 71 if (input_instance()) |
70 observer->OnInputInstanceReady(); | 72 observer->OnInputInstanceReady(); |
71 if (net_instance()) | 73 if (net_instance()) |
72 observer->OnNetInstanceReady(); | 74 observer->OnNetInstanceReady(); |
(...skipping 29 matching lines...) Expand all Loading... | |
102 | 104 |
103 void ArcBridgeService::CloseAppChannel() { | 105 void ArcBridgeService::CloseAppChannel() { |
104 DCHECK(CalledOnValidThread()); | 106 DCHECK(CalledOnValidThread()); |
105 if (!app_ptr_) | 107 if (!app_ptr_) |
106 return; | 108 return; |
107 | 109 |
108 app_ptr_.reset(); | 110 app_ptr_.reset(); |
109 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); | 111 FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); |
110 } | 112 } |
111 | 113 |
114 void ArcBridgeService::OnAudioInstanceReady(AudioInstancePtr audio_ptr) { | |
115 DCHECK(CalledOnValidThread()); | |
116 temporary_audio_ptr_ = std::move(audio_ptr); | |
117 temporary_audio_ptr_.QueryVersion(base::Bind( | |
118 &ArcBridgeService::OnAudioVersionReady, weak_factory_.GetWeakPtr())); | |
119 } | |
120 | |
121 void ArcBridgeService::OnAudioVersionReady(int32_t version) { | |
122 DCHECK(CalledOnValidThread()); | |
123 audio_ptr_ = std::move(temporary_audio_ptr_); | |
124 audio_ptr_.set_connection_error_handler(base::Bind( | |
125 &ArcBridgeService::CloseAudioChannel, weak_factory_.GetWeakPtr())); | |
126 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceReady()); | |
127 } | |
128 | |
129 void ArcBridgeService::CloseAudioChannel() { | |
130 if (!audio_ptr_) | |
131 return; | |
132 | |
133 audio_ptr_.reset(); | |
134 FOR_EACH_OBSERVER(Observer, observer_list(), OnAudioInstanceClosed()); | |
135 } | |
136 | |
112 void ArcBridgeService::OnAuthInstanceReady(AuthInstancePtr auth_ptr) { | 137 void ArcBridgeService::OnAuthInstanceReady(AuthInstancePtr auth_ptr) { |
113 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
114 temporary_auth_ptr_ = std::move(auth_ptr); | 139 temporary_auth_ptr_ = std::move(auth_ptr); |
115 temporary_auth_ptr_.QueryVersion(base::Bind( | 140 temporary_auth_ptr_.QueryVersion(base::Bind( |
116 &ArcBridgeService::OnAuthVersionReady, weak_factory_.GetWeakPtr())); | 141 &ArcBridgeService::OnAuthVersionReady, weak_factory_.GetWeakPtr())); |
117 } | 142 } |
118 | 143 |
119 void ArcBridgeService::OnAuthVersionReady(int32_t version) { | 144 void ArcBridgeService::OnAuthVersionReady(int32_t version) { |
120 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
121 auth_ptr_ = std::move(temporary_auth_ptr_); | 146 auth_ptr_ = std::move(temporary_auth_ptr_); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); | 400 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); |
376 } | 401 } |
377 | 402 |
378 bool ArcBridgeService::CalledOnValidThread() { | 403 bool ArcBridgeService::CalledOnValidThread() { |
379 return thread_checker_.CalledOnValidThread(); | 404 return thread_checker_.CalledOnValidThread(); |
380 } | 405 } |
381 | 406 |
382 void ArcBridgeService::CloseAllChannels() { | 407 void ArcBridgeService::CloseAllChannels() { |
383 // Call all the error handlers of all the channels to both close the channel | 408 // Call all the error handlers of all the channels to both close the channel |
384 // and notify any observers that the channel is closed. | 409 // and notify any observers that the channel is closed. |
385 CloseAppChannel(); | 410 CloseAppChannel(); |
Luis Héctor Chávez
2016/03/23 16:22:13
CloseAudioChannel();
chinyue
2016/03/25 09:50:31
Done.
| |
386 CloseAuthChannel(); | 411 CloseAuthChannel(); |
387 CloseClipboardChannel(); | 412 CloseClipboardChannel(); |
388 CloseImeChannel(); | 413 CloseImeChannel(); |
389 CloseInputChannel(); | 414 CloseInputChannel(); |
390 CloseIntentHelperChannel(); | 415 CloseIntentHelperChannel(); |
391 CloseNetChannel(); | 416 CloseNetChannel(); |
392 CloseNotificationsChannel(); | 417 CloseNotificationsChannel(); |
393 ClosePowerChannel(); | 418 ClosePowerChannel(); |
394 CloseProcessChannel(); | 419 CloseProcessChannel(); |
395 CloseVideoChannel(); | 420 CloseVideoChannel(); |
396 } | 421 } |
397 | 422 |
398 } // namespace arc | 423 } // namespace arc |
OLD | NEW |