| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 7 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
| 8 | 8 |
| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 WebrtcLoggingPrivateStartRtpDumpFunction:: | 272 WebrtcLoggingPrivateStartRtpDumpFunction:: |
| 273 WebrtcLoggingPrivateStartRtpDumpFunction() {} | 273 WebrtcLoggingPrivateStartRtpDumpFunction() {} |
| 274 | 274 |
| 275 WebrtcLoggingPrivateStartRtpDumpFunction:: | 275 WebrtcLoggingPrivateStartRtpDumpFunction:: |
| 276 ~WebrtcLoggingPrivateStartRtpDumpFunction() {} | 276 ~WebrtcLoggingPrivateStartRtpDumpFunction() {} |
| 277 | 277 |
| 278 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { | 278 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { |
| 279 scoped_ptr<StartRtpDump::Params> params(StartRtpDump::Params::Create(*args_)); | 279 scoped_ptr<StartRtpDump::Params> params(StartRtpDump::Params::Create(*args_)); |
| 280 EXTENSION_FUNCTION_VALIDATE(params.get()); | 280 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 281 | 281 |
| 282 if (!params->incoming && !params->outgoing) { |
| 283 StartRtpDumpCallback(false, "Either incoming or outgoing must be true."); |
| 284 return true; |
| 285 } |
| 286 |
| 287 content::RtpDumpType type = |
| 288 (params->incoming && params->outgoing) |
| 289 ? content::RTP_DUMP_BOTH |
| 290 : (params->incoming ? content::RTP_DUMP_INCOMING |
| 291 : content::RTP_DUMP_OUTGOING); |
| 292 |
| 282 content::RenderProcessHost* host = | 293 content::RenderProcessHost* host = |
| 283 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); | 294 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); |
| 284 if (!host) | 295 if (!host) |
| 285 return false; | 296 return false; |
| 286 | 297 |
| 287 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 298 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 288 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 299 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 289 | 300 |
| 290 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 301 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 291 &WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback, this); | 302 &WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback, this); |
| 292 | 303 |
| 304 // This call cannot fail. |
| 305 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = |
| 306 host->StartRtpDump(type, |
| 307 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, |
| 308 webrtc_logging_handler_host)); |
| 309 |
| 293 BrowserThread::PostTask(BrowserThread::IO, | 310 BrowserThread::PostTask(BrowserThread::IO, |
| 294 FROM_HERE, | 311 FROM_HERE, |
| 295 base::Bind(&WebRtcLoggingHandlerHost::StartRtpDump, | 312 base::Bind(&WebRtcLoggingHandlerHost::StartRtpDump, |
| 296 webrtc_logging_handler_host, | 313 webrtc_logging_handler_host, |
| 297 params->incoming, | 314 type, |
| 298 params->outgoing, | 315 callback, |
| 299 callback)); | 316 stop_callback)); |
| 300 | |
| 301 return true; | 317 return true; |
| 302 } | 318 } |
| 303 | 319 |
| 304 void WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback( | 320 void WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback( |
| 305 bool success, | 321 bool success, |
| 306 const std::string& error_message) { | 322 const std::string& error_message) { |
| 307 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 308 if (!success) | 324 if (!success) |
| 309 SetError(error_message); | 325 SetError(error_message); |
| 310 SendResponse(success); | 326 SendResponse(success); |
| 311 } | 327 } |
| 312 | 328 |
| 313 WebrtcLoggingPrivateStopRtpDumpFunction:: | 329 WebrtcLoggingPrivateStopRtpDumpFunction:: |
| 314 WebrtcLoggingPrivateStopRtpDumpFunction() {} | 330 WebrtcLoggingPrivateStopRtpDumpFunction() {} |
| 315 | 331 |
| 316 WebrtcLoggingPrivateStopRtpDumpFunction:: | 332 WebrtcLoggingPrivateStopRtpDumpFunction:: |
| 317 ~WebrtcLoggingPrivateStopRtpDumpFunction() {} | 333 ~WebrtcLoggingPrivateStopRtpDumpFunction() {} |
| 318 | 334 |
| 319 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { | 335 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { |
| 320 scoped_ptr<StopRtpDump::Params> params(StopRtpDump::Params::Create(*args_)); | 336 scoped_ptr<StopRtpDump::Params> params(StopRtpDump::Params::Create(*args_)); |
| 321 EXTENSION_FUNCTION_VALIDATE(params.get()); | 337 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 322 | 338 |
| 339 if (!params->incoming && !params->outgoing) { |
| 340 StopRtpDumpCallback(false, "Either incoming or outgoing must be true."); |
| 341 return true; |
| 342 } |
| 343 |
| 344 content::RtpDumpType type = |
| 345 (params->incoming && params->outgoing) |
| 346 ? content::RTP_DUMP_BOTH |
| 347 : (params->incoming ? content::RTP_DUMP_INCOMING |
| 348 : content::RTP_DUMP_OUTGOING); |
| 349 |
| 323 content::RenderProcessHost* host = | 350 content::RenderProcessHost* host = |
| 324 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); | 351 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); |
| 325 if (!host) | 352 if (!host) |
| 326 return false; | 353 return false; |
| 327 | 354 |
| 328 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 355 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 329 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 356 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 330 | 357 |
| 331 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 358 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 332 &WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback, this); | 359 &WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback, this); |
| 333 | 360 |
| 334 BrowserThread::PostTask(BrowserThread::IO, | 361 BrowserThread::PostTask(BrowserThread::IO, |
| 335 FROM_HERE, | 362 FROM_HERE, |
| 336 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 363 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, |
| 337 webrtc_logging_handler_host, | 364 webrtc_logging_handler_host, |
| 338 params->incoming, | 365 type, |
| 339 params->outgoing, | |
| 340 callback)); | 366 callback)); |
| 341 | |
| 342 return true; | 367 return true; |
| 343 } | 368 } |
| 344 | 369 |
| 345 void WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback( | 370 void WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback( |
| 346 bool success, | 371 bool success, |
| 347 const std::string& error_message) { | 372 const std::string& error_message) { |
| 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 373 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 349 if (!success) | 374 if (!success) |
| 350 SetError(error_message); | 375 SetError(error_message); |
| 351 SendResponse(success); | 376 SendResponse(success); |
| 352 } | 377 } |
| 353 | 378 |
| 354 } // namespace extensions | 379 } // namespace extensions |
| OLD | NEW |