Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2781)

Unified Diff: chrome/browser/media/audio_debug_recordings_handler.cc

Issue 1650133002: Start and stop RTC event logs from private extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split the logging handler into one for audio recordings and one for event logs Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/audio_debug_recordings_handler.cc
diff --git a/chrome/browser/media/audio_debug_recordings_handler.cc b/chrome/browser/media/audio_debug_recordings_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a99a43784874e422df8c080aed5fcbdfef46599f
--- /dev/null
+++ b/chrome/browser/media/audio_debug_recordings_handler.cc
@@ -0,0 +1,165 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/audio_debug_recordings_handler.h"
+
+#include <string>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/prefs/pref_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/sys_info.h"
+#include "base/time/time.h"
+#include "chrome/browser/bad_message.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/media/webrtc_log_list.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/channel_info.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_process_host.h"
+#include "net/base/net_util.h"
+#include "net/url_request/url_request_context_getter.h"
+
+using content::BrowserThread;
+
+// Keys used to attach handler to the RenderProcessHost
+const char AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey[] =
+ "kAudioDebugRecordingsHandlerKey";
+
+namespace {
+
+// Returns a path name to be used as prefix for audio debug recordings files.
+base::FilePath GetAudioDebugRecordingsPrefixPath(
+ const base::FilePath& directory,
+ uint64_t audio_debug_recordings_id) {
+ static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings.";
+ return directory.AppendASCII(kAudioDebugRecordingsFilePrefix +
+ base::Int64ToString(audio_debug_recordings_id));
+}
+
+} // namespace
+
+AudioDebugRecordingsHandler::AudioDebugRecordingsHandler(Profile* profile)
+ : profile_(profile),
+ is_audio_debug_recordings_in_progress_(false),
+ current_audio_debug_recordings_id_(0) {
+ DCHECK(profile_);
+}
+
+AudioDebugRecordingsHandler::~AudioDebugRecordingsHandler() {
+ // TODO: Can we check that we dont hold any references to any Javascript
Henrik Grunell 2016/02/23 15:29:10 Did this todo come from WebRtcLoggingHandlerHost?
terelius-chromium 2016/03/02 10:01:09 No, this was based on my interpretation of a comme
Henrik Grunell 2016/03/10 21:33:34 OK. All todos should have a reference. Change to T
+ // callbacks?
+}
+
+void AudioDebugRecordingsHandler::StartAudioDebugRecordings(
+ content::RenderProcessHost* host,
+ base::TimeDelta delay,
+ const TimeLimitedRecordingCallback& callback,
+ const TimeLimitedRecordingErrorCallback& error_callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists,
+ this),
+ base::Bind(&AudioDebugRecordingsHandler::DoStartAudioDebugRecordings,
+ this, host, delay, callback, error_callback));
+}
+
+void AudioDebugRecordingsHandler::StopAudioDebugRecordings(
+ content::RenderProcessHost* host,
+ const TimeLimitedRecordingCallback& callback,
+ const TimeLimitedRecordingErrorCallback& error_callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists,
+ this),
+ base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this,
+ host, true /* manual stop */,
+ current_audio_debug_recordings_id_, callback, error_callback));
+}
+
+base::FilePath AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ base::FilePath log_dir_path =
+ WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath());
+ base::File::Error error;
+ if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) {
+ DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error;
+ return base::FilePath();
+ }
+ return log_dir_path;
+}
+
+void AudioDebugRecordingsHandler::DoStartAudioDebugRecordings(
+ content::RenderProcessHost* host,
+ base::TimeDelta delay,
+ const TimeLimitedRecordingCallback& callback,
+ const TimeLimitedRecordingErrorCallback& error_callback,
+ const base::FilePath& log_directory) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ if (is_audio_debug_recordings_in_progress_) {
+ error_callback.Run("Audio debug recordings already in progress");
+ return;
+ }
+
+ is_audio_debug_recordings_in_progress_ = true;
+ base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
+ log_directory, ++current_audio_debug_recordings_id_);
+ host->EnableAudioDebugRecordings(prefix_path);
+
+ if (delay.is_zero()) {
+ callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
+ false /* not manually stopped */);
+ return;
+ }
+
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this,
+ host, false /* no manual stop */,
+ current_audio_debug_recordings_id_, callback, error_callback,
+ prefix_path),
+ delay);
+}
+
+void AudioDebugRecordingsHandler::DoStopAudioDebugRecordings(
+ content::RenderProcessHost* host,
+ bool is_manual_stop,
+ uint64_t audio_debug_recordings_id,
+ const TimeLimitedRecordingCallback& callback,
+ const TimeLimitedRecordingErrorCallback& error_callback,
+ const base::FilePath& log_directory) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_);
+
+ base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
+ log_directory, audio_debug_recordings_id);
+ // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump.
+ // 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 (audio_debug_recordings_id < current_audio_debug_recordings_id_) {
+ callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
+ is_manual_stop);
+ return;
+ }
+
+ if (!is_audio_debug_recordings_in_progress_) {
+ error_callback.Run("No audio debug recording in progress");
+ return;
+ }
+
+ host->DisableAudioDebugRecordings();
+ is_audio_debug_recordings_in_progress_ = false;
+ callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop);
+}

Powered by Google App Engine
This is Rietveld 408576698