Chromium Code Reviews| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 if (success) { | 127 if (success) { |
| 124 api::webrtc_logging_private::UploadResult result; | 128 api::webrtc_logging_private::UploadResult result; |
| 125 result.report_id = report_id; | 129 result.report_id = report_id; |
| 126 SetResult(result.ToValue().release()); | 130 SetResult(result.ToValue().release()); |
| 127 } else { | 131 } else { |
| 128 SetError(error_message); | 132 SetError(error_message); |
| 129 } | 133 } |
| 130 SendResponse(success); | 134 SendResponse(success); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback:: | 137 void WebrtcLoggingPrivateFunctionWithTimeLimitedRecordingCallback:: |
| 134 FireErrorCallback(const std::string& error_message) { | 138 FireErrorCallback(const std::string& error_message) { |
| 135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 136 SetError(error_message); | 140 SetError(error_message); |
| 137 SendResponse(false); | 141 SendResponse(false); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback::FireCallback( | 144 void WebrtcLoggingPrivateFunctionWithTimeLimitedRecordingCallback::FireCallback( |
| 141 const std::string& prefix_path, | 145 const std::string& prefix_path, |
| 142 bool did_stop, | 146 bool did_stop, |
| 143 bool did_manual_stop) { | 147 bool did_manual_stop) { |
| 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 145 api::webrtc_logging_private::AudioDebugRecordingsInfo result; | 149 api::webrtc_logging_private::TimeLimitedRecordingInfo result; |
| 146 result.prefix_path = prefix_path; | 150 result.prefix_path = prefix_path; |
| 147 result.did_stop = did_stop; | 151 result.did_stop = did_stop; |
| 148 result.did_manual_stop = did_manual_stop; | 152 result.did_manual_stop = did_manual_stop; |
| 149 SetResult(result.ToValue().release()); | 153 SetResult(result.ToValue().release()); |
| 150 SendResponse(true); | 154 SendResponse(true); |
| 151 } | 155 } |
| 152 | 156 |
| 153 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { | 157 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
| 154 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | 158 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
| 155 EXTENSION_FUNCTION_VALIDATE(params.get()); | 159 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 if (params->seconds < 0) { | 391 if (params->seconds < 0) { |
| 388 FireErrorCallback("seconds must be greater than or equal to 0"); | 392 FireErrorCallback("seconds must be greater than or equal to 0"); |
| 389 return true; | 393 return true; |
| 390 } | 394 } |
| 391 | 395 |
| 392 content::RenderProcessHost* host = | 396 content::RenderProcessHost* host = |
| 393 RphFromRequest(params->request, params->security_origin); | 397 RphFromRequest(params->request, params->security_origin); |
| 394 if (!host) | 398 if (!host) |
| 395 return false; | 399 return false; |
| 396 | 400 |
| 397 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 401 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
| 398 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 402 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get(host, host)); |
| 399 | 403 |
| 400 webrtc_logging_handler_host->StartAudioDebugRecordings( | 404 webrtc_internal_log_handler_host->StartAudioDebugRecordings( |
| 401 host, base::TimeDelta::FromSeconds(params->seconds), | 405 host, base::TimeDelta::FromSeconds(params->seconds), |
| 402 base::Bind( | 406 base::Bind( |
| 403 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, | 407 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, |
| 404 this), | 408 this), |
| 405 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: | 409 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: |
| 406 FireErrorCallback, | 410 FireErrorCallback, |
| 407 this)); | 411 this)); |
| 408 return true; | 412 return true; |
| 409 } | 413 } |
| 410 | 414 |
| 411 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { | 415 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { |
| 412 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 416 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 413 switches::kEnableAudioDebugRecordingsFromExtension)) { | 417 switches::kEnableAudioDebugRecordingsFromExtension)) { |
| 414 return false; | 418 return false; |
| 415 } | 419 } |
| 416 | 420 |
| 417 scoped_ptr<StopAudioDebugRecordings::Params> params( | 421 scoped_ptr<StopAudioDebugRecordings::Params> params( |
| 418 StopAudioDebugRecordings::Params::Create(*args_)); | 422 StopAudioDebugRecordings::Params::Create(*args_)); |
| 419 EXTENSION_FUNCTION_VALIDATE(params.get()); | 423 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 420 | 424 |
| 421 content::RenderProcessHost* host = | 425 content::RenderProcessHost* host = |
| 422 RphFromRequest(params->request, params->security_origin); | 426 RphFromRequest(params->request, params->security_origin); |
| 423 if (!host) | 427 if (!host) |
| 424 return false; | 428 return false; |
| 425 | 429 |
| 426 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 430 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( |
| 427 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 431 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get(host, host)); |
| 428 | 432 |
| 429 webrtc_logging_handler_host->StopAudioDebugRecordings( | 433 webrtc_internal_log_handler_host->StopAudioDebugRecordings( |
| 430 host, | 434 host, |
| 431 base::Bind( | 435 base::Bind( |
| 432 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, | 436 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, |
| 433 this), | 437 this), |
| 434 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: | 438 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: |
| 435 FireErrorCallback, | 439 FireErrorCallback, |
| 436 this)); | 440 this)); |
| 437 return true; | 441 return true; |
| 438 } | 442 } |
| 439 | 443 |
| 444 bool WebrtcLoggingPrivateStartRtcEventLoggingFunction::RunAsync() { | |
| 445 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 446 switches::kEnableRtcEventLoggingFromExtension)) { | |
|
tommi (sloooow) - chröme
2016/02/05 11:09:00
Is there information about when this switch will b
terelius1
2016/02/16 20:09:12
Extra privacy protection. See previous comments an
| |
| 447 return false; | |
| 448 } | |
| 449 | |
| 450 scoped_ptr<StartRtcEventLogging::Params> params( | |
| 451 StartRtcEventLogging::Params::Create(*args_)); | |
| 452 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 453 | |
| 454 if (params->seconds < 0) { | |
| 455 FireErrorCallback("seconds must be greater than or equal to 0"); | |
| 456 return true; | |
| 457 } | |
| 458 | |
| 459 content::RenderProcessHost* host = | |
| 460 RphFromRequest(params->request, params->security_origin); | |
| 461 if (!host) | |
| 462 return false; | |
| 463 | |
| 464 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( | |
| 465 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get(host, host)); | |
| 466 | |
| 467 webrtc_internal_log_handler_host->StartRtcEventLogging( | |
| 468 host, base::TimeDelta::FromSeconds(params->seconds), | |
| 469 base::Bind( | |
| 470 &WebrtcLoggingPrivateStartRtcEventLoggingFunction::FireCallback, | |
| 471 this), | |
| 472 base::Bind( | |
| 473 &WebrtcLoggingPrivateStartRtcEventLoggingFunction::FireErrorCallback, | |
| 474 this)); | |
| 475 return true; | |
| 476 } | |
| 477 | |
| 478 bool WebrtcLoggingPrivateStopRtcEventLoggingFunction::RunAsync() { | |
| 479 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 480 switches::kEnableRtcEventLoggingFromExtension)) { | |
| 481 return false; | |
| 482 } | |
| 483 | |
| 484 scoped_ptr<StopRtcEventLogging::Params> params( | |
| 485 StopRtcEventLogging::Params::Create(*args_)); | |
| 486 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 487 | |
| 488 content::RenderProcessHost* host = | |
| 489 RphFromRequest(params->request, params->security_origin); | |
| 490 if (!host) | |
| 491 return false; | |
| 492 | |
| 493 scoped_refptr<WebRtcInternalLogHandlerHost> webrtc_internal_log_handler_host( | |
| 494 base::UserDataAdapter<WebRtcInternalLogHandlerHost>::Get(host, host)); | |
| 495 | |
| 496 webrtc_internal_log_handler_host->StopRtcEventLogging( | |
| 497 host, | |
| 498 base::Bind(&WebrtcLoggingPrivateStopRtcEventLoggingFunction::FireCallback, | |
|
tommi (sloooow) - chröme
2016/02/05 11:09:00
nit: use the same way of wrapping as you do two li
terelius1
2016/02/16 20:09:12
Done.
| |
| 499 this), | |
| 500 base::Bind( | |
| 501 &WebrtcLoggingPrivateStopRtcEventLoggingFunction::FireErrorCallback, | |
| 502 this)); | |
| 503 return true; | |
| 504 } | |
| 505 | |
| 440 } // namespace extensions | 506 } // namespace extensions |
| OLD | NEW |