| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void ArcBridgeService::AddObserver(Observer* observer) { | 47 void ArcBridgeService::AddObserver(Observer* observer) { |
| 48 DCHECK(CalledOnValidThread()); | 48 DCHECK(CalledOnValidThread()); |
| 49 observer_list_.AddObserver(observer); | 49 observer_list_.AddObserver(observer); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void ArcBridgeService::RemoveObserver(Observer* observer) { | 52 void ArcBridgeService::RemoveObserver(Observer* observer) { |
| 53 DCHECK(CalledOnValidThread()); | 53 DCHECK(CalledOnValidThread()); |
| 54 observer_list_.RemoveObserver(observer); | 54 observer_list_.RemoveObserver(observer); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ArcBridgeService::OnAppInstanceReady(mojom::AppInstancePtr app_ptr) { | |
| 58 DCHECK(CalledOnValidThread()); | |
| 59 app_.OnInstanceReady(std::move(app_ptr)); | |
| 60 } | |
| 61 | |
| 62 void ArcBridgeService::OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) { | |
| 63 DCHECK(CalledOnValidThread()); | |
| 64 audio_.OnInstanceReady(std::move(audio_ptr)); | |
| 65 } | |
| 66 | |
| 67 void ArcBridgeService::OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) { | |
| 68 DCHECK(CalledOnValidThread()); | |
| 69 auth_.OnInstanceReady(std::move(auth_ptr)); | |
| 70 } | |
| 71 | |
| 72 void ArcBridgeService::OnBluetoothInstanceReady( | |
| 73 mojom::BluetoothInstancePtr bluetooth_ptr) { | |
| 74 DCHECK(CalledOnValidThread()); | |
| 75 bluetooth_.OnInstanceReady(std::move(bluetooth_ptr)); | |
| 76 } | |
| 77 | |
| 78 void ArcBridgeService::OnClipboardInstanceReady( | |
| 79 mojom::ClipboardInstancePtr clipboard_ptr) { | |
| 80 DCHECK(CalledOnValidThread()); | |
| 81 clipboard_.OnInstanceReady(std::move(clipboard_ptr)); | |
| 82 } | |
| 83 | |
| 84 void ArcBridgeService::OnCrashCollectorInstanceReady( | |
| 85 mojom::CrashCollectorInstancePtr crash_collector_ptr) { | |
| 86 DCHECK(CalledOnValidThread()); | |
| 87 crash_collector_.OnInstanceReady(std::move(crash_collector_ptr)); | |
| 88 } | |
| 89 | |
| 90 void ArcBridgeService::OnFileSystemInstanceReady( | |
| 91 mojom::FileSystemInstancePtr file_system_ptr) { | |
| 92 DCHECK(CalledOnValidThread()); | |
| 93 file_system_.OnInstanceReady(std::move(file_system_ptr)); | |
| 94 } | |
| 95 | |
| 96 void ArcBridgeService::OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) { | |
| 97 DCHECK(CalledOnValidThread()); | |
| 98 ime_.OnInstanceReady(std::move(ime_ptr)); | |
| 99 } | |
| 100 | |
| 101 void ArcBridgeService::OnIntentHelperInstanceReady( | |
| 102 mojom::IntentHelperInstancePtr intent_helper_ptr) { | |
| 103 DCHECK(CalledOnValidThread()); | |
| 104 intent_helper_.OnInstanceReady(std::move(intent_helper_ptr)); | |
| 105 } | |
| 106 | |
| 107 void ArcBridgeService::OnMetricsInstanceReady( | |
| 108 mojom::MetricsInstancePtr metrics_ptr) { | |
| 109 DCHECK(CalledOnValidThread()); | |
| 110 metrics_.OnInstanceReady(std::move(metrics_ptr)); | |
| 111 } | |
| 112 | |
| 113 void ArcBridgeService::OnNetInstanceReady(mojom::NetInstancePtr net_ptr) { | |
| 114 DCHECK(CalledOnValidThread()); | |
| 115 net_.OnInstanceReady(std::move(net_ptr)); | |
| 116 } | |
| 117 | |
| 118 void ArcBridgeService::OnNotificationsInstanceReady( | |
| 119 mojom::NotificationsInstancePtr notifications_ptr) { | |
| 120 DCHECK(CalledOnValidThread()); | |
| 121 notifications_.OnInstanceReady(std::move(notifications_ptr)); | |
| 122 } | |
| 123 | |
| 124 void ArcBridgeService::OnObbMounterInstanceReady( | |
| 125 mojom::ObbMounterInstancePtr obb_mounter_ptr) { | |
| 126 DCHECK(CalledOnValidThread()); | |
| 127 obb_mounter_.OnInstanceReady(std::move(obb_mounter_ptr)); | |
| 128 } | |
| 129 | |
| 130 void ArcBridgeService::OnPolicyInstanceReady( | |
| 131 mojom::PolicyInstancePtr policy_ptr) { | |
| 132 DCHECK(CalledOnValidThread()); | |
| 133 policy_.OnInstanceReady(std::move(policy_ptr)); | |
| 134 } | |
| 135 | |
| 136 void ArcBridgeService::OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) { | |
| 137 DCHECK(CalledOnValidThread()); | |
| 138 power_.OnInstanceReady(std::move(power_ptr)); | |
| 139 } | |
| 140 | |
| 141 void ArcBridgeService::OnProcessInstanceReady( | |
| 142 mojom::ProcessInstancePtr process_ptr) { | |
| 143 DCHECK(CalledOnValidThread()); | |
| 144 process_.OnInstanceReady(std::move(process_ptr)); | |
| 145 } | |
| 146 | |
| 147 void ArcBridgeService::OnStorageManagerInstanceReady( | |
| 148 mojom::StorageManagerInstancePtr storage_manager_ptr) { | |
| 149 DCHECK(CalledOnValidThread()); | |
| 150 storage_manager_.OnInstanceReady(std::move(storage_manager_ptr)); | |
| 151 } | |
| 152 | |
| 153 void ArcBridgeService::OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) { | |
| 154 DCHECK(CalledOnValidThread()); | |
| 155 video_.OnInstanceReady(std::move(video_ptr)); | |
| 156 } | |
| 157 | |
| 158 void ArcBridgeService::OnWindowManagerInstanceReady( | |
| 159 mojom::WindowManagerInstancePtr window_manager_ptr) { | |
| 160 DCHECK(CalledOnValidThread()); | |
| 161 window_manager_.OnInstanceReady(std::move(window_manager_ptr)); | |
| 162 } | |
| 163 | |
| 164 void ArcBridgeService::SetState(State state) { | 57 void ArcBridgeService::SetState(State state) { |
| 165 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
| 166 DCHECK_NE(state_, state); | 59 DCHECK_NE(state_, state); |
| 167 state_ = state; | 60 state_ = state; |
| 168 VLOG(2) << "State: " << static_cast<uint32_t>(state_); | 61 VLOG(2) << "State: " << static_cast<uint32_t>(state_); |
| 169 if (state_ == State::READY) | 62 if (state_ == State::READY) |
| 170 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); | 63 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); |
| 171 else if (state == State::STOPPED) | 64 else if (state == State::STOPPED) |
| 172 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped(stop_reason_)); | 65 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped(stop_reason_)); |
| 173 } | 66 } |
| 174 | 67 |
| 175 void ArcBridgeService::SetAvailable(bool available) { | 68 void ArcBridgeService::SetAvailable(bool available) { |
| 176 DCHECK(CalledOnValidThread()); | 69 DCHECK(CalledOnValidThread()); |
| 177 DCHECK_NE(available_, available); | 70 DCHECK_NE(available_, available); |
| 178 available_ = available; | 71 available_ = available; |
| 179 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); | 72 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); |
| 180 } | 73 } |
| 181 | 74 |
| 182 void ArcBridgeService::SetStopReason(StopReason stop_reason) { | 75 void ArcBridgeService::SetStopReason(StopReason stop_reason) { |
| 183 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
| 184 stop_reason_ = stop_reason; | 77 stop_reason_ = stop_reason; |
| 185 } | 78 } |
| 186 | 79 |
| 187 bool ArcBridgeService::CalledOnValidThread() { | 80 bool ArcBridgeService::CalledOnValidThread() { |
| 188 return thread_checker_.CalledOnValidThread(); | 81 return thread_checker_.CalledOnValidThread(); |
| 189 } | 82 } |
| 190 | 83 |
| 191 void ArcBridgeService::CloseAllChannels() { | |
| 192 // Call all the error handlers of all the channels to both close the channel | |
| 193 // and notify any observers that the channel is closed. | |
| 194 app_.CloseChannel(); | |
| 195 audio_.CloseChannel(); | |
| 196 auth_.CloseChannel(); | |
| 197 bluetooth_.CloseChannel(); | |
| 198 clipboard_.CloseChannel(); | |
| 199 crash_collector_.CloseChannel(); | |
| 200 file_system_.CloseChannel(); | |
| 201 ime_.CloseChannel(); | |
| 202 intent_helper_.CloseChannel(); | |
| 203 metrics_.CloseChannel(); | |
| 204 net_.CloseChannel(); | |
| 205 notifications_.CloseChannel(); | |
| 206 obb_mounter_.CloseChannel(); | |
| 207 policy_.CloseChannel(); | |
| 208 power_.CloseChannel(); | |
| 209 process_.CloseChannel(); | |
| 210 storage_manager_.CloseChannel(); | |
| 211 video_.CloseChannel(); | |
| 212 window_manager_.CloseChannel(); | |
| 213 } | |
| 214 | |
| 215 } // namespace arc | 84 } // namespace arc |
| OLD | NEW |