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