Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chromeos/dbus/cras_audio_client_stub_impl.cc

Issue 19861002: Add test coverage for CrasAudioHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/cras_audio_client_stub_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chromeos/dbus/cras_audio_client_stub_impl.h"
6
7 namespace chromeos {
8
9 CrasAudioClientStubImpl::CrasAudioClientStubImpl() {
10 VLOG(1) << "CrasAudioClientStubImpl is created";
11
12 // Fake audio output nodes.
13 AudioNode node_1;
14 node_1.is_input = false;
15 node_1.id = 10001;
16 node_1.device_name = "Fake Speaker";
17 node_1.type = "INTERNAL_SPEAKER";
18 node_1.name = "Speaker";
19 node_1.active = false;
20 node_list_.push_back(node_1);
21
22 AudioNode node_2;
23 node_2.is_input = false;
24 node_2.id = 10002;
25 node_2.device_name = "Fake Headphone";
26 node_2.type = "HEADPHONE";
27 node_2.name = "Headphone";
28 node_2.active = false;
29 node_list_.push_back(node_2);
30 active_output_node_id_ = node_2.id;
31
32 AudioNode node_3;
33 node_3.is_input = false;
34 node_3.id = 10003;
35 node_3.device_name = "Fake Bluetooth Headphone";
36 node_3.type = "BLUETOOTH";
37 node_3.name = "Bluetooth Headphone";
38 node_3.active = false;
39 node_list_.push_back(node_3);
40
41 // Fake audio input ndoes
42 AudioNode node_4;
43 node_4.is_input = true;
44 node_4.id = 10004;
45 node_4.device_name = "Fake Internal Mic";
46 node_4.type = "INTERNAL_MIC";
47 node_4.name = "Internal Mic";
48 node_4.active = false;
49 node_list_.push_back(node_4);
50
51 AudioNode node_5;
52 node_5.is_input = true;
53 node_5.id = 10005;
54 node_5.device_name = "Fake USB Mic";
55 node_5.type = "USB";
56 node_5.name = "USB Mic";
57 node_5.active = true;
58 node_list_.push_back(node_5);
59
60 active_input_node_id_ = node_5.id;
61 }
62
63 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
64 }
65
66 void CrasAudioClientStubImpl::AddObserver(Observer* observer) {
67 observers_.AddObserver(observer);
68 }
69
70 void CrasAudioClientStubImpl::RemoveObserver(Observer* observer) {
71 observers_.RemoveObserver(observer);
72 }
73
74 bool CrasAudioClientStubImpl::HasObserver(Observer* observer) {
75 return observers_.HasObserver(observer);
76 }
77
78 void CrasAudioClientStubImpl::GetVolumeState(
79 const GetVolumeStateCallback& callback) {
80 callback.Run(volume_state_, true);
81 }
82
83 void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback& callback) {
84 callback.Run(node_list_, true);
85 }
86
87 void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id,
88 int32 volume) {
89 }
90
91 void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on) {
92 volume_state_.output_user_mute = mute_on;
93 FOR_EACH_OBSERVER(Observer,
94 observers_,
95 OutputMuteChanged(volume_state_.output_user_mute));
96 }
97
98 void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id,
99 int32 input_gain) {
100 }
101
102 void CrasAudioClientStubImpl::SetInputMute(bool mute_on) {
103 volume_state_.input_mute = mute_on;
104 FOR_EACH_OBSERVER(Observer,
105 observers_,
106 InputMuteChanged(volume_state_.input_mute));
107 }
108
109 void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id) {
110 if (active_output_node_id_ == node_id)
111 return;
112
113 for (size_t i = 0; i < node_list_.size(); ++i) {
114 if (node_list_[i].id == active_output_node_id_)
115 node_list_[i].active = false;
116 else if (node_list_[i].id == node_id)
117 node_list_[i].active = true;
118 }
119 active_output_node_id_ = node_id;
120 FOR_EACH_OBSERVER(Observer,
121 observers_,
122 ActiveOutputNodeChanged(node_id));
123 }
124
125 void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id) {
126 if (active_input_node_id_ == node_id)
127 return;
128
129 for (size_t i = 0; i < node_list_.size(); ++i) {
130 if (node_list_[i].id == active_input_node_id_)
131 node_list_[i].active = false;
132 else if (node_list_[i].id == node_id)
133 node_list_[i].active = true;
134 }
135 active_input_node_id_ = node_id;
136 FOR_EACH_OBSERVER(Observer,
137 observers_,
138 ActiveInputNodeChanged(node_id));
139 }
140
141 void CrasAudioClientStubImpl::SetAudioDevices(
142 const AudioNodeList& audio_nodes) {
143 node_list_.clear();
144 for (size_t i = 0; i < audio_nodes.size(); ++i)
145 node_list_.push_back(audio_nodes[i]);
146 }
147
148 void CrasAudioClientStubImpl::ChangeAudioNodes(const AudioNodeList& new_nodes) {
149 SetAudioDevices(new_nodes);
150 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
151 }
152
153 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/cras_audio_client_stub_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698