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 StartAecDump = api::webrtc_logging_private::StartAecDump; | |
43 namespace StopAecDump = api::webrtc_logging_private::StopAecDump; | |
39 | 44 |
40 namespace { | 45 namespace { |
41 std::string HashIdWithOrigin(const std::string& security_origin, | 46 std::string HashIdWithOrigin(const std::string& security_origin, |
42 const std::string& log_id) { | 47 const std::string& log_id) { |
43 return base::UintToString(base::Hash(security_origin + log_id)); | 48 return base::UintToString(base::Hash(security_origin + log_id)); |
44 } | 49 } |
50 | |
51 uint64 current_aec_dump_id = 0; | |
52 bool is_dump_in_progress = false; | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
document what thread these variables are used on.
Guido Urdaneta
2015/12/17 14:35:40
Done.
| |
53 char kDumpFilePrefix[] = "aecdump."; | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
const
Guido Urdaneta
2015/12/17 14:35:40
Done.
| |
54 | |
55 // Starts AEC dump and save the files in the |dump_dir| directory, provided | |
56 // no dump is in progress. Returns a UTF8 string with the prefix common to all | |
57 // files produced by the dump (includes |dump_dir| and dump ID). | |
58 // If there is a dump in progress, returns an empty string. | |
59 std::string DoStartAecDump(const base::FilePath& dump_dir) { | |
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
61 if (is_dump_in_progress) | |
62 return std::string(); | |
63 | |
64 current_aec_dump_id++; | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
++foo;
Guido Urdaneta
2015/12/17 14:35:40
Done.
| |
65 base::FilePath prefix_path = dump_dir.Append( | |
66 kDumpFilePrefix + base::Int64ToString(current_aec_dump_id)); | |
67 is_dump_in_progress = true; | |
68 for (content::RenderProcessHost::iterator i( | |
69 content::RenderProcessHost::AllHostsIterator()); | |
70 !i.IsAtEnd(); i.Advance()) { | |
71 i.GetCurrentValue()->EnableAudioDebugRecordings(prefix_path); | |
72 } | |
73 | |
74 return prefix_path.AsUTF8Unsafe(); | |
75 } | |
76 | |
77 // If |dump_id| is zero or the ID of the current AEC dump, stops the current | |
78 // AEC dump. Otherwise, does nothing. | |
79 void DoStopAecDump(uint64 dump_id) { | |
80 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
81 | |
82 // Prevent a old posted StopAecDump() call to stop a newer dump. | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
nit: Prevent an old posted StopAecDump() call from
Guido Urdaneta
2015/12/17 14:35:40
Done.
| |
83 // This could happen in a sequence like: | |
84 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. | |
85 // Stop(); // Manually stop dump 1 before 10 seconds; | |
86 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. | |
87 if (dump_id != 0 && dump_id < current_aec_dump_id) | |
88 return; | |
89 | |
90 DCHECK_LE(dump_id, current_aec_dump_id); | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
I don't think this DCHECK will ever hit due to the
Guido Urdaneta
2015/12/17 14:35:42
Moved to the beginning of the function.
| |
91 for (content::RenderProcessHost::iterator i( | |
92 content::RenderProcessHost::AllHostsIterator()); | |
93 !i.IsAtEnd(); i.Advance()) { | |
94 i.GetCurrentValue()->DisableAudioDebugRecordings(); | |
95 } | |
96 | |
97 is_dump_in_progress = false; | |
98 } | |
45 } // namespace | 99 } // namespace |
46 | 100 |
47 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( | 101 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( |
48 const RequestInfo& request, const std::string& security_origin) { | 102 const RequestInfo& request, const std::string& security_origin) { |
49 // If |guest_process_id| is defined, directly use this id to find the | 103 // If |guest_process_id| is defined, directly use this id to find the |
50 // corresponding RenderProcessHost. | 104 // corresponding RenderProcessHost. |
51 if (request.guest_process_id.get()) | 105 if (request.guest_process_id.get()) |
52 return content::RenderProcessHost::FromID(*request.guest_process_id.get()); | 106 return content::RenderProcessHost::FromID(*request.guest_process_id.get()); |
53 | 107 |
54 // Otherwise, use the |tab_id|. If there's no |tab_id| and no | 108 // Otherwise, use the |tab_id|. If there's no |tab_id| and no |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 if (success) { | 171 if (success) { |
118 api::webrtc_logging_private::UploadResult result; | 172 api::webrtc_logging_private::UploadResult result; |
119 result.report_id = report_id; | 173 result.report_id = report_id; |
120 SetResult(result.ToValue().release()); | 174 SetResult(result.ToValue().release()); |
121 } else { | 175 } else { |
122 SetError(error_message); | 176 SetError(error_message); |
123 } | 177 } |
124 SendResponse(success); | 178 SendResponse(success); |
125 } | 179 } |
126 | 180 |
181 void WebrtcLoggingPrivateFunctionWithAecDumpStartedCallback::FireCallback( | |
182 bool success, | |
183 const std::string& prefix_path, | |
184 const std::string& error_message) { | |
185 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
186 if (success) { | |
187 api::webrtc_logging_private::AecDumpInfo result; | |
188 result.prefix_path = prefix_path; | |
189 SetResult(result.ToValue().release()); | |
190 } else { | |
191 SetError(error_message); | |
192 } | |
193 SendResponse(success); | |
194 } | |
195 | |
127 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { | 196 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
128 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | 197 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); |
129 EXTENSION_FUNCTION_VALIDATE(params.get()); | 198 EXTENSION_FUNCTION_VALIDATE(params.get()); |
130 | 199 |
131 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | 200 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
132 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | 201 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
133 PrepareTask(params->request, params->security_origin, &callback); | 202 PrepareTask(params->request, params->security_origin, &callback); |
134 if (!webrtc_logging_handler_host.get()) | 203 if (!webrtc_logging_handler_host.get()) |
135 return false; | 204 return false; |
136 | 205 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 | 410 |
342 BrowserThread::PostTask(BrowserThread::IO, | 411 BrowserThread::PostTask(BrowserThread::IO, |
343 FROM_HERE, | 412 FROM_HERE, |
344 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 413 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, |
345 webrtc_logging_handler_host, | 414 webrtc_logging_handler_host, |
346 type, | 415 type, |
347 callback)); | 416 callback)); |
348 return true; | 417 return true; |
349 } | 418 } |
350 | 419 |
420 bool WebrtcLoggingPrivateStartAecDumpFunction::RunAsync() { | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
do we need some sort of cleanup code here? E.g. d
Guido Urdaneta
2015/12/17 14:35:40
The functions are changed now so that the callback
| |
421 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
422 switches::kEnableAecDumps)) { | |
tommi (sloooow) - chröme
2015/12/17 11:03:26
can we call the constant kAllowAecDumpsFromExtensi
Guido Urdaneta
2015/12/17 14:35:42
Done.
| |
423 return false; | |
424 } | |
425 | |
426 scoped_ptr<StartAecDump::Params> params(StartAecDump::Params::Create(*args_)); | |
427 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
428 if (params->seconds < 0) { | |
429 FireCallback(false, std::string(), | |
430 "seconds must be greater than or equal to 0"); | |
431 return true; | |
432 } | |
433 | |
434 DownloadPrefs download_prefs(GetProfile()); | |
435 base::FilePath dump_dir = download_prefs.GetDefaultDownloadDirectory(); | |
436 std::string prefix_path = DoStartAecDump(dump_dir); | |
437 if (prefix_path.empty()) | |
438 FireCallback(false, std::string(), "AEC Dump already in progress"); | |
439 else | |
440 FireCallback(true, prefix_path, std::string()); | |
441 | |
442 if (params->seconds > 0) { | |
443 BrowserThread::PostDelayedTask( | |
444 BrowserThread::UI, FROM_HERE, | |
445 base::Bind(&DoStopAecDump, current_aec_dump_id), | |
446 base::TimeDelta::FromSeconds(params->seconds)); | |
447 } | |
448 | |
449 return true; | |
450 } | |
451 | |
452 bool WebrtcLoggingPrivateStopAecDumpFunction::RunAsync() { | |
453 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
454 switches::kEnableAecDumps)) { | |
455 return false; | |
456 } | |
457 | |
458 DoStopAecDump(0); | |
459 FireCallback(true, std::string()); | |
460 return true; | |
461 } | |
462 | |
351 } // namespace extensions | 463 } // namespace extensions |
OLD | NEW |