OLD | NEW |
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 Loading... |
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 StartRtcEventLogging = |
| 46 api::webrtc_logging_private::StartRtcEventLogging; |
| 47 namespace StopRtcEventLogging = |
| 48 api::webrtc_logging_private::StopRtcEventLogging; |
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 Loading... |
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 Loading... |
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 WebrtcLoggingPrivateFunctionWithTimeLimitedRecordingCallback:: |
134 FireErrorCallback(const std::string& error_message) { | 139 FireErrorCallback(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 WebrtcLoggingPrivateFunctionWithTimeLimitedRecordingCallback::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::TimeLimitedRecordingInfo 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 Loading... |
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 Loading... |
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 Loading... |
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<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
398 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 405 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get( |
| 406 host, |
| 407 WebRtcInternalLogHandlerHost::kWebRtcInternalLogHandlerHostKey)); |
399 | 408 |
400 webrtc_logging_handler_host->StartAudioDebugRecordings( | 409 webrtc_internal_log_handler_host->StartAudioDebugRecordings( |
401 host, base::TimeDelta::FromSeconds(params->seconds), | 410 host, base::TimeDelta::FromSeconds(params->seconds), |
402 base::Bind( | 411 base::Bind( |
403 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, | 412 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, |
404 this), | 413 this), |
405 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: | 414 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: |
406 FireErrorCallback, | 415 FireErrorCallback, |
407 this)); | 416 this)); |
408 return true; | 417 return true; |
409 } | 418 } |
410 | 419 |
411 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { | 420 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { |
412 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 421 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
413 switches::kEnableAudioDebugRecordingsFromExtension)) { | 422 switches::kEnableAudioDebugRecordingsFromExtension)) { |
414 return false; | 423 return false; |
415 } | 424 } |
416 | 425 |
417 scoped_ptr<StopAudioDebugRecordings::Params> params( | 426 scoped_ptr<StopAudioDebugRecordings::Params> params( |
418 StopAudioDebugRecordings::Params::Create(*args_)); | 427 StopAudioDebugRecordings::Params::Create(*args_)); |
419 EXTENSION_FUNCTION_VALIDATE(params.get()); | 428 EXTENSION_FUNCTION_VALIDATE(params.get()); |
420 | 429 |
421 content::RenderProcessHost* host = | 430 content::RenderProcessHost* host = |
422 RphFromRequest(params->request, params->security_origin); | 431 RphFromRequest(params->request, params->security_origin); |
423 if (!host) | 432 if (!host) |
424 return false; | 433 return false; |
425 | 434 |
426 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 435 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
427 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 436 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get( |
| 437 host, |
| 438 WebRtcInternalLogHandlerHost::kWebRtcInternalLogHandlerHostKey)); |
428 | 439 |
429 webrtc_logging_handler_host->StopAudioDebugRecordings( | 440 webrtc_internal_log_handler_host->StopAudioDebugRecordings( |
430 host, | 441 host, |
431 base::Bind( | 442 base::Bind( |
432 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, | 443 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, |
433 this), | 444 this), |
434 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: | 445 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: |
435 FireErrorCallback, | 446 FireErrorCallback, |
436 this)); | 447 this)); |
437 return true; | 448 return true; |
438 } | 449 } |
439 | 450 |
| 451 bool WebrtcLoggingPrivateStartRtcEventLoggingFunction::RunAsync() { |
| 452 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 453 switches::kEnableRtcEventLoggingFromExtension)) { |
| 454 return false; |
| 455 } |
| 456 |
| 457 scoped_ptr<StartRtcEventLogging::Params> params( |
| 458 StartRtcEventLogging::Params::Create(*args_)); |
| 459 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 460 |
| 461 if (params->seconds < 0) { |
| 462 FireErrorCallback("seconds must be greater than or equal to 0"); |
| 463 return true; |
| 464 } |
| 465 |
| 466 content::RenderProcessHost* host = |
| 467 RphFromRequest(params->request, params->security_origin); |
| 468 if (!host) |
| 469 return false; |
| 470 |
| 471 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
| 472 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get( |
| 473 host, |
| 474 WebRtcInternalLogHandlerHost::kWebRtcInternalLogHandlerHostKey)); |
| 475 |
| 476 webrtc_internal_log_handler_host->StartRtcEventLogging( |
| 477 host, base::TimeDelta::FromSeconds(params->seconds), |
| 478 base::Bind( |
| 479 &WebrtcLoggingPrivateStartRtcEventLoggingFunction::FireCallback, |
| 480 this), |
| 481 base::Bind( |
| 482 &WebrtcLoggingPrivateStartRtcEventLoggingFunction::FireErrorCallback, |
| 483 this)); |
| 484 return true; |
| 485 } |
| 486 |
| 487 bool WebrtcLoggingPrivateStopRtcEventLoggingFunction::RunAsync() { |
| 488 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 489 switches::kEnableRtcEventLoggingFromExtension)) { |
| 490 return false; |
| 491 } |
| 492 |
| 493 scoped_ptr<StopRtcEventLogging::Params> params( |
| 494 StopRtcEventLogging::Params::Create(*args_)); |
| 495 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 496 |
| 497 content::RenderProcessHost* host = |
| 498 RphFromRequest(params->request, params->security_origin); |
| 499 if (!host) |
| 500 return false; |
| 501 |
| 502 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
| 503 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get( |
| 504 host, |
| 505 WebRtcInternalLogHandlerHost::kWebRtcInternalLogHandlerHostKey)); |
| 506 |
| 507 webrtc_internal_log_handler_host->StopRtcEventLogging( |
| 508 host, |
| 509 base::Bind( |
| 510 &WebrtcLoggingPrivateStopRtcEventLoggingFunction::FireCallback, |
| 511 this), |
| 512 base::Bind( |
| 513 &WebrtcLoggingPrivateStopRtcEventLoggingFunction::FireErrorCallback, |
| 514 this)); |
| 515 return true; |
| 516 } |
| 517 |
440 } // namespace extensions | 518 } // namespace extensions |
OLD | NEW |