Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / chromeos / dbus / fake_cras_audio_client.cc
blob754d97d516271b25e7e03b14695f1e77982c47df
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);
71 void FakeCrasAudioClient::AddObserver(Observer* observer) {
72 observers_.AddObserver(observer);
75 void FakeCrasAudioClient::RemoveObserver(Observer* observer) {
76 observers_.RemoveObserver(observer);
79 bool FakeCrasAudioClient::HasObserver(const Observer* observer) const {
80 return observers_.HasObserver(observer);
83 void FakeCrasAudioClient::GetVolumeState(
84 const GetVolumeStateCallback& callback) {
85 callback.Run(volume_state_, true);
88 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback,
89 const ErrorCallback& error_callback) {
90 callback.Run(node_list_, true);
93 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id,
94 int32 volume) {
97 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) {
98 volume_state_.output_user_mute = mute_on;
99 FOR_EACH_OBSERVER(Observer,
100 observers_,
101 OutputMuteChanged(volume_state_.output_user_mute));
104 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id,
105 int32 input_gain) {
108 void FakeCrasAudioClient::SetInputMute(bool mute_on) {
109 volume_state_.input_mute = mute_on;
110 FOR_EACH_OBSERVER(Observer,
111 observers_,
112 InputMuteChanged(volume_state_.input_mute));
115 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) {
116 if (active_output_node_id_ == node_id)
117 return;
119 for (size_t i = 0; i < node_list_.size(); ++i) {
120 if (node_list_[i].id == active_output_node_id_)
121 node_list_[i].active = false;
122 else if (node_list_[i].id == node_id)
123 node_list_[i].active = true;
125 active_output_node_id_ = node_id;
126 FOR_EACH_OBSERVER(Observer,
127 observers_,
128 ActiveOutputNodeChanged(node_id));
131 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) {
132 if (active_input_node_id_ == node_id)
133 return;
135 for (size_t i = 0; i < node_list_.size(); ++i) {
136 if (node_list_[i].id == active_input_node_id_)
137 node_list_[i].active = false;
138 else if (node_list_[i].id == node_id)
139 node_list_[i].active = true;
141 active_input_node_id_ = node_id;
142 FOR_EACH_OBSERVER(Observer,
143 observers_,
144 ActiveInputNodeChanged(node_id));
147 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) {
148 for (size_t i = 0; i < node_list_.size(); ++i) {
149 if (node_list_[i].id == node_id)
150 node_list_[i].active = true;
154 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) {
155 for (size_t i = 0; i < node_list_.size(); ++i) {
156 if (node_list_[i].id == node_id)
157 node_list_[i].active = false;
161 void FakeCrasAudioClient::SwapLeftRight(uint64 node_id, bool swap) {
164 void FakeCrasAudioClient::AddActiveOutputNode(uint64 node_id) {
165 for (size_t i = 0; i < node_list_.size(); ++i) {
166 if (node_list_[i].id == node_id)
167 node_list_[i].active = true;
171 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) {
172 for (size_t i = 0; i < node_list_.size(); ++i) {
173 if (node_list_[i].id == node_id)
174 node_list_[i].active = false;
178 void FakeCrasAudioClient::SetAudioNodesForTesting(
179 const AudioNodeList& audio_nodes) {
180 node_list_ = audio_nodes;
183 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
184 const AudioNodeList& new_nodes) {
185 SetAudioNodesForTesting(new_nodes);
186 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
189 } // namespace chromeos