Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / fake_cras_audio_client.cc
blobc59b3e5312fc9054eabdf922665c318161feb7b5
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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_cras_audio_client.h"
7 namespace chromeos {
9 FakeCrasAudioClient::FakeCrasAudioClient()
10 : active_input_node_id_(0),
11 active_output_node_id_(0) {
14 FakeCrasAudioClient::~FakeCrasAudioClient() {
17 void FakeCrasAudioClient::Init(dbus::Bus* bus) {
18 VLOG(1) << "FakeCrasAudioClient is created";
20 // Fake audio output nodes.
21 AudioNode output_1;
22 output_1.is_input = false;
23 output_1.id = 10001;
24 output_1.device_name = "Fake Speaker";
25 output_1.type = "INTERNAL_SPEAKER";
26 output_1.name = "Speaker";
27 node_list_.push_back(output_1);
29 AudioNode output_2;
30 output_2.is_input = false;
31 output_2.id = 10002;
32 output_2.device_name = "Fake Headphone";
33 output_2.type = "HEADPHONE";
34 output_2.name = "Headphone";
35 node_list_.push_back(output_2);
37 AudioNode output_3;
38 output_3.is_input = false;
39 output_3.id = 10003;
40 output_3.device_name = "Fake Bluetooth Headphone";
41 output_3.type = "BLUETOOTH";
42 output_3.name = "Headphone";
43 node_list_.push_back(output_3);
45 AudioNode output_4;
46 output_4.is_input = false;
47 output_4.id = 10004;
48 output_4.device_name = "Fake HDMI Speaker";
49 output_4.type = "HDMI";
50 output_4.name = "HDMI Speaker";
51 node_list_.push_back(output_4);
53 // Fake audio input nodes
54 AudioNode input_1;
55 input_1.is_input = true;
56 input_1.id = 20001;
57 input_1.device_name = "Fake Internal Mic";
58 input_1.type = "INTERNAL_MIC";
59 input_1.name = "Internal Mic";
60 node_list_.push_back(input_1);
62 AudioNode input_2;
63 input_2.is_input = true;
64 input_2.id = 20002;
65 input_2.device_name = "Fake USB Mic";
66 input_2.type = "USB";
67 input_2.name = "Mic";
68 node_list_.push_back(input_2);
70 AudioNode input_3;
71 input_3.is_input = true;
72 input_3.id = 20003;
73 input_3.device_name = "Fake Mick Jack";
74 input_3.type = "MIC";
75 input_3.name = "Some type of Mic";
76 node_list_.push_back(input_3);
79 void FakeCrasAudioClient::AddObserver(Observer* observer) {
80 observers_.AddObserver(observer);
83 void FakeCrasAudioClient::RemoveObserver(Observer* observer) {
84 observers_.RemoveObserver(observer);
87 bool FakeCrasAudioClient::HasObserver(const Observer* observer) const {
88 return observers_.HasObserver(observer);
91 void FakeCrasAudioClient::GetVolumeState(
92 const GetVolumeStateCallback& callback) {
93 callback.Run(volume_state_, true);
96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback,
97 const ErrorCallback& error_callback) {
98 callback.Run(node_list_, true);
101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id,
102 int32 volume) {
105 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) {
106 volume_state_.output_user_mute = mute_on;
107 FOR_EACH_OBSERVER(Observer,
108 observers_,
109 OutputMuteChanged(volume_state_.output_user_mute));
112 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id,
113 int32 input_gain) {
116 void FakeCrasAudioClient::SetInputMute(bool mute_on) {
117 volume_state_.input_mute = mute_on;
118 FOR_EACH_OBSERVER(Observer,
119 observers_,
120 InputMuteChanged(volume_state_.input_mute));
123 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) {
124 if (active_output_node_id_ == node_id)
125 return;
127 for (size_t i = 0; i < node_list_.size(); ++i) {
128 if (node_list_[i].id == active_output_node_id_)
129 node_list_[i].active = false;
130 else if (node_list_[i].id == node_id)
131 node_list_[i].active = true;
133 active_output_node_id_ = node_id;
134 FOR_EACH_OBSERVER(Observer,
135 observers_,
136 ActiveOutputNodeChanged(node_id));
139 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) {
140 if (active_input_node_id_ == node_id)
141 return;
143 for (size_t i = 0; i < node_list_.size(); ++i) {
144 if (node_list_[i].id == active_input_node_id_)
145 node_list_[i].active = false;
146 else if (node_list_[i].id == node_id)
147 node_list_[i].active = true;
149 active_input_node_id_ = node_id;
150 FOR_EACH_OBSERVER(Observer,
151 observers_,
152 ActiveInputNodeChanged(node_id));
155 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) {
156 for (size_t i = 0; i < node_list_.size(); ++i) {
157 if (node_list_[i].id == node_id)
158 node_list_[i].active = true;
162 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) {
163 for (size_t i = 0; i < node_list_.size(); ++i) {
164 if (node_list_[i].id == node_id)
165 node_list_[i].active = false;
169 void FakeCrasAudioClient::SwapLeftRight(uint64 node_id, bool swap) {
172 void FakeCrasAudioClient::AddActiveOutputNode(uint64 node_id) {
173 for (size_t i = 0; i < node_list_.size(); ++i) {
174 if (node_list_[i].id == node_id)
175 node_list_[i].active = true;
179 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) {
180 for (size_t i = 0; i < node_list_.size(); ++i) {
181 if (node_list_[i].id == node_id)
182 node_list_[i].active = false;
186 void FakeCrasAudioClient::SetAudioNodesForTesting(
187 const AudioNodeList& audio_nodes) {
188 node_list_ = audio_nodes;
191 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
192 const AudioNodeList& new_nodes) {
193 SetAudioNodesForTesting(new_nodes);
194 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
197 } // namespace chromeos