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

Side by Side Diff: chrome/browser/media/webrtc_rtp_dump_handler.cc

Issue 1099803003: [chrome/browser/media] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build issue Created 5 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
« no previous file with comments | « chrome/browser/media/webrtc_logging_handler_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media/webrtc_rtp_dump_handler.h" 5 #include "chrome/browser/media/webrtc_rtp_dump_handler.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/media/webrtc_rtp_dump_writer.h" 11 #include "chrome/browser/media/webrtc_rtp_dump_writer.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace { 16 namespace {
17 17
18 static const size_t kMaxOngoingRtpDumpsAllowed = 5; 18 static const size_t kMaxOngoingRtpDumpsAllowed = 5;
19 19
20 // The browser process wide total number of ongoing (i.e. started and not 20 // The browser process wide total number of ongoing (i.e. started and not
21 // released) RTP dumps. Incoming and outgoing in one WebRtcDumpHandler are 21 // released) RTP dumps. Incoming and outgoing in one WebRtcDumpHandler are
22 // counted as one dump. 22 // counted as one dump.
23 // Must be accessed on the browser IO thread. 23 // Must be accessed on the browser IO thread.
24 static size_t g_ongoing_rtp_dumps = 0; 24 static size_t g_ongoing_rtp_dumps = 0;
25 25
26 void FireGenericDoneCallback( 26 void FireGenericDoneCallback(
27 const WebRtcRtpDumpHandler::GenericDoneCallback& callback, 27 const WebRtcRtpDumpHandler::GenericDoneCallback& callback,
28 bool success, 28 bool success,
29 const std::string& error_message) { 29 const std::string& error_message) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 30 DCHECK_CURRENTLY_ON(BrowserThread::IO);
31 DCHECK(!callback.is_null()); 31 DCHECK(!callback.is_null());
32 32
33 content::BrowserThread::PostTask( 33 content::BrowserThread::PostTask(
34 content::BrowserThread::UI, 34 content::BrowserThread::UI,
35 FROM_HERE, 35 FROM_HERE,
36 base::Bind(callback, success, error_message)); 36 base::Bind(callback, success, error_message));
37 } 37 }
38 38
39 bool DumpTypeContainsIncoming(RtpDumpType type) { 39 bool DumpTypeContainsIncoming(RtpDumpType type) {
40 return type == RTP_DUMP_INCOMING || type == RTP_DUMP_BOTH; 40 return type == RTP_DUMP_INCOMING || type == RTP_DUMP_BOTH;
41 } 41 }
42 42
43 bool DumpTypeContainsOutgoing(RtpDumpType type) { 43 bool DumpTypeContainsOutgoing(RtpDumpType type) {
44 return type == RTP_DUMP_OUTGOING || type == RTP_DUMP_BOTH; 44 return type == RTP_DUMP_OUTGOING || type == RTP_DUMP_BOTH;
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 WebRtcRtpDumpHandler::WebRtcRtpDumpHandler(const base::FilePath& dump_dir) 49 WebRtcRtpDumpHandler::WebRtcRtpDumpHandler(const base::FilePath& dump_dir)
50 : dump_dir_(dump_dir), 50 : dump_dir_(dump_dir),
51 incoming_state_(STATE_NONE), 51 incoming_state_(STATE_NONE),
52 outgoing_state_(STATE_NONE), 52 outgoing_state_(STATE_NONE),
53 weak_ptr_factory_(this) { 53 weak_ptr_factory_(this) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 54 DCHECK_CURRENTLY_ON(BrowserThread::IO);
55 } 55 }
56 56
57 WebRtcRtpDumpHandler::~WebRtcRtpDumpHandler() { 57 WebRtcRtpDumpHandler::~WebRtcRtpDumpHandler() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 58 DCHECK_CURRENTLY_ON(BrowserThread::IO);
59 59
60 // Reset dump writer first to stop writing. 60 // Reset dump writer first to stop writing.
61 if (dump_writer_) { 61 if (dump_writer_) {
62 --g_ongoing_rtp_dumps; 62 --g_ongoing_rtp_dumps;
63 dump_writer_.reset(); 63 dump_writer_.reset();
64 } 64 }
65 65
66 if (incoming_state_ != STATE_NONE && !incoming_dump_path_.empty()) { 66 if (incoming_state_ != STATE_NONE && !incoming_dump_path_.empty()) {
67 BrowserThread::PostTask( 67 BrowserThread::PostTask(
68 BrowserThread::FILE, 68 BrowserThread::FILE,
69 FROM_HERE, 69 FROM_HERE,
70 base::Bind( 70 base::Bind(
71 base::IgnoreResult(&base::DeleteFile), incoming_dump_path_, false)); 71 base::IgnoreResult(&base::DeleteFile), incoming_dump_path_, false));
72 } 72 }
73 73
74 if (outgoing_state_ != STATE_NONE && !outgoing_dump_path_.empty()) { 74 if (outgoing_state_ != STATE_NONE && !outgoing_dump_path_.empty()) {
75 BrowserThread::PostTask( 75 BrowserThread::PostTask(
76 BrowserThread::FILE, 76 BrowserThread::FILE,
77 FROM_HERE, 77 FROM_HERE,
78 base::Bind( 78 base::Bind(
79 base::IgnoreResult(&base::DeleteFile), outgoing_dump_path_, false)); 79 base::IgnoreResult(&base::DeleteFile), outgoing_dump_path_, false));
80 } 80 }
81 } 81 }
82 82
83 bool WebRtcRtpDumpHandler::StartDump(RtpDumpType type, 83 bool WebRtcRtpDumpHandler::StartDump(RtpDumpType type,
84 std::string* error_message) { 84 std::string* error_message) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 85 DCHECK_CURRENTLY_ON(BrowserThread::IO);
86 86
87 if (!dump_writer_ && g_ongoing_rtp_dumps >= kMaxOngoingRtpDumpsAllowed) { 87 if (!dump_writer_ && g_ongoing_rtp_dumps >= kMaxOngoingRtpDumpsAllowed) {
88 *error_message = "Max RTP dump limit reached."; 88 *error_message = "Max RTP dump limit reached.";
89 DVLOG(2) << *error_message; 89 DVLOG(2) << *error_message;
90 return false; 90 return false;
91 } 91 }
92 92
93 // Returns an error if any type of dump specified by the caller cannot be 93 // Returns an error if any type of dump specified by the caller cannot be
94 // started. 94 // started.
95 if ((DumpTypeContainsIncoming(type) && incoming_state_ != STATE_NONE) || 95 if ((DumpTypeContainsIncoming(type) && incoming_state_ != STATE_NONE) ||
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 kMaxDumpSize, 133 kMaxDumpSize,
134 base::Bind(&WebRtcRtpDumpHandler::OnMaxDumpSizeReached, 134 base::Bind(&WebRtcRtpDumpHandler::OnMaxDumpSizeReached,
135 base::Unretained(this)))); 135 base::Unretained(this))));
136 } 136 }
137 137
138 return true; 138 return true;
139 } 139 }
140 140
141 void WebRtcRtpDumpHandler::StopDump(RtpDumpType type, 141 void WebRtcRtpDumpHandler::StopDump(RtpDumpType type,
142 const GenericDoneCallback& callback) { 142 const GenericDoneCallback& callback) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 143 DCHECK_CURRENTLY_ON(BrowserThread::IO);
144 144
145 // Returns an error if any type of dump specified by the caller cannot be 145 // Returns an error if any type of dump specified by the caller cannot be
146 // stopped. 146 // stopped.
147 if ((DumpTypeContainsIncoming(type) && incoming_state_ != STATE_STARTED) || 147 if ((DumpTypeContainsIncoming(type) && incoming_state_ != STATE_STARTED) ||
148 (DumpTypeContainsOutgoing(type) && outgoing_state_ != STATE_STARTED)) { 148 (DumpTypeContainsOutgoing(type) && outgoing_state_ != STATE_STARTED)) {
149 if (!callback.is_null()) { 149 if (!callback.is_null()) {
150 FireGenericDoneCallback( 150 FireGenericDoneCallback(
151 callback, 151 callback,
152 false, 152 false,
153 "RTP dump not started or already stopped for type " + 153 "RTP dump not started or already stopped for type " +
(...skipping 17 matching lines...) Expand all
171 type, 171 type,
172 base::Bind(&WebRtcRtpDumpHandler::OnDumpEnded, 172 base::Bind(&WebRtcRtpDumpHandler::OnDumpEnded,
173 base::Unretained(this), 173 base::Unretained(this),
174 callback.is_null() 174 callback.is_null()
175 ? base::Closure() 175 ? base::Closure()
176 : base::Bind(&FireGenericDoneCallback, callback, true, ""), 176 : base::Bind(&FireGenericDoneCallback, callback, true, ""),
177 type)); 177 type));
178 } 178 }
179 179
180 bool WebRtcRtpDumpHandler::ReadyToRelease() const { 180 bool WebRtcRtpDumpHandler::ReadyToRelease() const {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 181 DCHECK_CURRENTLY_ON(BrowserThread::IO);
182 182
183 return incoming_state_ != STATE_STARTED && 183 return incoming_state_ != STATE_STARTED &&
184 incoming_state_ != STATE_STOPPING && 184 incoming_state_ != STATE_STOPPING &&
185 outgoing_state_ != STATE_STARTED && outgoing_state_ != STATE_STOPPING; 185 outgoing_state_ != STATE_STARTED && outgoing_state_ != STATE_STOPPING;
186 } 186 }
187 187
188 WebRtcRtpDumpHandler::ReleasedDumps WebRtcRtpDumpHandler::ReleaseDumps() { 188 WebRtcRtpDumpHandler::ReleasedDumps WebRtcRtpDumpHandler::ReleaseDumps() {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 189 DCHECK_CURRENTLY_ON(BrowserThread::IO);
190 DCHECK(ReadyToRelease()); 190 DCHECK(ReadyToRelease());
191 191
192 base::FilePath incoming_dump, outgoing_dump; 192 base::FilePath incoming_dump, outgoing_dump;
193 193
194 if (incoming_state_ == STATE_STOPPED) { 194 if (incoming_state_ == STATE_STOPPED) {
195 DVLOG(2) << "Incoming RTP dumps released: " << incoming_dump_path_.value(); 195 DVLOG(2) << "Incoming RTP dumps released: " << incoming_dump_path_.value();
196 196
197 incoming_state_ = STATE_NONE; 197 incoming_state_ = STATE_NONE;
198 incoming_dump = incoming_dump_path_; 198 incoming_dump = incoming_dump_path_;
199 } 199 }
200 200
201 if (outgoing_state_ == STATE_STOPPED) { 201 if (outgoing_state_ == STATE_STOPPED) {
202 DVLOG(2) << "Outgoing RTP dumps released: " << outgoing_dump_path_.value(); 202 DVLOG(2) << "Outgoing RTP dumps released: " << outgoing_dump_path_.value();
203 203
204 outgoing_state_ = STATE_NONE; 204 outgoing_state_ = STATE_NONE;
205 outgoing_dump = outgoing_dump_path_; 205 outgoing_dump = outgoing_dump_path_;
206 } 206 }
207 return ReleasedDumps(incoming_dump, outgoing_dump); 207 return ReleasedDumps(incoming_dump, outgoing_dump);
208 } 208 }
209 209
210 void WebRtcRtpDumpHandler::OnRtpPacket(const uint8* packet_header, 210 void WebRtcRtpDumpHandler::OnRtpPacket(const uint8* packet_header,
211 size_t header_length, 211 size_t header_length,
212 size_t packet_length, 212 size_t packet_length,
213 bool incoming) { 213 bool incoming) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
215 215
216 if ((incoming && incoming_state_ != STATE_STARTED) || 216 if ((incoming && incoming_state_ != STATE_STARTED) ||
217 (!incoming && outgoing_state_ != STATE_STARTED)) { 217 (!incoming && outgoing_state_ != STATE_STARTED)) {
218 return; 218 return;
219 } 219 }
220 220
221 dump_writer_->WriteRtpPacket( 221 dump_writer_->WriteRtpPacket(
222 packet_header, header_length, packet_length, incoming); 222 packet_header, header_length, packet_length, incoming);
223 } 223 }
224 224
225 void WebRtcRtpDumpHandler::StopOngoingDumps(const base::Closure& callback) { 225 void WebRtcRtpDumpHandler::StopOngoingDumps(const base::Closure& callback) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 DCHECK(!callback.is_null()); 227 DCHECK(!callback.is_null());
228 228
229 // No ongoing dumps, return directly. 229 // No ongoing dumps, return directly.
230 if ((incoming_state_ == STATE_NONE || incoming_state_ == STATE_STOPPED) && 230 if ((incoming_state_ == STATE_NONE || incoming_state_ == STATE_STOPPED) &&
231 (outgoing_state_ == STATE_NONE || outgoing_state_ == STATE_STOPPED)) { 231 (outgoing_state_ == STATE_NONE || outgoing_state_ == STATE_STOPPED)) {
232 callback.Run(); 232 callback.Run();
233 return; 233 return;
234 } 234 }
235 235
236 // If the FILE thread is working on stopping the dumps, wait for the FILE 236 // If the FILE thread is working on stopping the dumps, wait for the FILE
(...skipping 26 matching lines...) Expand all
263 263
264 dump_writer_->EndDump(type, 264 dump_writer_->EndDump(type,
265 base::Bind(&WebRtcRtpDumpHandler::OnDumpEnded, 265 base::Bind(&WebRtcRtpDumpHandler::OnDumpEnded,
266 base::Unretained(this), 266 base::Unretained(this),
267 callback, 267 callback,
268 type)); 268 type));
269 } 269 }
270 270
271 void WebRtcRtpDumpHandler::SetDumpWriterForTesting( 271 void WebRtcRtpDumpHandler::SetDumpWriterForTesting(
272 scoped_ptr<WebRtcRtpDumpWriter> writer) { 272 scoped_ptr<WebRtcRtpDumpWriter> writer) {
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 273 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274 274
275 dump_writer_ = writer.Pass(); 275 dump_writer_ = writer.Pass();
276 ++g_ongoing_rtp_dumps; 276 ++g_ongoing_rtp_dumps;
277 277
278 incoming_dump_path_ = dump_dir_.AppendASCII("recv"); 278 incoming_dump_path_ = dump_dir_.AppendASCII("recv");
279 outgoing_dump_path_ = dump_dir_.AppendASCII("send"); 279 outgoing_dump_path_ = dump_dir_.AppendASCII("send");
280 } 280 }
281 281
282 void WebRtcRtpDumpHandler::OnMaxDumpSizeReached() { 282 void WebRtcRtpDumpHandler::OnMaxDumpSizeReached() {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 283 DCHECK_CURRENTLY_ON(BrowserThread::IO);
284 284
285 RtpDumpType type = 285 RtpDumpType type =
286 (incoming_state_ == STATE_STARTED) 286 (incoming_state_ == STATE_STARTED)
287 ? (outgoing_state_ == STATE_STARTED ? RTP_DUMP_BOTH 287 ? (outgoing_state_ == STATE_STARTED ? RTP_DUMP_BOTH
288 : RTP_DUMP_INCOMING) 288 : RTP_DUMP_INCOMING)
289 : RTP_DUMP_OUTGOING; 289 : RTP_DUMP_OUTGOING;
290 StopDump(type, GenericDoneCallback()); 290 StopDump(type, GenericDoneCallback());
291 } 291 }
292 292
293 void WebRtcRtpDumpHandler::OnDumpEnded(const base::Closure& callback, 293 void WebRtcRtpDumpHandler::OnDumpEnded(const base::Closure& callback,
294 RtpDumpType ended_type, 294 RtpDumpType ended_type,
295 bool incoming_success, 295 bool incoming_success,
296 bool outgoing_success) { 296 bool outgoing_success) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 297 DCHECK_CURRENTLY_ON(BrowserThread::IO);
298 298
299 if (DumpTypeContainsIncoming(ended_type)) { 299 if (DumpTypeContainsIncoming(ended_type)) {
300 DCHECK_EQ(STATE_STOPPING, incoming_state_); 300 DCHECK_EQ(STATE_STOPPING, incoming_state_);
301 incoming_state_ = STATE_STOPPED; 301 incoming_state_ = STATE_STOPPED;
302 302
303 if (!incoming_success) { 303 if (!incoming_success) {
304 BrowserThread::PostTask(BrowserThread::FILE, 304 BrowserThread::PostTask(BrowserThread::FILE,
305 FROM_HERE, 305 FROM_HERE,
306 base::Bind(base::IgnoreResult(&base::DeleteFile), 306 base::Bind(base::IgnoreResult(&base::DeleteFile),
307 incoming_dump_path_, 307 incoming_dump_path_,
(...skipping 26 matching lines...) Expand all
334 if (incoming_state_ != STATE_STOPPING && outgoing_state_ != STATE_STOPPING && 334 if (incoming_state_ != STATE_STOPPING && outgoing_state_ != STATE_STOPPING &&
335 incoming_state_ != STATE_STARTED && outgoing_state_ != STATE_STARTED) { 335 incoming_state_ != STATE_STARTED && outgoing_state_ != STATE_STARTED) {
336 dump_writer_.reset(); 336 dump_writer_.reset();
337 --g_ongoing_rtp_dumps; 337 --g_ongoing_rtp_dumps;
338 } 338 }
339 339
340 // This object might be deleted after running the callback. 340 // This object might be deleted after running the callback.
341 if (!callback.is_null()) 341 if (!callback.is_null())
342 callback.Run(); 342 callback.Run();
343 } 343 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_logging_handler_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698