Chromium Code Reviews| Index: chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc |
| diff --git a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc |
| index cefad21fbc903acd54f389614e2064f38613be4d..5c1206d0424e6df8fc111ee57b4f65fb531c60c1 100644 |
| --- a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc |
| +++ b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc |
| @@ -4,13 +4,16 @@ |
| #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.h" |
| +#include "base/command_line.h" |
| #include "base/hash.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/supports_user_data.h" |
| +#include "chrome/browser/download/download_prefs.h" |
| #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| #include "chrome/browser/extensions/extension_tab_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/site_instance.h" |
| @@ -36,6 +39,10 @@ namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; |
| namespace Store = api::webrtc_logging_private::Store; |
| namespace Upload = api::webrtc_logging_private::Upload; |
| namespace UploadStored = api::webrtc_logging_private::UploadStored; |
| +namespace StartAudioDebugRecordings = |
| + api::webrtc_logging_private::StartAudioDebugRecordings; |
| +namespace StopAudioDebugRecordings = |
| + api::webrtc_logging_private::StopAudioDebugRecordings; |
| namespace { |
| std::string HashIdWithOrigin(const std::string& security_origin, |
| @@ -124,6 +131,26 @@ void WebrtcLoggingPrivateFunctionWithUploadCallback::FireCallback( |
| SendResponse(success); |
| } |
| +void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback:: |
| + FireErrorCallback(const std::string& error_message) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + SetError(error_message); |
| + SendResponse(false); |
| +} |
| + |
| +void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback::FireCallback( |
| + const std::string& prefix_path, |
| + bool did_stop, |
| + bool did_manual_stop) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + api::webrtc_logging_private::AudioDebugRecordingsInfo result; |
| + result.prefix_path = prefix_path; |
| + result.did_stop = did_stop; |
| + result.did_manual_stop = did_manual_stop; |
| + SetResult(result.ToValue().release()); |
| + SendResponse(true); |
| +} |
| + |
| bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
| scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params.get()); |
| @@ -348,4 +375,67 @@ bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { |
| return true; |
| } |
| +bool WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::RunAsync() { |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableAudioDebugRecordingsFromExtension)) { |
| + return false; |
| + } |
| + |
| + scoped_ptr<StartAudioDebugRecordings::Params> params( |
| + StartAudioDebugRecordings::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + if (params->seconds < 0) { |
| + FireErrorCallback("seconds must be greater than or equal to 0"); |
|
Marijn Kruisselbrink
2015/12/18 23:40:10
It seems really weird to "asynchronously" return (
Guido Urdaneta
2015/12/19 00:32:42
I'll leave it as it is for consistency with the re
Marijn Kruisselbrink
2015/12/19 00:43:37
In UIThreadExtensionFunction::Run you'd return Res
|
| + return true; |
| + } |
| + |
| + content::RenderProcessHost* host = |
| + RphFromRequest(params->request, params->security_origin); |
| + if (!host) |
| + return false; |
| + |
| + scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| + base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| + |
| + webrtc_logging_handler_host->StartAudioDebugRecordings( |
| + host, base::TimeDelta::FromSeconds(params->seconds), |
| + base::Bind( |
| + &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, |
| + this), |
| + base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: |
| + FireErrorCallback, |
| + this)); |
| + return true; |
| +} |
| + |
| +bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableAudioDebugRecordingsFromExtension)) { |
| + return false; |
| + } |
| + |
| + scoped_ptr<StopAudioDebugRecordings::Params> params( |
| + StopAudioDebugRecordings::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + content::RenderProcessHost* host = |
| + RphFromRequest(params->request, params->security_origin); |
| + if (!host) |
| + return false; |
| + |
| + scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| + base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| + |
| + webrtc_logging_handler_host->StopAudioDebugRecordings( |
| + host, |
| + base::Bind( |
| + &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, |
| + this), |
| + base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: |
| + FireErrorCallback, |
| + this)); |
| + return true; |
| +} |
| + |
| } // namespace extensions |