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

Side by Side Diff: chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.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: Test that the event log actually produces some content Created 4 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h" 5 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 24 matching lines...) Expand all
35 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump; 35 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump;
36 namespace Stop = api::webrtc_logging_private::Stop; 36 namespace Stop = api::webrtc_logging_private::Stop;
37 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; 37 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump;
38 namespace Store = api::webrtc_logging_private::Store; 38 namespace Store = api::webrtc_logging_private::Store;
39 namespace Upload = api::webrtc_logging_private::Upload; 39 namespace Upload = api::webrtc_logging_private::Upload;
40 namespace UploadStored = api::webrtc_logging_private::UploadStored; 40 namespace UploadStored = api::webrtc_logging_private::UploadStored;
41 namespace StartAudioDebugRecordings = 41 namespace StartAudioDebugRecordings =
42 api::webrtc_logging_private::StartAudioDebugRecordings; 42 api::webrtc_logging_private::StartAudioDebugRecordings;
43 namespace StopAudioDebugRecordings = 43 namespace StopAudioDebugRecordings =
44 api::webrtc_logging_private::StopAudioDebugRecordings; 44 api::webrtc_logging_private::StopAudioDebugRecordings;
45 namespace StartWebRtcEventLogging =
46 api::webrtc_logging_private::StartWebRtcEventLogging;
47 namespace StopWebRtcEventLogging =
48 api::webrtc_logging_private::StopWebRtcEventLogging;
45 49
46 namespace { 50 namespace {
47 std::string HashIdWithOrigin(const std::string& security_origin, 51 std::string HashIdWithOrigin(const std::string& security_origin,
48 const std::string& log_id) { 52 const std::string& log_id) {
49 return base::UintToString(base::Hash(security_origin + log_id)); 53 return base::UintToString(base::Hash(security_origin + log_id));
50 } 54 }
51 } // namespace 55 } // namespace
52 56
53 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( 57 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest(
54 const RequestInfo& request, const std::string& security_origin) { 58 const RequestInfo& request, const std::string& security_origin) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 93 }
90 94
91 scoped_refptr<WebRtcLoggingHandlerHost> 95 scoped_refptr<WebRtcLoggingHandlerHost>
92 WebrtcLoggingPrivateFunction::LoggingHandlerFromRequest( 96 WebrtcLoggingPrivateFunction::LoggingHandlerFromRequest(
93 const api::webrtc_logging_private::RequestInfo& request, 97 const api::webrtc_logging_private::RequestInfo& request,
94 const std::string& security_origin) { 98 const std::string& security_origin) {
95 content::RenderProcessHost* host = RphFromRequest(request, security_origin); 99 content::RenderProcessHost* host = RphFromRequest(request, security_origin);
96 if (!host) 100 if (!host)
97 return nullptr; 101 return nullptr;
98 102
99 return base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host); 103 return base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(
104 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey);
100 } 105 }
101 106
102 scoped_refptr<WebRtcLoggingHandlerHost> 107 scoped_refptr<WebRtcLoggingHandlerHost>
103 WebrtcLoggingPrivateFunctionWithGenericCallback::PrepareTask( 108 WebrtcLoggingPrivateFunctionWithGenericCallback::PrepareTask(
104 const RequestInfo& request, const std::string& security_origin, 109 const RequestInfo& request, const std::string& security_origin,
105 WebRtcLoggingHandlerHost::GenericDoneCallback* callback) { 110 WebRtcLoggingHandlerHost::GenericDoneCallback* callback) {
106 *callback = base::Bind( 111 *callback = base::Bind(
107 &WebrtcLoggingPrivateFunctionWithGenericCallback::FireCallback, this); 112 &WebrtcLoggingPrivateFunctionWithGenericCallback::FireCallback, this);
108 return LoggingHandlerFromRequest(request, security_origin); 113 return LoggingHandlerFromRequest(request, security_origin);
109 } 114 }
(...skipping 13 matching lines...) Expand all
123 if (success) { 128 if (success) {
124 api::webrtc_logging_private::UploadResult result; 129 api::webrtc_logging_private::UploadResult result;
125 result.report_id = report_id; 130 result.report_id = report_id;
126 SetResult(result.ToValue().release()); 131 SetResult(result.ToValue().release());
127 } else { 132 } else {
128 SetError(error_message); 133 SetError(error_message);
129 } 134 }
130 SendResponse(success); 135 SendResponse(success);
131 } 136 }
132 137
133 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback:: 138 void WebrtcLoggingPrivateFunctionWithRecordingDoneCallback::FireErrorCallback(
134 FireErrorCallback(const std::string& error_message) { 139 const std::string& error_message) {
135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
136 SetError(error_message); 141 SetError(error_message);
137 SendResponse(false); 142 SendResponse(false);
138 } 143 }
139 144
140 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback::FireCallback( 145 void WebrtcLoggingPrivateFunctionWithRecordingDoneCallback::FireCallback(
141 const std::string& prefix_path, 146 const std::string& prefix_path,
142 bool did_stop, 147 bool did_stop,
143 bool did_manual_stop) { 148 bool did_manual_stop) {
144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
145 api::webrtc_logging_private::AudioDebugRecordingsInfo result; 150 api::webrtc_logging_private::RecordingInfo result;
146 result.prefix_path = prefix_path; 151 result.prefix_path = prefix_path;
147 result.did_stop = did_stop; 152 result.did_stop = did_stop;
148 result.did_manual_stop = did_manual_stop; 153 result.did_manual_stop = did_manual_stop;
149 SetResult(result.ToValue().release()); 154 SetResult(result.ToValue().release());
150 SendResponse(true); 155 SendResponse(true);
151 } 156 }
152 157
153 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { 158 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() {
154 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); 159 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_));
155 EXTENSION_FUNCTION_VALIDATE(params.get()); 160 EXTENSION_FUNCTION_VALIDATE(params.get());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 (params->incoming && params->outgoing) 316 (params->incoming && params->outgoing)
312 ? RTP_DUMP_BOTH 317 ? RTP_DUMP_BOTH
313 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); 318 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING);
314 319
315 content::RenderProcessHost* host = 320 content::RenderProcessHost* host =
316 RphFromRequest(params->request, params->security_origin); 321 RphFromRequest(params->request, params->security_origin);
317 if (!host) 322 if (!host)
318 return false; 323 return false;
319 324
320 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 325 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host(
321 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 326 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(
327 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey));
322 328
323 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( 329 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind(
324 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this); 330 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this);
325 331
326 // This call cannot fail. 332 // This call cannot fail.
327 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = 333 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback =
328 host->StartRtpDump(params->incoming, 334 host->StartRtpDump(params->incoming,
329 params->outgoing, 335 params->outgoing,
330 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, 336 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket,
331 webrtc_logging_handler_host)); 337 webrtc_logging_handler_host));
(...skipping 21 matching lines...) Expand all
353 (params->incoming && params->outgoing) 359 (params->incoming && params->outgoing)
354 ? RTP_DUMP_BOTH 360 ? RTP_DUMP_BOTH
355 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); 361 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING);
356 362
357 content::RenderProcessHost* host = 363 content::RenderProcessHost* host =
358 RphFromRequest(params->request, params->security_origin); 364 RphFromRequest(params->request, params->security_origin);
359 if (!host) 365 if (!host)
360 return false; 366 return false;
361 367
362 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 368 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host(
363 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 369 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(
370 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey));
364 371
365 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( 372 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind(
366 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this); 373 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this);
367 374
368 BrowserThread::PostTask(BrowserThread::IO, 375 BrowserThread::PostTask(BrowserThread::IO,
369 FROM_HERE, 376 FROM_HERE,
370 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, 377 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump,
371 webrtc_logging_handler_host, 378 webrtc_logging_handler_host,
372 type, 379 type,
373 callback)); 380 callback));
(...skipping 13 matching lines...) Expand all
387 if (params->seconds < 0) { 394 if (params->seconds < 0) {
388 FireErrorCallback("seconds must be greater than or equal to 0"); 395 FireErrorCallback("seconds must be greater than or equal to 0");
389 return true; 396 return true;
390 } 397 }
391 398
392 content::RenderProcessHost* host = 399 content::RenderProcessHost* host =
393 RphFromRequest(params->request, params->security_origin); 400 RphFromRequest(params->request, params->security_origin);
394 if (!host) 401 if (!host)
395 return false; 402 return false;
396 403
397 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 404 scoped_refptr<AudioDebugRecordingsHandler> audio_debug_recordings_handler(
398 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 405 base::UserDataAdapter<AudioDebugRecordingsHandler>::Get(
406 host, AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey));
399 407
400 webrtc_logging_handler_host->StartAudioDebugRecordings( 408 audio_debug_recordings_handler->StartAudioDebugRecordings(
401 host, base::TimeDelta::FromSeconds(params->seconds), 409 host, base::TimeDelta::FromSeconds(params->seconds),
402 base::Bind( 410 base::Bind(
403 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, 411 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback,
404 this), 412 this),
405 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: 413 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::
406 FireErrorCallback, 414 FireErrorCallback,
407 this)); 415 this));
408 return true; 416 return true;
409 } 417 }
410 418
411 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { 419 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() {
412 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 420 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
413 switches::kEnableAudioDebugRecordingsFromExtension)) { 421 switches::kEnableAudioDebugRecordingsFromExtension)) {
414 return false; 422 return false;
415 } 423 }
416 424
417 scoped_ptr<StopAudioDebugRecordings::Params> params( 425 scoped_ptr<StopAudioDebugRecordings::Params> params(
418 StopAudioDebugRecordings::Params::Create(*args_)); 426 StopAudioDebugRecordings::Params::Create(*args_));
419 EXTENSION_FUNCTION_VALIDATE(params.get()); 427 EXTENSION_FUNCTION_VALIDATE(params.get());
420 428
421 content::RenderProcessHost* host = 429 content::RenderProcessHost* host =
422 RphFromRequest(params->request, params->security_origin); 430 RphFromRequest(params->request, params->security_origin);
423 if (!host) 431 if (!host)
424 return false; 432 return false;
425 433
426 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 434 scoped_refptr<AudioDebugRecordingsHandler> audio_debug_recordings_handler(
427 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 435 base::UserDataAdapter<AudioDebugRecordingsHandler>::Get(
436 host, AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey));
428 437
429 webrtc_logging_handler_host->StopAudioDebugRecordings( 438 audio_debug_recordings_handler->StopAudioDebugRecordings(
430 host, 439 host,
431 base::Bind( 440 base::Bind(
432 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, 441 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback,
433 this), 442 this),
434 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: 443 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::
435 FireErrorCallback, 444 FireErrorCallback,
436 this)); 445 this));
437 return true; 446 return true;
438 } 447 }
439 448
449 bool WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::RunAsync() {
450 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
451 switches::kEnableWebRtcEventLoggingFromExtension)) {
452 return false;
453 }
454
455 scoped_ptr<StartWebRtcEventLogging::Params> params(
456 StartWebRtcEventLogging::Params::Create(*args_));
457 EXTENSION_FUNCTION_VALIDATE(params.get());
458
459 if (params->seconds < 0) {
460 FireErrorCallback("seconds must be greater than or equal to 0");
461 return true;
462 }
463
464 content::RenderProcessHost* host =
465 RphFromRequest(params->request, params->security_origin);
466 if (!host)
467 return false;
468
469 scoped_refptr<WebRtcEventLogHandler> webrtc_event_log_handler(
470 base::UserDataAdapter<WebRtcEventLogHandler>::Get(
471 host, WebRtcEventLogHandler::kWebRtcEventLogHandlerKey));
472
473 webrtc_event_log_handler->StartWebRtcEventLogging(
474 host, base::TimeDelta::FromSeconds(params->seconds),
475 base::Bind(
476 &WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::FireCallback,
477 this),
478 base::Bind(&WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::
479 FireErrorCallback,
480 this));
481 return true;
482 }
483
484 bool WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::RunAsync() {
485 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
486 switches::kEnableWebRtcEventLoggingFromExtension)) {
487 return false;
488 }
489
490 scoped_ptr<StopWebRtcEventLogging::Params> params(
491 StopWebRtcEventLogging::Params::Create(*args_));
492 EXTENSION_FUNCTION_VALIDATE(params.get());
493
494 content::RenderProcessHost* host =
495 RphFromRequest(params->request, params->security_origin);
496 if (!host)
497 return false;
498
499 scoped_refptr<WebRtcEventLogHandler> webrtc_event_log_handler(
500 base::UserDataAdapter<WebRtcEventLogHandler>::Get(
501 host, WebRtcEventLogHandler::kWebRtcEventLogHandlerKey));
502
503 webrtc_event_log_handler->StopWebRtcEventLogging(
504 host,
505 base::Bind(
506 &WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::FireCallback,
507 this),
508 base::Bind(&WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::
509 FireErrorCallback,
510 this));
511 return true;
512 }
513
440 } // namespace extensions 514 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698