OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/safe_browsing/srt_global_error_win.h" | 5 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/process/launch.h" | 15 #include "base/process/launch.h" |
16 #include "base/single_thread_task_runner.h" | |
17 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
18 #include "base/task_scheduler/post_task.h" | 17 #include "base/task_scheduler/post_task.h" |
19 #include "base/threading/thread_task_runner_handle.h" | |
20 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
21 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 20 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
23 #include "chrome/browser/safe_browsing/srt_client_info_win.h" | 21 #include "chrome/browser/safe_browsing/srt_client_info_win.h" |
24 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" | 22 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" |
25 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/global_error/global_error_service.h" | 25 #include "chrome/browser/ui/global_error/global_error_service.h" |
28 #include "chrome/common/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
29 #include "chrome/grit/chromium_strings.h" | 27 #include "chrome/grit/chromium_strings.h" |
30 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
31 #include "chrome/installer/util/install_util.h" | 29 #include "chrome/installer/util/install_util.h" |
32 #include "components/chrome_cleaner/public/constants/constants.h" | 30 #include "components/chrome_cleaner/public/constants/constants.h" |
33 #include "components/component_updater/pref_names.h" | 31 #include "components/component_updater/pref_names.h" |
34 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
35 #include "components/version_info/version_info.h" | 33 #include "components/version_info/version_info.h" |
36 #include "content/public/browser/browser_thread.h" | |
37 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
38 | 35 |
39 using base::SingleThreadTaskRunner; | |
40 using base::ThreadTaskRunnerHandle; | |
41 using content::BrowserThread; | |
42 | |
43 namespace safe_browsing { | 36 namespace safe_browsing { |
44 | 37 |
45 namespace { | 38 namespace { |
46 | 39 |
47 // Used as a backup plan in case the SRT executable was not successfully | 40 // Used as a backup plan in case the SRT executable was not successfully |
48 // downloaded or run. | 41 // downloaded or run. |
49 const char kSRTDownloadURL[] = | 42 const char kSRTDownloadURL[] = |
50 "https://www.google.com/chrome/srt/?chrome-prompt=1"; | 43 "https://www.google.com/chrome/srt/?chrome-prompt=1"; |
51 | 44 |
52 // The extension to use to replace the temporary one created when the SRT was | 45 // The extension to use to replace the temporary one created when the SRT was |
53 // downloaded. | 46 // downloaded. |
54 const base::FilePath::CharType kExecutableExtension[] = L"exe"; | 47 const base::FilePath::CharType kExecutableExtension[] = L"exe"; |
55 | 48 |
56 void MaybeExecuteSRTFromBlockingPool( | 49 bool MaybeExecuteSRTFromBlockingPool( |
57 const base::FilePath& downloaded_path, | 50 const base::FilePath& downloaded_path, |
58 bool metrics_enabled, | 51 bool metrics_enabled, |
59 bool sber_enabled, | 52 bool sber_enabled, |
60 chrome_cleaner::ChromePromptValue prompt_value, | 53 chrome_cleaner::ChromePromptValue prompt_value) { |
61 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | |
62 const base::Closure& success_callback, | |
63 const base::Closure& failure_callback) { | |
64 DCHECK(!downloaded_path.empty()); | 54 DCHECK(!downloaded_path.empty()); |
65 | 55 |
66 if (base::PathExists(downloaded_path)) { | 56 if (base::PathExists(downloaded_path)) { |
67 base::FilePath executable_path( | 57 base::FilePath executable_path( |
68 downloaded_path.ReplaceExtension(kExecutableExtension)); | 58 downloaded_path.ReplaceExtension(kExecutableExtension)); |
69 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) { | 59 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) { |
70 base::CommandLine srt_command_line(executable_path); | 60 base::CommandLine srt_command_line(executable_path); |
71 srt_command_line.AppendSwitchASCII( | 61 srt_command_line.AppendSwitchASCII( |
72 chrome_cleaner::kChromePromptSwitch, | 62 chrome_cleaner::kChromePromptSwitch, |
73 base::IntToString(static_cast<int>(prompt_value))); | 63 base::IntToString(static_cast<int>(prompt_value))); |
(...skipping 15 matching lines...) Expand all Loading... |
89 srt_command_line.AppendSwitch( | 79 srt_command_line.AppendSwitch( |
90 chrome_cleaner::kEnableCrashReportingSwitch); | 80 chrome_cleaner::kEnableCrashReportingSwitch); |
91 } | 81 } |
92 | 82 |
93 if (sber_enabled) | 83 if (sber_enabled) |
94 srt_command_line.AppendSwitch( | 84 srt_command_line.AppendSwitch( |
95 chrome_cleaner::kExtendedSafeBrowsingEnabledSwitch); | 85 chrome_cleaner::kExtendedSafeBrowsingEnabledSwitch); |
96 | 86 |
97 base::Process srt_process( | 87 base::Process srt_process( |
98 base::LaunchProcess(srt_command_line, base::LaunchOptions())); | 88 base::LaunchProcess(srt_command_line, base::LaunchOptions())); |
99 if (srt_process.IsValid()) { | 89 return srt_process.IsValid(); |
100 task_runner->PostTask(FROM_HERE, success_callback); | |
101 return; | |
102 } | |
103 } | 90 } |
104 } | 91 } |
105 | 92 return false; |
106 task_runner->PostTask(FROM_HERE, failure_callback); | |
107 } | 93 } |
108 | 94 |
109 void DeleteFilesFromBlockingPool(const base::FilePath& downloaded_path) { | 95 void DeleteFilesFromBlockingPool(const base::FilePath& downloaded_path) { |
110 base::DeleteFile(downloaded_path, false); | 96 base::DeleteFile(downloaded_path, false); |
111 base::DeleteFile(downloaded_path.ReplaceExtension(kExecutableExtension), | 97 base::DeleteFile(downloaded_path.ReplaceExtension(kExecutableExtension), |
112 false); | 98 false); |
113 } | 99 } |
114 | 100 |
115 } // namespace | 101 } // namespace |
116 | 102 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 201 } |
216 | 202 |
217 void SRTGlobalError::MaybeExecuteSRT() { | 203 void SRTGlobalError::MaybeExecuteSRT() { |
218 if (downloaded_path_.empty()) { | 204 if (downloaded_path_.empty()) { |
219 FallbackToDownloadPage(); | 205 FallbackToDownloadPage(); |
220 return; | 206 return; |
221 } | 207 } |
222 // At this point, this object owns itself, since ownership has been taken back | 208 // At this point, this object owns itself, since ownership has been taken back |
223 // from the global_error_service_ in the call to OnUserInteractionStarted. | 209 // from the global_error_service_ in the call to OnUserInteractionStarted. |
224 // This means that it is safe to use base::Unretained here. | 210 // This means that it is safe to use base::Unretained here. |
225 base::PostTaskWithTraits( | 211 base::PostTaskWithTraitsAndReplyWithResult( |
226 FROM_HERE, | 212 FROM_HERE, |
227 base::TaskTraits().MayBlock().WithPriority( | 213 base::TaskTraits().MayBlock().WithPriority( |
228 base::TaskPriority::BACKGROUND), | 214 base::TaskPriority::BACKGROUND), |
229 base::Bind( | 215 base::Bind( |
230 &MaybeExecuteSRTFromBlockingPool, downloaded_path_, | 216 &MaybeExecuteSRTFromBlockingPool, downloaded_path_, |
231 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), | 217 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), |
232 SafeBrowsingExtendedReportingEnabled(), | 218 SafeBrowsingExtendedReportingEnabled(), |
233 bubble_shown_from_menu_ | 219 bubble_shown_from_menu_ |
234 ? chrome_cleaner::ChromePromptValue::kShownFromMenu | 220 ? chrome_cleaner::ChromePromptValue::kShownFromMenu |
235 : chrome_cleaner::ChromePromptValue::kPrompted, | 221 : chrome_cleaner::ChromePromptValue::kPrompted), |
236 base::ThreadTaskRunnerHandle::Get(), | 222 base::Bind( |
237 base::Bind(&SRTGlobalError::OnUserinteractionDone, | 223 [](SRTGlobalError* self, bool success) { |
238 base::Unretained(this)), | 224 if (success) |
239 base::Bind(&SRTGlobalError::FallbackToDownloadPage, | 225 self->OnUserinteractionDone(); |
240 base::Unretained(this)))); | 226 else |
| 227 self->FallbackToDownloadPage(); |
| 228 }, |
| 229 base::Unretained(this))); |
241 } | 230 } |
242 | 231 |
243 void SRTGlobalError::FallbackToDownloadPage() { | 232 void SRTGlobalError::FallbackToDownloadPage() { |
244 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK); | 233 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK); |
245 | 234 |
246 Browser* browser = chrome::FindLastActive(); | 235 Browser* browser = chrome::FindLastActive(); |
247 if (browser) { | 236 if (browser) { |
248 browser->OpenURL( | 237 browser->OpenURL( |
249 content::OpenURLParams(GURL(kSRTDownloadURL), content::Referrer(), | 238 content::OpenURLParams(GURL(kSRTDownloadURL), content::Referrer(), |
250 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 239 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
(...skipping 24 matching lines...) Expand all Loading... |
275 void SRTGlobalError::OnUserinteractionDone() { | 264 void SRTGlobalError::OnUserinteractionDone() { |
276 DCHECK(interacted_); | 265 DCHECK(interacted_); |
277 // Once the user interacted with the bubble, we can forget about any pending | 266 // Once the user interacted with the bubble, we can forget about any pending |
278 // prompt. | 267 // prompt. |
279 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, | 268 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, |
280 false); | 269 false); |
281 delete this; | 270 delete this; |
282 } | 271 } |
283 | 272 |
284 } // namespace safe_browsing | 273 } // namespace safe_browsing |
OLD | NEW |