| 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 RtpDumpType type = |
| 288 (params->incoming && params->outgoing) |
| 289 ? RTP_DUMP_BOTH |
| 290 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); |
| 291 |
| 282 content::RenderProcessHost* host = | 292 content::RenderProcessHost* host = |
| 283 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); | 293 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); |
| 284 if (!host) | 294 if (!host) |
| 285 return false; | 295 return false; |
| 286 | 296 |
| 287 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 297 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 288 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 298 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 289 | 299 |
| 290 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 300 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 291 &WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback, this); | 301 &WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback, this); |
| 292 | 302 |
| 303 // This call cannot fail. |
| 304 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = |
| 305 host->StartRtpDump(params->incoming, |
| 306 params->outgoing, |
| 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 RtpDumpType type = |
| 345 (params->incoming && params->outgoing) |
| 346 ? RTP_DUMP_BOTH |
| 347 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); |
| 348 |
| 323 content::RenderProcessHost* host = | 349 content::RenderProcessHost* host = |
| 324 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); | 350 RphFromTabIdAndSecurityOrigin(params->tab_id, params->security_origin); |
| 325 if (!host) | 351 if (!host) |
| 326 return false; | 352 return false; |
| 327 | 353 |
| 328 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 354 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 329 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 355 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 330 | 356 |
| 331 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 357 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 332 &WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback, this); | 358 &WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback, this); |
| 333 | 359 |
| 334 BrowserThread::PostTask(BrowserThread::IO, | 360 BrowserThread::PostTask(BrowserThread::IO, |
| 335 FROM_HERE, | 361 FROM_HERE, |
| 336 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 362 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, |
| 337 webrtc_logging_handler_host, | 363 webrtc_logging_handler_host, |
| 338 params->incoming, | 364 type, |
| 339 params->outgoing, | |
| 340 callback)); | 365 callback)); |
| 341 | |
| 342 return true; | 366 return true; |
| 343 } | 367 } |
| 344 | 368 |
| 345 void WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback( | 369 void WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback( |
| 346 bool success, | 370 bool success, |
| 347 const std::string& error_message) { | 371 const std::string& error_message) { |
| 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 372 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 349 if (!success) | 373 if (!success) |
| 350 SetError(error_message); | 374 SetError(error_message); |
| 351 SendResponse(success); | 375 SendResponse(success); |
| 352 } | 376 } |
| 353 | 377 |
| 354 } // namespace extensions | 378 } // namespace extensions |
| OLD | NEW |