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/hash.h" | 8 #include "base/hash.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
12 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/chrome_switches.h" |
14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 20 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
19 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
20 #include "extensions/common/error_utils.h" | 22 #include "extensions/common/error_utils.h" |
21 | 23 |
22 namespace extensions { | 24 namespace extensions { |
23 | 25 |
24 using api::webrtc_logging_private::MetaDataEntry; | 26 using api::webrtc_logging_private::MetaDataEntry; |
25 using api::webrtc_logging_private::RequestInfo; | 27 using api::webrtc_logging_private::RequestInfo; |
26 using content::BrowserThread; | 28 using content::BrowserThread; |
27 | 29 |
28 namespace Discard = api::webrtc_logging_private::Discard; | 30 namespace Discard = api::webrtc_logging_private::Discard; |
29 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; | 31 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; |
30 namespace SetUploadOnRenderClose = | 32 namespace SetUploadOnRenderClose = |
31 api::webrtc_logging_private::SetUploadOnRenderClose; | 33 api::webrtc_logging_private::SetUploadOnRenderClose; |
32 namespace Start = api::webrtc_logging_private::Start; | 34 namespace Start = api::webrtc_logging_private::Start; |
33 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump; | 35 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump; |
34 namespace Stop = api::webrtc_logging_private::Stop; | 36 namespace Stop = api::webrtc_logging_private::Stop; |
35 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; | 37 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; |
36 namespace Store = api::webrtc_logging_private::Store; | 38 namespace Store = api::webrtc_logging_private::Store; |
37 namespace Upload = api::webrtc_logging_private::Upload; | 39 namespace Upload = api::webrtc_logging_private::Upload; |
38 namespace UploadStored = api::webrtc_logging_private::UploadStored; | 40 namespace UploadStored = api::webrtc_logging_private::UploadStored; |
| 41 namespace StartAudioDebugRecordings = |
| 42 api::webrtc_logging_private::StartAudioDebugRecordings; |
| 43 namespace StopAudioDebugRecordings = |
| 44 api::webrtc_logging_private::StopAudioDebugRecordings; |
39 | 45 |
40 namespace { | 46 namespace { |
41 std::string HashIdWithOrigin(const std::string& security_origin, | 47 std::string HashIdWithOrigin(const std::string& security_origin, |
42 const std::string& log_id) { | 48 const std::string& log_id) { |
43 return base::UintToString(base::Hash(security_origin + log_id)); | 49 return base::UintToString(base::Hash(security_origin + log_id)); |
44 } | 50 } |
45 } // namespace | 51 } // namespace |
46 | 52 |
47 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( | 53 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( |
48 const RequestInfo& request, const std::string& security_origin) { | 54 const RequestInfo& request, const std::string& security_origin) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (success) { | 123 if (success) { |
118 api::webrtc_logging_private::UploadResult result; | 124 api::webrtc_logging_private::UploadResult result; |
119 result.report_id = report_id; | 125 result.report_id = report_id; |
120 SetResult(result.ToValue().release()); | 126 SetResult(result.ToValue().release()); |
121 } else { | 127 } else { |
122 SetError(error_message); | 128 SetError(error_message); |
123 } | 129 } |
124 SendResponse(success); | 130 SendResponse(success); |
125 } | 131 } |
126 | 132 |
| 133 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback:: |
| 134 FireErrorCallback(const std::string& error_message) { |
| 135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 136 SetError(error_message); |
| 137 SendResponse(false); |
| 138 } |
| 139 |
| 140 void WebrtcLoggingPrivateFunctionWithAudioDebugRecordingsCallback::FireCallback( |
| 141 const std::string& prefix_path, |
| 142 bool did_stop, |
| 143 bool did_manual_stop) { |
| 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 145 api::webrtc_logging_private::AudioDebugRecordingsInfo result; |
| 146 result.prefix_path = prefix_path; |
| 147 result.did_stop = did_stop; |
| 148 result.did_manual_stop = did_manual_stop; |
| 149 SetResult(result.ToValue().release()); |
| 150 SendResponse(true); |
| 151 } |
| 152 |
127 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { | 153 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
128 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | 154 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
129 EXTENSION_FUNCTION_VALIDATE(params.get()); | 155 EXTENSION_FUNCTION_VALIDATE(params.get()); |
130 | 156 |
131 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 157 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
132 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 158 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
133 PrepareTask(params->request, params->security_origin, &callback); | 159 PrepareTask(params->request, params->security_origin, &callback); |
134 if (!webrtc_logging_handler_host.get()) | 160 if (!webrtc_logging_handler_host.get()) |
135 return false; | 161 return false; |
136 | 162 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 367 |
342 BrowserThread::PostTask(BrowserThread::IO, | 368 BrowserThread::PostTask(BrowserThread::IO, |
343 FROM_HERE, | 369 FROM_HERE, |
344 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 370 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, |
345 webrtc_logging_handler_host, | 371 webrtc_logging_handler_host, |
346 type, | 372 type, |
347 callback)); | 373 callback)); |
348 return true; | 374 return true; |
349 } | 375 } |
350 | 376 |
| 377 bool WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::RunAsync() { |
| 378 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 379 switches::kEnableAudioDebugRecordingsFromExtension)) { |
| 380 return false; |
| 381 } |
| 382 |
| 383 scoped_ptr<StartAudioDebugRecordings::Params> params( |
| 384 StartAudioDebugRecordings::Params::Create(*args_)); |
| 385 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 386 |
| 387 if (params->seconds < 0) { |
| 388 FireErrorCallback("seconds must be greater than or equal to 0"); |
| 389 return true; |
| 390 } |
| 391 |
| 392 content::RenderProcessHost* host = |
| 393 RphFromRequest(params->request, params->security_origin); |
| 394 if (!host) |
| 395 return false; |
| 396 |
| 397 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 398 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 399 |
| 400 webrtc_logging_handler_host->StartAudioDebugRecordings( |
| 401 host, base::TimeDelta::FromSeconds(params->seconds), |
| 402 base::Bind( |
| 403 &WebrtcLoggingPrivateStartAudioDebugRecordingsFunction::FireCallback, |
| 404 this), |
| 405 base::Bind(&WebrtcLoggingPrivateStartAudioDebugRecordingsFunction:: |
| 406 FireErrorCallback, |
| 407 this)); |
| 408 return true; |
| 409 } |
| 410 |
| 411 bool WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::RunAsync() { |
| 412 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 413 switches::kEnableAudioDebugRecordingsFromExtension)) { |
| 414 return false; |
| 415 } |
| 416 |
| 417 scoped_ptr<StopAudioDebugRecordings::Params> params( |
| 418 StopAudioDebugRecordings::Params::Create(*args_)); |
| 419 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 420 |
| 421 content::RenderProcessHost* host = |
| 422 RphFromRequest(params->request, params->security_origin); |
| 423 if (!host) |
| 424 return false; |
| 425 |
| 426 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 427 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 428 |
| 429 webrtc_logging_handler_host->StopAudioDebugRecordings( |
| 430 host, |
| 431 base::Bind( |
| 432 &WebrtcLoggingPrivateStopAudioDebugRecordingsFunction::FireCallback, |
| 433 this), |
| 434 base::Bind(&WebrtcLoggingPrivateStopAudioDebugRecordingsFunction:: |
| 435 FireErrorCallback, |
| 436 this)); |
| 437 return true; |
| 438 } |
| 439 |
351 } // namespace extensions | 440 } // namespace extensions |
OLD | NEW |