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

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: Some comments from tommi 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
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 std::unique_ptr<SetMetaData::Params> params( 159 std::unique_ptr<SetMetaData::Params> params(
155 SetMetaData::Params::Create(*args_)); 160 SetMetaData::Params::Create(*args_));
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 (params->incoming && params->outgoing) 319 (params->incoming && params->outgoing)
315 ? RTP_DUMP_BOTH 320 ? RTP_DUMP_BOTH
316 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); 321 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING);
317 322
318 content::RenderProcessHost* host = 323 content::RenderProcessHost* host =
319 RphFromRequest(params->request, params->security_origin); 324 RphFromRequest(params->request, params->security_origin);
320 if (!host) 325 if (!host)
321 return false; 326 return false;
322 327
323 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 328 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host(
324 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 329 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(
330 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey));
325 331
326 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( 332 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind(
327 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this); 333 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this);
328 334
329 // This call cannot fail. 335 // This call cannot fail.
330 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = 336 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback =
331 host->StartRtpDump(params->incoming, 337 host->StartRtpDump(params->incoming,
332 params->outgoing, 338 params->outgoing,
333 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, 339 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket,
334 webrtc_logging_handler_host)); 340 webrtc_logging_handler_host));
(...skipping 22 matching lines...) Expand all
357 (params->incoming && params->outgoing) 363 (params->incoming && params->outgoing)
358 ? RTP_DUMP_BOTH 364 ? RTP_DUMP_BOTH
359 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); 365 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING);
360 366
361 content::RenderProcessHost* host = 367 content::RenderProcessHost* host =
362 RphFromRequest(params->request, params->security_origin); 368 RphFromRequest(params->request, params->security_origin);
363 if (!host) 369 if (!host)
364 return false; 370 return false;
365 371
366 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 372 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host(
367 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 373 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(
374 host, WebRtcLoggingHandlerHost::kWebRtcLoggingHandlerHostKey));
368 375
369 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( 376 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind(
370 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this); 377 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this);
371 378
372 BrowserThread::PostTask(BrowserThread::IO, 379 BrowserThread::PostTask(BrowserThread::IO,
373 FROM_HERE, 380 FROM_HERE,
374 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, 381 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump,
375 webrtc_logging_handler_host, 382 webrtc_logging_handler_host,
376 type, 383 type,
377 callback)); 384 callback));
(...skipping 13 matching lines...) Expand all
391 if (params->seconds < 0) { 398 if (params->seconds < 0) {
392 FireErrorCallback("seconds must be greater than or equal to 0"); 399 FireErrorCallback("seconds must be greater than or equal to 0");
393 return true; 400 return true;
394 } 401 }
395 402
396 content::RenderProcessHost* host = 403 content::RenderProcessHost* host =
397 RphFromRequest(params->request, params->security_origin); 404 RphFromRequest(params->request, params->security_origin);
398 if (!host) 405 if (!host)
399 return false; 406 return false;
400 407
401 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 408 scoped_refptr<AudioDebugRecordingsHandler> audio_debug_recordings_handler(
402 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 409 base::UserDataAdapter<AudioDebugRecordingsHandler>::Get(
410 host, AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey));
403 411
404 webrtc_logging_handler_host->StartAudioDebugRecordings( 412 audio_debug_recordings_handler->StartAudioDebugRecordings(
405 host, base::TimeDelta::FromSeconds(params->seconds), 413 host, base::TimeDelta::FromSeconds(params->seconds),
406 base::Bind( 414 base::Bind(
407 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, 415 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback,
408 this), 416 this),
409 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: 417 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::
410 FireErrorCallback, 418 FireErrorCallback,
411 this)); 419 this));
412 return true; 420 return true;
413 } 421 }
414 422
415 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { 423 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() {
416 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 424 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
417 switches::kEnableAudioDebugRecordingsFromExtension)) { 425 switches::kEnableAudioDebugRecordingsFromExtension)) {
418 return false; 426 return false;
419 } 427 }
420 428
421 std::unique_ptr<StopAudioDebugRecordings::Params> params( 429 std::unique_ptr<StopAudioDebugRecordings::Params> params(
422 StopAudioDebugRecordings::Params::Create(*args_)); 430 StopAudioDebugRecordings::Params::Create(*args_));
423 EXTENSION_FUNCTION_VALIDATE(params.get()); 431 EXTENSION_FUNCTION_VALIDATE(params.get());
424 432
425 content::RenderProcessHost* host = 433 content::RenderProcessHost* host =
426 RphFromRequest(params->request, params->security_origin); 434 RphFromRequest(params->request, params->security_origin);
427 if (!host) 435 if (!host)
428 return false; 436 return false;
429 437
430 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( 438 scoped_refptr<AudioDebugRecordingsHandler> audio_debug_recordings_handler(
431 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); 439 base::UserDataAdapter<AudioDebugRecordingsHandler>::Get(
440 host, AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey));
432 441
433 webrtc_logging_handler_host->StopAudioDebugRecordings( 442 audio_debug_recordings_handler->StopAudioDebugRecordings(
434 host, 443 host,
435 base::Bind( 444 base::Bind(
436 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, 445 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback,
437 this), 446 this),
438 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: 447 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::
439 FireErrorCallback, 448 FireErrorCallback,
440 this)); 449 this));
441 return true; 450 return true;
442 } 451 }
443 452
453 bool WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::RunAsync() {
454 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
455 switches::kEnableWebRtcEventLoggingFromExtension)) {
456 return false;
457 }
458
459 scoped_ptr<StartWebRtcEventLogging::Params> params(
460 StartWebRtcEventLogging::Params::Create(*args_));
461 EXTENSION_FUNCTION_VALIDATE(params.get());
462
463 if (params->seconds < 0) {
464 FireErrorCallback("seconds must be greater than or equal to 0");
465 return true;
466 }
467
468 content::RenderProcessHost* host =
469 RphFromRequest(params->request, params->security_origin);
470 if (!host)
471 return false;
472
473 scoped_refptr<WebRtcEventLogHandler> webrtc_event_log_handler(
474 base::UserDataAdapter<WebRtcEventLogHandler>::Get(
475 host, WebRtcEventLogHandler::kWebRtcEventLogHandlerKey));
476
477 webrtc_event_log_handler->StartWebRtcEventLogging(
478 host, base::TimeDelta::FromSeconds(params->seconds),
479 base::Bind(
480 &WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::FireCallback,
481 this),
482 base::Bind(
483 &WebrtcLoggingPrivateStartWebRtcEventLoggingFunction::FireErrorCallback,
484 this));
485 return true;
486 }
487
488 bool WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::RunAsync() {
489 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
490 switches::kEnableWebRtcEventLoggingFromExtension)) {
491 return false;
492 }
493
494 scoped_ptr<StopWebRtcEventLogging::Params> params(
495 StopWebRtcEventLogging::Params::Create(*args_));
496 EXTENSION_FUNCTION_VALIDATE(params.get());
497
498 content::RenderProcessHost* host =
499 RphFromRequest(params->request, params->security_origin);
500 if (!host)
501 return false;
502
503 scoped_refptr<WebRtcEventLogHandler> webrtc_event_log_handler(
504 base::UserDataAdapter<WebRtcEventLogHandler>::Get(
505 host, WebRtcEventLogHandler::kWebRtcEventLogHandlerKey));
506
507 webrtc_event_log_handler->StopWebRtcEventLogging(
508 host,
509 base::Bind(
510 &WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::FireCallback,
511 this),
512 base::Bind(
513 &WebrtcLoggingPrivateStopWebRtcEventLoggingFunction::FireErrorCallback,
514 this));
515 return true;
516 }
517
444 } // namespace extensions 518 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698