Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: chrome/browser/safe_browsing/srt_global_error_win.cc

Issue 2812223003: Move shared constants to //components/chrome_cleaner (Closed)
Patch Set: Code review Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 22 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
23 #include "chrome/browser/safe_browsing/srt_client_info_win.h" 23 #include "chrome/browser/safe_browsing/srt_client_info_win.h"
24 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" 24 #include "chrome/browser/safe_browsing/srt_field_trial_win.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/global_error/global_error_service.h" 27 #include "chrome/browser/ui/global_error/global_error_service.h"
28 #include "chrome/common/channel_info.h" 28 #include "chrome/common/channel_info.h"
29 #include "chrome/grit/chromium_strings.h" 29 #include "chrome/grit/chromium_strings.h"
30 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
31 #include "chrome/installer/util/install_util.h" 31 #include "chrome/installer/util/install_util.h"
32 #include "components/chrome_cleaner/public/constants/constants.h"
32 #include "components/component_updater/pref_names.h" 33 #include "components/component_updater/pref_names.h"
33 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
34 #include "components/version_info/version_info.h" 35 #include "components/version_info/version_info.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 38
38 using base::SingleThreadTaskRunner; 39 using base::SingleThreadTaskRunner;
39 using base::ThreadTaskRunnerHandle; 40 using base::ThreadTaskRunnerHandle;
40 using content::BrowserThread; 41 using content::BrowserThread;
41 42
42 namespace safe_browsing { 43 namespace safe_browsing {
43 44
44 namespace { 45 namespace {
45 46
46 // Used as a backup plan in case the SRT executable was not successfully 47 // Used as a backup plan in case the SRT executable was not successfully
47 // downloaded or run. 48 // downloaded or run.
48 const char kSRTDownloadURL[] = 49 const char kSRTDownloadURL[] =
49 "https://www.google.com/chrome/srt/?chrome-prompt=1"; 50 "https://www.google.com/chrome/srt/?chrome-prompt=1";
50 51
51 // The extension to use to replace the temporary one created when the SRT was 52 // The extension to use to replace the temporary one created when the SRT was
52 // downloaded. 53 // downloaded.
53 const base::FilePath::CharType kExecutableExtension[] = L"exe"; 54 const base::FilePath::CharType kExecutableExtension[] = L"exe";
54 55
55 // Switches to add to the command line when executing the SRT.
56 const char kChromePromptSwitch[] = "chrome-prompt";
57 const char kChromeExePathSwitch[] = "chrome-exe-path";
58 const char kChromeSystemInstallSwitch[] = "chrome-system-install";
59 const char kUmaUserSwitch[] = "uma-user";
60
61 // Values to be passed to the kChromePromptSwitch of the Chrome Cleanup Tool to
62 // indicate how the user interacted with the accept button.
63 enum class ChromePromptValue {
64 // The user accepted the prompt when the prompt was first shown.
65 kPrompted = 3,
66 // The user accepted the prompt after navigating to it from the menu.
67 kShownFromMenu = 4
68 };
69
70 void MaybeExecuteSRTFromBlockingPool( 56 void MaybeExecuteSRTFromBlockingPool(
71 const base::FilePath& downloaded_path, 57 const base::FilePath& downloaded_path,
72 bool metrics_enabled, 58 bool metrics_enabled,
73 bool sber_enabled, 59 bool sber_enabled,
74 ChromePromptValue prompt_value, 60 chrome_cleaner::ChromePromptValue prompt_value,
75 const scoped_refptr<SingleThreadTaskRunner>& task_runner, 61 const scoped_refptr<SingleThreadTaskRunner>& task_runner,
76 const base::Closure& success_callback, 62 const base::Closure& success_callback,
77 const base::Closure& failure_callback) { 63 const base::Closure& failure_callback) {
78 DCHECK(!downloaded_path.empty()); 64 DCHECK(!downloaded_path.empty());
79 65
80 if (base::PathExists(downloaded_path)) { 66 if (base::PathExists(downloaded_path)) {
81 base::FilePath executable_path( 67 base::FilePath executable_path(
82 downloaded_path.ReplaceExtension(kExecutableExtension)); 68 downloaded_path.ReplaceExtension(kExecutableExtension));
83 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) { 69 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) {
84 base::CommandLine srt_command_line(executable_path); 70 base::CommandLine srt_command_line(executable_path);
85 srt_command_line.AppendSwitchASCII( 71 srt_command_line.AppendSwitchASCII(
86 kChromePromptSwitch, 72 chrome_cleaner::kChromePromptSwitch,
87 base::IntToString(static_cast<int>(prompt_value))); 73 base::IntToString(static_cast<int>(prompt_value)));
88 srt_command_line.AppendSwitchASCII(kChromeVersionSwitch, 74 srt_command_line.AppendSwitchASCII(chrome_cleaner::kChromeVersionSwitch,
89 version_info::GetVersionNumber()); 75 version_info::GetVersionNumber());
90 srt_command_line.AppendSwitchASCII(kChromeChannelSwitch, 76 srt_command_line.AppendSwitchASCII(chrome_cleaner::kChromeChannelSwitch,
91 base::IntToString(ChannelAsInt())); 77 base::IntToString(ChannelAsInt()));
92 78
93 base::FilePath chrome_exe_path; 79 base::FilePath chrome_exe_path;
94 PathService::Get(base::FILE_EXE, &chrome_exe_path); 80 PathService::Get(base::FILE_EXE, &chrome_exe_path);
95 srt_command_line.AppendSwitchPath(kChromeExePathSwitch, chrome_exe_path); 81 srt_command_line.AppendSwitchPath(chrome_cleaner::kChromeExePathSwitch,
82 chrome_exe_path);
96 if (!InstallUtil::IsPerUserInstall()) 83 if (!InstallUtil::IsPerUserInstall())
97 srt_command_line.AppendSwitch(kChromeSystemInstallSwitch); 84 srt_command_line.AppendSwitch(
85 chrome_cleaner::kChromeSystemInstallSwitch);
98 86
99 if (metrics_enabled) { 87 if (metrics_enabled) {
100 srt_command_line.AppendSwitch(kUmaUserSwitch); 88 srt_command_line.AppendSwitch(chrome_cleaner::kUmaUserSwitch);
101 srt_command_line.AppendSwitch(kEnableCrashReporting); 89 srt_command_line.AppendSwitch(
90 chrome_cleaner::kEnableCrashReportingSwitch);
102 } 91 }
103 92
104 if (sber_enabled) 93 if (sber_enabled)
105 srt_command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); 94 srt_command_line.AppendSwitch(
95 chrome_cleaner::kExtendedSafeBrowsingEnabledSwitch);
106 96
107 base::Process srt_process( 97 base::Process srt_process(
108 base::LaunchProcess(srt_command_line, base::LaunchOptions())); 98 base::LaunchProcess(srt_command_line, base::LaunchOptions()));
109 if (srt_process.IsValid()) { 99 if (srt_process.IsValid()) {
110 task_runner->PostTask(FROM_HERE, success_callback); 100 task_runner->PostTask(FROM_HERE, success_callback);
111 return; 101 return;
112 } 102 }
113 } 103 }
114 } 104 }
115 105
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 216
227 void SRTGlobalError::MaybeExecuteSRT() { 217 void SRTGlobalError::MaybeExecuteSRT() {
228 if (downloaded_path_.empty()) { 218 if (downloaded_path_.empty()) {
229 FallbackToDownloadPage(); 219 FallbackToDownloadPage();
230 return; 220 return;
231 } 221 }
232 // At this point, this object owns itself, since ownership has been taken back 222 // At this point, this object owns itself, since ownership has been taken back
233 // from the global_error_service_ in the call to OnUserInteractionStarted. 223 // from the global_error_service_ in the call to OnUserInteractionStarted.
234 // This means that it is safe to use base::Unretained here. 224 // This means that it is safe to use base::Unretained here.
235 base::PostTaskWithTraits( 225 base::PostTaskWithTraits(
236 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( 226 FROM_HERE,
237 base::TaskPriority::BACKGROUND), 227 base::TaskTraits().MayBlock().WithPriority(
228 base::TaskPriority::BACKGROUND),
238 base::Bind( 229 base::Bind(
239 &MaybeExecuteSRTFromBlockingPool, downloaded_path_, 230 &MaybeExecuteSRTFromBlockingPool, downloaded_path_,
240 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), 231 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(),
241 SafeBrowsingExtendedReportingEnabled(), 232 SafeBrowsingExtendedReportingEnabled(),
242 bubble_shown_from_menu_ ? ChromePromptValue::kShownFromMenu 233 bubble_shown_from_menu_
243 : ChromePromptValue::kPrompted, 234 ? chrome_cleaner::ChromePromptValue::kShownFromMenu
235 : chrome_cleaner::ChromePromptValue::kPrompted,
244 base::ThreadTaskRunnerHandle::Get(), 236 base::ThreadTaskRunnerHandle::Get(),
245 base::Bind(&SRTGlobalError::OnUserinteractionDone, 237 base::Bind(&SRTGlobalError::OnUserinteractionDone,
246 base::Unretained(this)), 238 base::Unretained(this)),
247 base::Bind(&SRTGlobalError::FallbackToDownloadPage, 239 base::Bind(&SRTGlobalError::FallbackToDownloadPage,
248 base::Unretained(this)))); 240 base::Unretained(this))));
249 } 241 }
250 242
251 void SRTGlobalError::FallbackToDownloadPage() { 243 void SRTGlobalError::FallbackToDownloadPage() {
252 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK); 244 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK);
253 245
(...skipping 29 matching lines...) Expand all
283 void SRTGlobalError::OnUserinteractionDone() { 275 void SRTGlobalError::OnUserinteractionDone() {
284 DCHECK(interacted_); 276 DCHECK(interacted_);
285 // Once the user interacted with the bubble, we can forget about any pending 277 // Once the user interacted with the bubble, we can forget about any pending
286 // prompt. 278 // prompt.
287 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, 279 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt,
288 false); 280 false);
289 delete this; 281 delete this;
290 } 282 }
291 283
292 } // namespace safe_browsing 284 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_win.cc ('k') | components/chrome_cleaner/public/constants/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698