| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/dbus/fake_cras_audio_client.h" | 5 #include "chromeos/dbus/fake_cras_audio_client.h" |
| 6 | 6 |
| 7 namespace chromeos { | 7 namespace chromeos { |
| 8 | 8 |
| 9 FakeCrasAudioClient::FakeCrasAudioClient() | 9 FakeCrasAudioClient::FakeCrasAudioClient() |
| 10 : active_input_node_id_(0), | 10 : active_input_node_id_(0), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FakeCrasAudioClient::SetOutputNodeVolume(uint64_t node_id, | 108 void FakeCrasAudioClient::SetOutputNodeVolume(uint64_t node_id, |
| 109 int32_t volume) { | 109 int32_t volume) { |
| 110 if (!notify_volume_change_with_delay_) | 110 if (!notify_volume_change_with_delay_) |
| 111 NotifyOutputNodeVolumeChangedForTesting(node_id, volume); | 111 NotifyOutputNodeVolumeChangedForTesting(node_id, volume); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) { | 114 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) { |
| 115 volume_state_.output_user_mute = mute_on; | 115 volume_state_.output_user_mute = mute_on; |
| 116 FOR_EACH_OBSERVER(Observer, observers_, | 116 for (auto& observer : observers_) |
| 117 OutputMuteChanged(volume_state_.output_user_mute)); | 117 observer.OutputMuteChanged(volume_state_.output_user_mute); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void FakeCrasAudioClient::SetInputNodeGain(uint64_t node_id, | 120 void FakeCrasAudioClient::SetInputNodeGain(uint64_t node_id, |
| 121 int32_t input_gain) {} | 121 int32_t input_gain) {} |
| 122 | 122 |
| 123 void FakeCrasAudioClient::SetInputMute(bool mute_on) { | 123 void FakeCrasAudioClient::SetInputMute(bool mute_on) { |
| 124 volume_state_.input_mute = mute_on; | 124 volume_state_.input_mute = mute_on; |
| 125 FOR_EACH_OBSERVER(Observer, observers_, | 125 for (auto& observer : observers_) |
| 126 InputMuteChanged(volume_state_.input_mute)); | 126 observer.InputMuteChanged(volume_state_.input_mute); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void FakeCrasAudioClient::SetActiveOutputNode(uint64_t node_id) { | 129 void FakeCrasAudioClient::SetActiveOutputNode(uint64_t node_id) { |
| 130 if (active_output_node_id_ == node_id) | 130 if (active_output_node_id_ == node_id) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 for (size_t i = 0; i < node_list_.size(); ++i) { | 133 for (size_t i = 0; i < node_list_.size(); ++i) { |
| 134 if (node_list_[i].id == active_output_node_id_) | 134 if (node_list_[i].id == active_output_node_id_) |
| 135 node_list_[i].active = false; | 135 node_list_[i].active = false; |
| 136 else if (node_list_[i].id == node_id) | 136 else if (node_list_[i].id == node_id) |
| 137 node_list_[i].active = true; | 137 node_list_[i].active = true; |
| 138 } | 138 } |
| 139 active_output_node_id_ = node_id; | 139 active_output_node_id_ = node_id; |
| 140 FOR_EACH_OBSERVER(Observer, observers_, ActiveOutputNodeChanged(node_id)); | 140 for (auto& observer : observers_) |
| 141 observer.ActiveOutputNodeChanged(node_id); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void FakeCrasAudioClient::SetActiveInputNode(uint64_t node_id) { | 144 void FakeCrasAudioClient::SetActiveInputNode(uint64_t node_id) { |
| 144 if (active_input_node_id_ == node_id) | 145 if (active_input_node_id_ == node_id) |
| 145 return; | 146 return; |
| 146 | 147 |
| 147 for (size_t i = 0; i < node_list_.size(); ++i) { | 148 for (size_t i = 0; i < node_list_.size(); ++i) { |
| 148 if (node_list_[i].id == active_input_node_id_) | 149 if (node_list_[i].id == active_input_node_id_) |
| 149 node_list_[i].active = false; | 150 node_list_[i].active = false; |
| 150 else if (node_list_[i].id == node_id) | 151 else if (node_list_[i].id == node_id) |
| 151 node_list_[i].active = true; | 152 node_list_[i].active = true; |
| 152 } | 153 } |
| 153 active_input_node_id_ = node_id; | 154 active_input_node_id_ = node_id; |
| 154 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); | 155 for (auto& observer : observers_) |
| 156 observer.ActiveInputNodeChanged(node_id); |
| 155 } | 157 } |
| 156 | 158 |
| 157 void FakeCrasAudioClient::AddActiveInputNode(uint64_t node_id) { | 159 void FakeCrasAudioClient::AddActiveInputNode(uint64_t node_id) { |
| 158 for (size_t i = 0; i < node_list_.size(); ++i) { | 160 for (size_t i = 0; i < node_list_.size(); ++i) { |
| 159 if (node_list_[i].id == node_id) | 161 if (node_list_[i].id == node_id) |
| 160 node_list_[i].active = true; | 162 node_list_[i].active = true; |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 | 165 |
| 164 void FakeCrasAudioClient::RemoveActiveInputNode(uint64_t node_id) { | 166 void FakeCrasAudioClient::RemoveActiveInputNode(uint64_t node_id) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 191 node_list_[i].active = false; | 193 node_list_[i].active = false; |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
| 195 void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) { | 197 void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) { |
| 196 auto iter = FindNode(audio_node.id); | 198 auto iter = FindNode(audio_node.id); |
| 197 if (iter != node_list_.end()) | 199 if (iter != node_list_.end()) |
| 198 (*iter) = audio_node; | 200 (*iter) = audio_node; |
| 199 else | 201 else |
| 200 node_list_.push_back(audio_node); | 202 node_list_.push_back(audio_node); |
| 201 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | 203 for (auto& observer : observers_) |
| 204 observer.NodesChanged(); |
| 202 } | 205 } |
| 203 | 206 |
| 204 void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64_t& node_id) { | 207 void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64_t& node_id) { |
| 205 auto iter = FindNode(node_id); | 208 auto iter = FindNode(node_id); |
| 206 if (iter != node_list_.end()) { | 209 if (iter != node_list_.end()) { |
| 207 node_list_.erase(iter); | 210 node_list_.erase(iter); |
| 208 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | 211 for (auto& observer : observers_) |
| 212 observer.NodesChanged(); |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 void FakeCrasAudioClient::SetAudioNodesForTesting( | 216 void FakeCrasAudioClient::SetAudioNodesForTesting( |
| 213 const AudioNodeList& audio_nodes) { | 217 const AudioNodeList& audio_nodes) { |
| 214 node_list_ = audio_nodes; | 218 node_list_ = audio_nodes; |
| 215 } | 219 } |
| 216 | 220 |
| 217 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting( | 221 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting( |
| 218 const AudioNodeList& new_nodes) { | 222 const AudioNodeList& new_nodes) { |
| 219 SetAudioNodesForTesting(new_nodes); | 223 SetAudioNodesForTesting(new_nodes); |
| 220 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | 224 for (auto& observer : observers_) |
| 225 observer.NodesChanged(); |
| 221 } | 226 } |
| 222 | 227 |
| 223 void FakeCrasAudioClient::NotifyOutputNodeVolumeChangedForTesting( | 228 void FakeCrasAudioClient::NotifyOutputNodeVolumeChangedForTesting( |
| 224 uint64_t node_id, | 229 uint64_t node_id, |
| 225 int volume) { | 230 int volume) { |
| 226 FOR_EACH_OBSERVER(Observer, observers_, | 231 for (auto& observer : observers_) |
| 227 OutputNodeVolumeChanged(node_id, volume)); | 232 observer.OutputNodeVolumeChanged(node_id, volume); |
| 228 } | 233 } |
| 229 | 234 |
| 230 AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64_t node_id) { | 235 AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64_t node_id) { |
| 231 return std::find_if( | 236 return std::find_if( |
| 232 node_list_.begin(), node_list_.end(), | 237 node_list_.begin(), node_list_.end(), |
| 233 [node_id](const AudioNode& node) { return node_id == node.id; }); | 238 [node_id](const AudioNode& node) { return node_id == node.id; }); |
| 234 } | 239 } |
| 235 | 240 |
| 236 } // namespace chromeos | 241 } // namespace chromeos |
| OLD | NEW |