| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/webrtc_audio_private/webrtc_audio_privat
e_api.h" | 5 #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat
e_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | |
| 9 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 12 #include "chrome/browser/extensions/event_router.h" | 11 #include "chrome/browser/extensions/event_router.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "content/public/browser/media_device_id.h" | 14 #include "content/public/browser/media_device_id.h" |
| 16 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 17 #include "extensions/common/error_utils.h" | 16 #include "extensions/common/error_utils.h" |
| 18 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 scoped_ptr<Event> event( | 91 scoped_ptr<Event> event( |
| 93 new Event(kEventName, make_scoped_ptr(new ListValue()).Pass())); | 92 new Event(kEventName, make_scoped_ptr(new ListValue()).Pass())); |
| 94 router->DispatchEventToExtension(extension_id, event.Pass()); | 93 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 95 } | 94 } |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 bool WebrtcAudioPrivateGetSinksFunction::RunImpl() { | 98 bool WebrtcAudioPrivateGetSinksFunction::RunImpl() { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 101 | 100 |
| 102 AudioManager::Get()->GetMessageLoop()->PostTaskAndReply( | 101 AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
| 103 FROM_HERE, | 102 FROM_HERE, |
| 104 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoQuery, this), | 103 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoQuery, this), |
| 105 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this)); | 104 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this)); |
| 106 return true; | 105 return true; |
| 107 } | 106 } |
| 108 | 107 |
| 109 void WebrtcAudioPrivateGetSinksFunction::DoQuery() { | 108 void WebrtcAudioPrivateGetSinksFunction::DoQuery() { |
| 110 DCHECK(AudioManager::Get()->GetMessageLoop()->BelongsToCurrentThread()); | 109 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 111 | 110 |
| 112 AudioDeviceNames device_names; | 111 AudioDeviceNames device_names; |
| 113 AudioManager::Get()->GetAudioOutputDeviceNames(&device_names); | 112 AudioManager::Get()->GetAudioOutputDeviceNames(&device_names); |
| 114 | 113 |
| 115 std::vector<linked_ptr<wap::SinkInfo> > results; | 114 std::vector<linked_ptr<wap::SinkInfo> > results; |
| 116 for (AudioDeviceNames::const_iterator it = device_names.begin(); | 115 for (AudioDeviceNames::const_iterator it = device_names.begin(); |
| 117 it != device_names.end(); | 116 it != device_names.end(); |
| 118 ++it) { | 117 ++it) { |
| 119 linked_ptr<wap::SinkInfo> info(new wap::SinkInfo); | 118 linked_ptr<wap::SinkInfo> info(new wap::SinkInfo); |
| 120 info->sink_id = it->unique_id; | 119 info->sink_id = it->unique_id; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (result.empty()) { | 190 if (result.empty()) { |
| 192 DVLOG(2) << "Received empty ID, replacing with default ID."; | 191 DVLOG(2) << "Received empty ID, replacing with default ID."; |
| 193 result = media::AudioManagerBase::kDefaultDeviceId; | 192 result = media::AudioManagerBase::kDefaultDeviceId; |
| 194 } | 193 } |
| 195 results_.reset(wap::GetActiveSink::Results::Create(result).release()); | 194 results_.reset(wap::GetActiveSink::Results::Create(result).release()); |
| 196 SendResponse(true); | 195 SendResponse(true); |
| 197 } | 196 } |
| 198 | 197 |
| 199 WebrtcAudioPrivateSetActiveSinkFunction:: | 198 WebrtcAudioPrivateSetActiveSinkFunction:: |
| 200 WebrtcAudioPrivateSetActiveSinkFunction() | 199 WebrtcAudioPrivateSetActiveSinkFunction() |
| 201 : message_loop_(base::MessageLoopProxy::current()), | 200 : task_runner_(base::MessageLoopProxy::current()), |
| 202 tab_id_(0), | 201 tab_id_(0), |
| 203 num_remaining_sink_ids_(0) { | 202 num_remaining_sink_ids_(0) { |
| 204 } | 203 } |
| 205 | 204 |
| 206 WebrtcAudioPrivateSetActiveSinkFunction:: | 205 WebrtcAudioPrivateSetActiveSinkFunction:: |
| 207 ~WebrtcAudioPrivateSetActiveSinkFunction() { | 206 ~WebrtcAudioPrivateSetActiveSinkFunction() { |
| 208 } | 207 } |
| 209 | 208 |
| 210 bool WebrtcAudioPrivateSetActiveSinkFunction::RunImpl() { | 209 bool WebrtcAudioPrivateSetActiveSinkFunction::RunImpl() { |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 237 controllers.begin(); | 236 controllers.begin(); |
| 238 for (; it != controllers.end(); ++it) { | 237 for (; it != controllers.end(); ++it) { |
| 239 (*it)->SwitchOutputDevice(sink_id_, base::Bind( | 238 (*it)->SwitchOutputDevice(sink_id_, base::Bind( |
| 240 &WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone, this)); | 239 &WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone, this)); |
| 241 } | 240 } |
| 242 } | 241 } |
| 243 } | 242 } |
| 244 | 243 |
| 245 void WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone() { | 244 void WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone() { |
| 246 if (--num_remaining_sink_ids_ == 0) { | 245 if (--num_remaining_sink_ids_ == 0) { |
| 247 message_loop_->PostTask( | 246 task_runner_->PostTask( |
| 248 FROM_HERE, | 247 FROM_HERE, |
| 249 base::Bind(&WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread, | 248 base::Bind(&WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread, |
| 250 this)); | 249 this)); |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 | 252 |
| 254 void WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread() { | 253 void WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread() { |
| 255 SendResponse(true); | 254 SendResponse(true); |
| 256 } | 255 } |
| 257 | 256 |
| 258 WebrtcAudioPrivateGetAssociatedSinkFunction:: | 257 WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 259 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { | 258 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { |
| 260 } | 259 } |
| 261 | 260 |
| 262 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunImpl() { | 261 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunImpl() { |
| 263 scoped_ptr<wap::GetAssociatedSink::Params> params( | 262 scoped_ptr<wap::GetAssociatedSink::Params> params( |
| 264 wap::GetAssociatedSink::Params::Create(*args_)); | 263 wap::GetAssociatedSink::Params::Create(*args_)); |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 EXTENSION_FUNCTION_VALIDATE(params.get()); | 265 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 267 | 266 |
| 268 base::PostTaskAndReplyWithResult( | 267 base::PostTaskAndReplyWithResult( |
| 269 AudioManager::Get()->GetMessageLoop(), | 268 AudioManager::Get()->GetTaskRunner(), |
| 270 FROM_HERE, | 269 FROM_HERE, |
| 271 base::Bind( | 270 base::Bind( |
| 272 &WebrtcAudioPrivateGetAssociatedSinkFunction::DoWorkOnDeviceThread, | 271 &WebrtcAudioPrivateGetAssociatedSinkFunction::DoWorkOnDeviceThread, |
| 273 this, GURL(params->security_origin), params->source_id_in_origin), | 272 this, GURL(params->security_origin), params->source_id_in_origin), |
| 274 base::Bind( | 273 base::Bind( |
| 275 &WebrtcAudioPrivateGetAssociatedSinkFunction::DoneOnUIThread, | 274 &WebrtcAudioPrivateGetAssociatedSinkFunction::DoneOnUIThread, |
| 276 this)); | 275 this)); |
| 277 | 276 |
| 278 return true; | 277 return true; |
| 279 } | 278 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 310 void WebrtcAudioPrivateGetAssociatedSinkFunction::DoneOnUIThread( | 309 void WebrtcAudioPrivateGetAssociatedSinkFunction::DoneOnUIThread( |
| 311 const std::string& associated_sink_id) { | 310 const std::string& associated_sink_id) { |
| 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 313 | 312 |
| 314 results_.reset( | 313 results_.reset( |
| 315 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); | 314 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); |
| 316 SendResponse(true); | 315 SendResponse(true); |
| 317 } | 316 } |
| 318 | 317 |
| 319 } // namespace extensions | 318 } // namespace extensions |
| OLD | NEW |