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..fae1f0cf987423329c201fa364d32311ce21ed46 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,12 +39,63 @@ 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 StartAecDump = api::webrtc_logging_private::StartAecDump; |
| +namespace StopAecDump = api::webrtc_logging_private::StopAecDump; |
| namespace { |
| std::string HashIdWithOrigin(const std::string& security_origin, |
| const std::string& log_id) { |
| return base::UintToString(base::Hash(security_origin + log_id)); |
| } |
| + |
| +uint64 current_aec_dump_id = 0; |
| +bool is_dump_in_progress = false; |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
document what thread these variables are used on.
Guido Urdaneta
2015/12/17 14:35:40
Done.
|
| +char kDumpFilePrefix[] = "aecdump."; |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
const
Guido Urdaneta
2015/12/17 14:35:40
Done.
|
| + |
| +// Starts AEC dump and save the files in the |dump_dir| directory, provided |
| +// no dump is in progress. Returns a UTF8 string with the prefix common to all |
| +// files produced by the dump (includes |dump_dir| and dump ID). |
| +// If there is a dump in progress, returns an empty string. |
| +std::string DoStartAecDump(const base::FilePath& dump_dir) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + if (is_dump_in_progress) |
| + return std::string(); |
| + |
| + current_aec_dump_id++; |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
++foo;
Guido Urdaneta
2015/12/17 14:35:40
Done.
|
| + base::FilePath prefix_path = dump_dir.Append( |
| + kDumpFilePrefix + base::Int64ToString(current_aec_dump_id)); |
| + is_dump_in_progress = true; |
| + for (content::RenderProcessHost::iterator i( |
| + content::RenderProcessHost::AllHostsIterator()); |
| + !i.IsAtEnd(); i.Advance()) { |
| + i.GetCurrentValue()->EnableAudioDebugRecordings(prefix_path); |
| + } |
| + |
| + return prefix_path.AsUTF8Unsafe(); |
| +} |
| + |
| +// If |dump_id| is zero or the ID of the current AEC dump, stops the current |
| +// AEC dump. Otherwise, does nothing. |
| +void DoStopAecDump(uint64 dump_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + // Prevent a old posted StopAecDump() call to stop a newer dump. |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
nit: Prevent an old posted StopAecDump() call from
Guido Urdaneta
2015/12/17 14:35:40
Done.
|
| + // This could happen in a sequence like: |
| + // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. |
| + // Stop(); // Manually stop dump 1 before 10 seconds; |
| + // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. |
| + if (dump_id != 0 && dump_id < current_aec_dump_id) |
| + return; |
| + |
| + DCHECK_LE(dump_id, current_aec_dump_id); |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
I don't think this DCHECK will ever hit due to the
Guido Urdaneta
2015/12/17 14:35:42
Moved to the beginning of the function.
|
| + for (content::RenderProcessHost::iterator i( |
| + content::RenderProcessHost::AllHostsIterator()); |
| + !i.IsAtEnd(); i.Advance()) { |
| + i.GetCurrentValue()->DisableAudioDebugRecordings(); |
| + } |
| + |
| + is_dump_in_progress = false; |
| +} |
| } // namespace |
| content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( |
| @@ -124,6 +178,21 @@ void WebrtcLoggingPrivateFunctionWithUploadCallback::FireCallback( |
| SendResponse(success); |
| } |
| +void WebrtcLoggingPrivateFunctionWithAecDumpStartedCallback::FireCallback( |
| + bool success, |
| + const std::string& prefix_path, |
| + const std::string& error_message) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + if (success) { |
| + api::webrtc_logging_private::AecDumpInfo result; |
| + result.prefix_path = prefix_path; |
| + SetResult(result.ToValue().release()); |
| + } else { |
| + SetError(error_message); |
| + } |
| + SendResponse(success); |
| +} |
| + |
| bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
| scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params.get()); |
| @@ -348,4 +417,47 @@ bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { |
| return true; |
| } |
| +bool WebrtcLoggingPrivateStartAecDumpFunction::RunAsync() { |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
do we need some sort of cleanup code here? E.g. d
Guido Urdaneta
2015/12/17 14:35:40
The functions are changed now so that the callback
|
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableAecDumps)) { |
|
tommi (sloooow) - chröme
2015/12/17 11:03:26
can we call the constant kAllowAecDumpsFromExtensi
Guido Urdaneta
2015/12/17 14:35:42
Done.
|
| + return false; |
| + } |
| + |
| + scoped_ptr<StartAecDump::Params> params(StartAecDump::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + if (params->seconds < 0) { |
| + FireCallback(false, std::string(), |
| + "seconds must be greater than or equal to 0"); |
| + return true; |
| + } |
| + |
| + DownloadPrefs download_prefs(GetProfile()); |
| + base::FilePath dump_dir = download_prefs.GetDefaultDownloadDirectory(); |
| + std::string prefix_path = DoStartAecDump(dump_dir); |
| + if (prefix_path.empty()) |
| + FireCallback(false, std::string(), "AEC Dump already in progress"); |
| + else |
| + FireCallback(true, prefix_path, std::string()); |
| + |
| + if (params->seconds > 0) { |
| + BrowserThread::PostDelayedTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&DoStopAecDump, current_aec_dump_id), |
| + base::TimeDelta::FromSeconds(params->seconds)); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool WebrtcLoggingPrivateStopAecDumpFunction::RunAsync() { |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableAecDumps)) { |
| + return false; |
| + } |
| + |
| + DoStopAecDump(0); |
| + FireCallback(true, std::string()); |
| + return true; |
| +} |
| + |
| } // namespace extensions |