| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 WebrtcAudioPrivateFunction::~WebrtcAudioPrivateFunction() { | 111 WebrtcAudioPrivateFunction::~WebrtcAudioPrivateFunction() { |
| 112 } | 112 } |
| 113 | 113 |
| 114 void WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions() { | 114 void WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions() { |
| 115 scoped_refptr<base::SingleThreadTaskRunner> audio_manager_runner = | 115 scoped_refptr<base::SingleThreadTaskRunner> audio_manager_runner = |
| 116 AudioManager::Get()->GetTaskRunner(); | 116 AudioManager::Get()->GetTaskRunner(); |
| 117 if (!audio_manager_runner->BelongsToCurrentThread()) { | 117 if (!audio_manager_runner->BelongsToCurrentThread()) { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 audio_manager_runner->PostTask( | 119 audio_manager_runner->PostTask( |
| 120 FROM_HERE, | 120 FROM_HERE, |
| 121 base::Bind(&WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions, | 121 base::BindOnce(&WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions, |
| 122 this)); | 122 this)); |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 | 125 |
| 126 std::unique_ptr<AudioDeviceDescriptions> device_descriptions = | 126 std::unique_ptr<AudioDeviceDescriptions> device_descriptions = |
| 127 base::MakeUnique<AudioDeviceDescriptions>(); | 127 base::MakeUnique<AudioDeviceDescriptions>(); |
| 128 AudioManager::Get()->GetAudioOutputDeviceDescriptions( | 128 AudioManager::Get()->GetAudioOutputDeviceDescriptions( |
| 129 device_descriptions.get()); | 129 device_descriptions.get()); |
| 130 | 130 |
| 131 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
| 132 BrowserThread::IO, FROM_HERE, | 132 BrowserThread::IO, FROM_HERE, |
| 133 base::Bind(&WebrtcAudioPrivateFunction::OnOutputDeviceDescriptions, this, | 133 base::BindOnce(&WebrtcAudioPrivateFunction::OnOutputDeviceDescriptions, |
| 134 base::Passed(&device_descriptions))); | 134 this, base::Passed(&device_descriptions))); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void WebrtcAudioPrivateFunction::OnOutputDeviceDescriptions( | 137 void WebrtcAudioPrivateFunction::OnOutputDeviceDescriptions( |
| 138 std::unique_ptr<AudioDeviceDescriptions> device_descriptions) { | 138 std::unique_ptr<AudioDeviceDescriptions> device_descriptions) { |
| 139 NOTREACHED(); | 139 NOTREACHED(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool WebrtcAudioPrivateFunction::GetControllerList(const RequestInfo& request) { | 142 bool WebrtcAudioPrivateFunction::GetControllerList(const RequestInfo& request) { |
| 143 content::RenderProcessHost* rph = nullptr; | 143 content::RenderProcessHost* rph = nullptr; |
| 144 | 144 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 void WebrtcAudioPrivateFunction::OnControllerList( | 172 void WebrtcAudioPrivateFunction::OnControllerList( |
| 173 const content::RenderProcessHost::AudioOutputControllerList& list) { | 173 const content::RenderProcessHost::AudioOutputControllerList& list) { |
| 174 NOTREACHED(); | 174 NOTREACHED(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void WebrtcAudioPrivateFunction::CalculateHMAC(const std::string& raw_id) { | 177 void WebrtcAudioPrivateFunction::CalculateHMAC(const std::string& raw_id) { |
| 178 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 178 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 179 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
| 180 BrowserThread::IO, | 180 BrowserThread::IO, FROM_HERE, |
| 181 FROM_HERE, | 181 base::BindOnce(&WebrtcAudioPrivateFunction::CalculateHMAC, this, |
| 182 base::Bind(&WebrtcAudioPrivateFunction::CalculateHMAC, this, raw_id)); | 182 raw_id)); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 std::string hmac = CalculateHMACImpl(raw_id); | 186 std::string hmac = CalculateHMACImpl(raw_id); |
| 187 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
| 188 BrowserThread::UI, | 188 BrowserThread::UI, FROM_HERE, |
| 189 FROM_HERE, | 189 base::BindOnce(&WebrtcAudioPrivateFunction::OnHMACCalculated, this, |
| 190 base::Bind(&WebrtcAudioPrivateFunction::OnHMACCalculated, this, hmac)); | 190 hmac)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void WebrtcAudioPrivateFunction::OnHMACCalculated(const std::string& hmac) { | 193 void WebrtcAudioPrivateFunction::OnHMACCalculated(const std::string& hmac) { |
| 194 NOTREACHED(); | 194 NOTREACHED(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 std::string WebrtcAudioPrivateFunction::CalculateHMACImpl( | 197 std::string WebrtcAudioPrivateFunction::CalculateHMACImpl( |
| 198 const std::string& raw_id) { | 198 const std::string& raw_id) { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 200 | 200 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // than the UI thread, on which an AsyncExtensionFunction otherwise | 282 // than the UI thread, on which an AsyncExtensionFunction otherwise |
| 283 // normally runs) because there is one instance of this object per | 283 // normally runs) because there is one instance of this object per |
| 284 // function call, no actor outside of this object is modifying the | 284 // function call, no actor outside of this object is modifying the |
| 285 // results_ member, and the different method invocations on this | 285 // results_ member, and the different method invocations on this |
| 286 // object run strictly in sequence; first RunAsync on the UI thread, | 286 // object run strictly in sequence; first RunAsync on the UI thread, |
| 287 // then DoQuery on the audio IO thread, then DoneOnUIThread on the | 287 // then DoQuery on the audio IO thread, then DoneOnUIThread on the |
| 288 // UI thread. | 288 // UI thread. |
| 289 results_ = wap::GetSinks::Results::Create(results); | 289 results_ = wap::GetSinks::Results::Create(results); |
| 290 | 290 |
| 291 BrowserThread::PostTask( | 291 BrowserThread::PostTask( |
| 292 BrowserThread::UI, | 292 BrowserThread::UI, FROM_HERE, |
| 293 FROM_HERE, | 293 base::BindOnce(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, |
| 294 base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this)); | 294 this)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { | 297 void WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread() { |
| 298 SendResponse(true); | 298 SendResponse(true); |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool WebrtcAudioPrivateGetActiveSinkFunction::RunAsync() { | 301 bool WebrtcAudioPrivateGetActiveSinkFunction::RunAsync() { |
| 302 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 302 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 303 InitDeviceIDSalt(); | 303 InitDeviceIDSalt(); |
| 304 | 304 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 controllers_.begin(); | 432 controllers_.begin(); |
| 433 for (; it != controllers_.end(); ++it) { | 433 for (; it != controllers_.end(); ++it) { |
| 434 (*it)->SwitchOutputDevice(raw_sink_id, base::Bind( | 434 (*it)->SwitchOutputDevice(raw_sink_id, base::Bind( |
| 435 &WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone, this)); | 435 &WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone, this)); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 void WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone() { | 439 void WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone() { |
| 440 if (--num_remaining_sink_ids_ == 0) { | 440 if (--num_remaining_sink_ids_ == 0) { |
| 441 BrowserThread::PostTask( | 441 BrowserThread::PostTask( |
| 442 BrowserThread::UI, | 442 BrowserThread::UI, FROM_HERE, |
| 443 FROM_HERE, | 443 base::BindOnce(&WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread, |
| 444 base::Bind(&WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread, | 444 this)); |
| 445 this)); | |
| 446 } | 445 } |
| 447 } | 446 } |
| 448 | 447 |
| 449 void WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread() { | 448 void WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread() { |
| 450 SendResponse(true); | 449 SendResponse(true); |
| 451 } | 450 } |
| 452 | 451 |
| 453 WebrtcAudioPrivateGetAssociatedSinkFunction:: | 452 WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 454 WebrtcAudioPrivateGetAssociatedSinkFunction() { | 453 WebrtcAudioPrivateGetAssociatedSinkFunction() { |
| 455 } | 454 } |
| 456 | 455 |
| 457 WebrtcAudioPrivateGetAssociatedSinkFunction:: | 456 WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 458 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { | 457 ~WebrtcAudioPrivateGetAssociatedSinkFunction() { |
| 459 } | 458 } |
| 460 | 459 |
| 461 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunAsync() { | 460 bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunAsync() { |
| 462 params_ = wap::GetAssociatedSink::Params::Create(*args_); | 461 params_ = wap::GetAssociatedSink::Params::Create(*args_); |
| 463 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 462 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 464 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 463 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 465 | 464 |
| 466 InitDeviceIDSalt(); | 465 InitDeviceIDSalt(); |
| 467 | 466 |
| 468 AudioManager::Get()->GetTaskRunner()->PostTask( | 467 AudioManager::Get()->GetTaskRunner()->PostTask( |
| 469 FROM_HERE, | 468 FROM_HERE, base::BindOnce(&WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 470 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: | 469 GetDevicesOnDeviceThread, |
| 471 GetDevicesOnDeviceThread, this)); | 470 this)); |
| 472 | 471 |
| 473 return true; | 472 return true; |
| 474 } | 473 } |
| 475 | 474 |
| 476 void WebrtcAudioPrivateGetAssociatedSinkFunction::GetDevicesOnDeviceThread() { | 475 void WebrtcAudioPrivateGetAssociatedSinkFunction::GetDevicesOnDeviceThread() { |
| 477 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 476 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 478 AudioManager::Get()->GetAudioInputDeviceDescriptions(&source_devices_); | 477 AudioManager::Get()->GetAudioInputDeviceDescriptions(&source_devices_); |
| 479 | 478 |
| 480 BrowserThread::PostTask( | 479 BrowserThread::PostTask( |
| 481 BrowserThread::IO, | 480 BrowserThread::IO, FROM_HERE, |
| 482 FROM_HERE, | 481 base::BindOnce(&WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 483 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: | 482 GetRawSourceIDOnIOThread, |
| 484 GetRawSourceIDOnIOThread, | 483 this)); |
| 485 this)); | |
| 486 } | 484 } |
| 487 | 485 |
| 488 void | 486 void |
| 489 WebrtcAudioPrivateGetAssociatedSinkFunction::GetRawSourceIDOnIOThread() { | 487 WebrtcAudioPrivateGetAssociatedSinkFunction::GetRawSourceIDOnIOThread() { |
| 490 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 488 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 491 | 489 |
| 492 url::Origin security_origin(GURL(params_->security_origin)); | 490 url::Origin security_origin(GURL(params_->security_origin)); |
| 493 std::string source_id_in_origin(params_->source_id_in_origin); | 491 std::string source_id_in_origin(params_->source_id_in_origin); |
| 494 | 492 |
| 495 // Find the raw source ID for source_id_in_origin. | 493 // Find the raw source ID for source_id_in_origin. |
| 496 std::string raw_source_id; | 494 std::string raw_source_id; |
| 497 for (AudioDeviceDescriptions::const_iterator it = source_devices_.begin(); | 495 for (AudioDeviceDescriptions::const_iterator it = source_devices_.begin(); |
| 498 it != source_devices_.end(); ++it) { | 496 it != source_devices_.end(); ++it) { |
| 499 const std::string& id = it->unique_id; | 497 const std::string& id = it->unique_id; |
| 500 if (content::DoesMediaDeviceIDMatchHMAC(device_id_salt(), security_origin, | 498 if (content::DoesMediaDeviceIDMatchHMAC(device_id_salt(), security_origin, |
| 501 source_id_in_origin, id)) { | 499 source_id_in_origin, id)) { |
| 502 raw_source_id = id; | 500 raw_source_id = id; |
| 503 DVLOG(2) << "Found raw ID " << raw_source_id | 501 DVLOG(2) << "Found raw ID " << raw_source_id |
| 504 << " for source ID in origin " << source_id_in_origin; | 502 << " for source ID in origin " << source_id_in_origin; |
| 505 break; | 503 break; |
| 506 } | 504 } |
| 507 } | 505 } |
| 508 | 506 |
| 509 AudioManager::Get()->GetTaskRunner()->PostTask( | 507 AudioManager::Get()->GetTaskRunner()->PostTask( |
| 510 FROM_HERE, | 508 FROM_HERE, base::BindOnce(&WebrtcAudioPrivateGetAssociatedSinkFunction:: |
| 511 base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction:: | 509 GetAssociatedSinkOnDeviceThread, |
| 512 GetAssociatedSinkOnDeviceThread, | 510 this, raw_source_id)); |
| 513 this, | |
| 514 raw_source_id)); | |
| 515 } | 511 } |
| 516 | 512 |
| 517 void | 513 void |
| 518 WebrtcAudioPrivateGetAssociatedSinkFunction::GetAssociatedSinkOnDeviceThread( | 514 WebrtcAudioPrivateGetAssociatedSinkFunction::GetAssociatedSinkOnDeviceThread( |
| 519 const std::string& raw_source_id) { | 515 const std::string& raw_source_id) { |
| 520 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 516 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 521 | 517 |
| 522 // We return an empty string if there is no associated output device. | 518 // We return an empty string if there is no associated output device. |
| 523 std::string raw_sink_id; | 519 std::string raw_sink_id; |
| 524 if (!raw_source_id.empty()) { | 520 if (!raw_source_id.empty()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 560 } |
| 565 | 561 |
| 566 host->SetEchoCanceller3(*params->audio_experiments.enable_aec3); | 562 host->SetEchoCanceller3(*params->audio_experiments.enable_aec3); |
| 567 } | 563 } |
| 568 | 564 |
| 569 SendResponse(true); | 565 SendResponse(true); |
| 570 return true; | 566 return true; |
| 571 } | 567 } |
| 572 | 568 |
| 573 } // namespace extensions | 569 } // namespace extensions |
| OLD | NEW |