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 "chrome/browser/extensions/api/audio/audio_service.h" | 5 #include "chrome/browser/extensions/api/audio/audio_service.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chromeos/audio/audio_device.h" | 10 #include "chromeos/audio/audio_device.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 virtual void OnActiveInputNodeChanged() OVERRIDE; | 50 virtual void OnActiveInputNodeChanged() OVERRIDE; |
51 | 51 |
52 private: | 52 private: |
53 void NotifyDeviceChanged(); | 53 void NotifyDeviceChanged(); |
54 | 54 |
55 // Callback for CrasAudioClient::GetNodes(). | 55 // Callback for CrasAudioClient::GetNodes(). |
56 void OnGetNodes(const GetInfoCallback& callback, | 56 void OnGetNodes(const GetInfoCallback& callback, |
57 const chromeos::AudioNodeList& audio_nodes, | 57 const chromeos::AudioNodeList& audio_nodes, |
58 bool success); | 58 bool success); |
59 | 59 |
| 60 // ErrorCallback for CrasAudioClient::GetNodes(). |
| 61 void OnGetNodesError(const std::string& error_name, |
| 62 const std::string& error_msg); |
| 63 |
60 bool FindDevice(uint64 id, chromeos::AudioDevice* device); | 64 bool FindDevice(uint64 id, chromeos::AudioDevice* device); |
61 uint64 GetIdFromStr(const std::string& id_str); | 65 uint64 GetIdFromStr(const std::string& id_str); |
62 | 66 |
63 // List of observers. | 67 // List of observers. |
64 ObserverList<AudioService::Observer> observer_list_; | 68 ObserverList<AudioService::Observer> observer_list_; |
65 | 69 |
66 chromeos::CrasAudioClient* cras_audio_client_; | 70 chromeos::CrasAudioClient* cras_audio_client_; |
67 chromeos::CrasAudioHandler* cras_audio_handler_; | 71 chromeos::CrasAudioHandler* cras_audio_handler_; |
68 | 72 |
69 // Note: This should remain the last member so it'll be destroyed and | 73 // Note: This should remain the last member so it'll be destroyed and |
(...skipping 28 matching lines...) Expand all Loading... |
98 observer_list_.AddObserver(observer); | 102 observer_list_.AddObserver(observer); |
99 } | 103 } |
100 | 104 |
101 void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) { | 105 void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) { |
102 observer_list_.RemoveObserver(observer); | 106 observer_list_.RemoveObserver(observer); |
103 } | 107 } |
104 | 108 |
105 void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) { | 109 void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
107 DCHECK(cras_audio_client_); | 111 DCHECK(cras_audio_client_); |
| 112 // TODO(jennyz,rkc): Replace cras_audio_client_ call with CrasAudioHandler |
| 113 // Api call. |
108 if (cras_audio_client_) | 114 if (cras_audio_client_) |
109 cras_audio_client_->GetNodes(base::Bind(&AudioServiceImpl::OnGetNodes, | 115 cras_audio_client_->GetNodes(base::Bind(&AudioServiceImpl::OnGetNodes, |
110 weak_ptr_factory_.GetWeakPtr(), | 116 weak_ptr_factory_.GetWeakPtr(), |
111 callback)); | 117 callback), |
| 118 base::Bind(&AudioServiceImpl::OnGetNodesError, |
| 119 weak_ptr_factory_.GetWeakPtr())); |
112 } | 120 } |
113 | 121 |
114 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) { | 122 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) { |
115 DCHECK(cras_audio_handler_); | 123 DCHECK(cras_audio_handler_); |
116 if (!cras_audio_handler_) | 124 if (!cras_audio_handler_) |
117 return; | 125 return; |
118 | 126 |
119 bool input_device_set = false; | 127 bool input_device_set = false; |
120 bool output_device_set = false; | 128 bool output_device_set = false; |
121 | 129 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 input_info.push_back(info); | 196 input_info.push_back(info); |
189 } | 197 } |
190 } | 198 } |
191 } | 199 } |
192 | 200 |
193 DCHECK(!callback.is_null()); | 201 DCHECK(!callback.is_null()); |
194 if (!callback.is_null()) | 202 if (!callback.is_null()) |
195 callback.Run(output_info, input_info, success); | 203 callback.Run(output_info, input_info, success); |
196 } | 204 } |
197 | 205 |
| 206 void AudioServiceImpl::OnGetNodesError(const std::string& error_name, |
| 207 const std::string& error_msg) { |
| 208 } |
| 209 |
198 bool AudioServiceImpl::FindDevice(uint64 id, chromeos::AudioDevice* device) { | 210 bool AudioServiceImpl::FindDevice(uint64 id, chromeos::AudioDevice* device) { |
199 chromeos::AudioDeviceList devices; | 211 chromeos::AudioDeviceList devices; |
200 cras_audio_handler_->GetAudioDevices(&devices); | 212 cras_audio_handler_->GetAudioDevices(&devices); |
201 | 213 |
202 for (size_t i = 0; i < devices.size(); ++i) { | 214 for (size_t i = 0; i < devices.size(); ++i) { |
203 if (devices[i].id == id) { | 215 if (devices[i].id == id) { |
204 *device = devices[i]; | 216 *device = devices[i]; |
205 return true; | 217 return true; |
206 } | 218 } |
207 } | 219 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 258 |
247 void AudioServiceImpl::NotifyDeviceChanged() { | 259 void AudioServiceImpl::NotifyDeviceChanged() { |
248 FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, OnDeviceChanged()); | 260 FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, OnDeviceChanged()); |
249 } | 261 } |
250 | 262 |
251 AudioService* AudioService::CreateInstance() { | 263 AudioService* AudioService::CreateInstance() { |
252 return new AudioServiceImpl; | 264 return new AudioServiceImpl; |
253 } | 265 } |
254 | 266 |
255 } // namespace extensions | 267 } // namespace extensions |
OLD | NEW |