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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 void WebrtcAudioPrivateFunction::InitResourceContext() { | 198 void WebrtcAudioPrivateFunction::InitResourceContext() { |
199 resource_context_ = GetProfile()->GetResourceContext(); | 199 resource_context_ = GetProfile()->GetResourceContext(); |
200 } | 200 } |
201 | 201 |
202 content::ResourceContext* WebrtcAudioPrivateFunction::resource_context() const { | 202 content::ResourceContext* WebrtcAudioPrivateFunction::resource_context() const { |
203 DCHECK(resource_context_); // Did you forget to InitResourceContext()? | 203 DCHECK(resource_context_); // Did you forget to InitResourceContext()? |
204 return resource_context_; | 204 return resource_context_; |
205 } | 205 } |
206 | 206 |
207 bool WebrtcAudioPrivateGetSinksFunction::RunImpl() { | 207 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { |
208 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 208 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
209 | 209 |
210 InitResourceContext(); | 210 InitResourceContext(); |
211 GetOutputDeviceNames(); | 211 GetOutputDeviceNames(); |
212 | 212 |
213 return true; | 213 return true; |
214 } | 214 } |
215 | 215 |
216 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceNames( | 216 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceNames( |
217 scoped_ptr<AudioDeviceNames> raw_ids) { | 217 scoped_ptr<AudioDeviceNames> raw_ids) { |
218 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 218 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
219 | 219 |
220 std::vector<linked_ptr<wap::SinkInfo> > results; | 220 std::vector<linked_ptr<wap::SinkInfo> > results; |
221 for (AudioDeviceNames::const_iterator it = raw_ids->begin(); | 221 for (AudioDeviceNames::const_iterator it = raw_ids->begin(); |
222 it != raw_ids->end(); | 222 it != raw_ids->end(); |
223 ++it) { | 223 ++it) { |
224 linked_ptr<wap::SinkInfo> info(new wap::SinkInfo); | 224 linked_ptr<wap::SinkInfo> info(new wap::SinkInfo); |
225 info->sink_id = CalculateHMACImpl(it->unique_id); | 225 info->sink_id = CalculateHMACImpl(it->unique_id); |
226 info->sink_label = it->device_name; | 226 info->sink_label = it->device_name; |
227 // TODO(joi): Add other parameters. | 227 // TODO(joi): Add other parameters. |
228 results.push_back(info); | 228 results.push_back(info); |
229 } | 229 } |
230 | 230 |
231 // It's safe to directly set the results here (from a thread other | 231 // It's safe to directly set the results here (from a thread other |
232 // than the UI thread, on which an AsyncExtensionFunction otherwise | 232 // than the UI thread, on which an AsyncExtensionFunction otherwise |
233 // normally runs) because there is one instance of this object per | 233 // normally runs) because there is one instance of this object per |
234 // function call, no actor outside of this object is modifying the | 234 // function call, no actor outside of this object is modifying the |
235 // results_ member, and the different method invocations on this | 235 // results_ member, and the different method invocations on this |
236 // object run strictly in sequence; first RunImpl on the UI thread, | 236 // object run strictly in sequence; first RunAsync on the UI thread, |
237 // then DoQuery on the audio IO thread, then DoneOnUIThread on the | 237 // then DoQuery on the audio IO thread, then DoneOnUIThread on the |
238 // UI thread. | 238 // UI thread. |
239 results_.reset(wap::GetSinks::Results::Create(results).release()); | 239 results_.reset(wap::GetSinks::Results::Create(results).release()); |
240 | 240 |
241 BrowserThread::PostTask( | 241 BrowserThread::PostTask( |
242 BrowserThread::UI, | 242 BrowserThread::UI, |
243 FROM_HERE, | 243 FROM_HERE, |
244 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this)); | 244 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this)); |
245 } | 245 } |
246 | 246 |
247 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { | 247 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { |
248 SendResponse(true); | 248 SendResponse(true); |
249 } | 249 } |
250 | 250 |
251 bool WebrtcAudioPrivateGetActiveSinkFunction::RunImpl() { | 251 bool WebrtcAudioPrivateGetActiveSinkFunction::RunAsync() { |
252 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
253 InitResourceContext(); | 253 InitResourceContext(); |
254 | 254 |
255 scoped_ptr<wap::GetActiveSink::Params> params( | 255 scoped_ptr<wap::GetActiveSink::Params> params( |
256 wap::GetActiveSink::Params::Create(*args_)); | 256 wap::GetActiveSink::Params::Create(*args_)); |
257 EXTENSION_FUNCTION_VALIDATE(params.get()); | 257 EXTENSION_FUNCTION_VALIDATE(params.get()); |
258 | 258 |
259 return GetControllerList(params->tab_id); | 259 return GetControllerList(params->tab_id); |
260 } | 260 } |
261 | 261 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 WebrtcAudioPrivateSetActiveSinkFunction:: | 299 WebrtcAudioPrivateSetActiveSinkFunction:: |
300 WebrtcAudioPrivateSetActiveSinkFunction() | 300 WebrtcAudioPrivateSetActiveSinkFunction() |
301 : tab_id_(0), | 301 : tab_id_(0), |
302 num_remaining_sink_ids_(0) { | 302 num_remaining_sink_ids_(0) { |
303 } | 303 } |
304 | 304 |
305 WebrtcAudioPrivateSetActiveSinkFunction:: | 305 WebrtcAudioPrivateSetActiveSinkFunction:: |
306 ~WebrtcAudioPrivateSetActiveSinkFunction() { | 306 ~WebrtcAudioPrivateSetActiveSinkFunction() { |
307 } | 307 } |
308 | 308 |
309 bool WebrtcAudioPrivateSetActiveSinkFunction::RunImpl() { | 309 bool WebrtcAudioPrivateSetActiveSinkFunction::RunAsync() { |
310 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 310 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
311 scoped_ptr<wap::SetActiveSink::Params> params( | 311 scoped_ptr<wap::SetActiveSink::Params> params( |
312 wap::SetActiveSink::Params::Create(*args_)); | 312 wap::SetActiveSink::Params::Create(*args_)); |
313 EXTENSION_FUNCTION_VALIDATE(params.get()); | 313 EXTENSION_FUNCTION_VALIDATE(params.get()); |
314 | 314 |
315 InitResourceContext(); | 315 InitResourceContext(); |
316 | 316 |
317 tab_id_ = params->tab_id; | 317 tab_id_ = params->tab_id; |
318 sink_id_ = params->sink_id; | 318 sink_id_ = params->sink_id; |
319 | 319 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 384 } |
385 | 385 |
386 WebrtcAudioPrivateGetAssociatedSinkFunction:: | 386 WebrtcAudioPrivateGetAssociatedSinkFunction:: |
387 WebrtcAudioPrivateGetAssociatedSinkFunction() { | 387 WebrtcAudioPrivateGetAssociatedSinkFunction() { |
388 } | 388 } |
389 | 389 |
390 WebrtcAudioPrivateGetAssociatedSinkFunction:: | 390 WebrtcAudioPrivateGetAssociatedSinkFunction:: |
391 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { | 391 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { |
392 } | 392 } |
393 | 393 |
394 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunImpl() { | 394 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunAsync() { |
395 params_ = wap::GetAssociatedSink::Params::Create(*args_); | 395 params_ = wap::GetAssociatedSink::Params::Create(*args_); |
396 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
397 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 397 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
398 | 398 |
399 InitResourceContext(); | 399 InitResourceContext(); |
400 | 400 |
401 AudioManager::Get()->GetTaskRunner()->PostTask( | 401 AudioManager::Get()->GetTaskRunner()->PostTask( |
402 FROM_HERE, | 402 FROM_HERE, |
403 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: | 403 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: |
404 GetDevicesOnDeviceThread, this)); | 404 GetDevicesOnDeviceThread, this)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); | 475 results_.reset(wap::GetAssociatedSink::Results::Create("").release()); |
476 } else { | 476 } else { |
477 results_.reset( | 477 results_.reset( |
478 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); | 478 wap::GetAssociatedSink::Results::Create(associated_sink_id).release()); |
479 } | 479 } |
480 | 480 |
481 SendResponse(true); | 481 SendResponse(true); |
482 } | 482 } |
483 | 483 |
484 } // namespace extensions | 484 } // namespace extensions |
OLD | NEW |