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

Side by Side 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: Fix bug in current time-limited audio debug recordings. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/audio_debug_recordings_handler.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/command_line.h"
12 #include "base/files/file_util.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/media/webrtc_log_list.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/render_process_host.h"
20
21 using content::BrowserThread;
22
23 // Keys used to attach handler to the RenderProcessHost
24 const char AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey[] =
25 "kAudioDebugRecordingsHandlerKey";
26
27 namespace {
28
29 // Returns a path name to be used as prefix for audio debug recordings files.
30 base::FilePath GetAudioDebugRecordingsPrefixPath(
31 const base::FilePath& directory,
32 uint64_t audio_debug_recordings_id) {
33 static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings.";
34 return directory.AppendASCII(kAudioDebugRecordingsFilePrefix +
35 base::Int64ToString(audio_debug_recordings_id));
36 }
37
38 } // namespace
39
40 AudioDebugRecordingsHandler::AudioDebugRecordingsHandler(Profile* profile)
41 : profile_(profile),
42 is_audio_debug_recordings_in_progress_(false),
43 current_audio_debug_recordings_id_(0) {
44 DCHECK(profile_);
45 }
46
47 AudioDebugRecordingsHandler::~AudioDebugRecordingsHandler() {
48 }
49
50 void AudioDebugRecordingsHandler::StartAudioDebugRecordings(
51 content::RenderProcessHost* host,
52 base::TimeDelta delay,
53 const RecordingDoneCallback& callback,
54 const RecordingErrorCallback& error_callback) {
55 DCHECK(thread_checker_.CalledOnValidThread());
56
57 BrowserThread::PostTaskAndReplyWithResult(
58 BrowserThread::FILE, FROM_HERE,
59 base::Bind(&AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists,
60 this),
61 base::Bind(&AudioDebugRecordingsHandler::DoStartAudioDebugRecordings,
62 this, host, delay, callback, error_callback));
63 }
64
65 void AudioDebugRecordingsHandler::StopAudioDebugRecordings(
66 content::RenderProcessHost* host,
67 const RecordingDoneCallback& callback,
68 const RecordingErrorCallback& error_callback) {
69 DCHECK(thread_checker_.CalledOnValidThread());
70 BrowserThread::PostTaskAndReplyWithResult(
71 BrowserThread::FILE, FROM_HERE,
72 base::Bind(&AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists,
73 this),
74 base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this,
75 host, true /* manual stop */,
tommi (sloooow) - chröme 2016/04/07 12:44:29 nit: we usually don't use these kinds of comments
terelius-chromium 2016/04/13 08:52:05 I added a variable is_manual_stop = true; to make
76 current_audio_debug_recordings_id_, callback, error_callback));
77 }
78
79 base::FilePath AudioDebugRecordingsHandler::GetLogDirectoryAndEnsureExists() {
80 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
81 base::FilePath log_dir_path =
82 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath());
83 base::File::Error error;
84 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) {
85 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error;
86 return base::FilePath();
87 }
88 return log_dir_path;
89 }
90
91 void AudioDebugRecordingsHandler::DoStartAudioDebugRecordings(
92 content::RenderProcessHost* host,
93 base::TimeDelta delay,
94 const RecordingDoneCallback& callback,
95 const RecordingErrorCallback& error_callback,
96 const base::FilePath& log_directory) {
97 DCHECK(thread_checker_.CalledOnValidThread());
98
99 if (is_audio_debug_recordings_in_progress_) {
100 error_callback.Run("Audio debug recordings already in progress");
101 return;
102 }
103
104 is_audio_debug_recordings_in_progress_ = true;
105 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
106 log_directory, ++current_audio_debug_recordings_id_);
107 host->EnableAudioDebugRecordings(prefix_path);
108
109 if (delay.is_zero()) {
110 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
111 false /* not manually stopped */);
112 return;
113 }
114
115 BrowserThread::PostDelayedTask(
116 BrowserThread::UI, FROM_HERE,
117 base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this,
118 host, false /* no manual stop */,
119 current_audio_debug_recordings_id_, callback, error_callback,
120 log_directory),
121 delay);
122 }
123
124 void AudioDebugRecordingsHandler::DoStopAudioDebugRecordings(
125 content::RenderProcessHost* host,
126 bool is_manual_stop,
127 uint64_t audio_debug_recordings_id,
128 const RecordingDoneCallback& callback,
129 const RecordingErrorCallback& error_callback,
130 const base::FilePath& log_directory) {
131 DCHECK(thread_checker_.CalledOnValidThread());
132 DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_);
133
134 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
135 log_directory, audio_debug_recordings_id);
136 // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump.
137 // This could happen in a sequence like:
138 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds.
tommi (sloooow) - chröme 2016/04/07 12:44:29 nit: space after//
terelius-chromium 2016/04/13 08:52:05 Done.
139 // Stop(); // Manually stop dump 1 before 10 seconds;
140 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2.
141 if (audio_debug_recordings_id < current_audio_debug_recordings_id_) {
142 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
143 is_manual_stop);
144 return;
145 }
146
147 if (!is_audio_debug_recordings_in_progress_) {
148 error_callback.Run("No audio debug recording in progress");
149 return;
150 }
151
152 host->DisableAudioDebugRecordings();
153 is_audio_debug_recordings_in_progress_ = false;
154 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop);
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698