| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/process/launch.h" | 12 #include "base/process/launch.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" | |
| 18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/global_error/global_error_service.h" | 19 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 21 #include "components/component_updater/pref_names.h" | 20 #include "components/component_updater/pref_names.h" |
| 22 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 24 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 | 26 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 48 void MaybeExecuteSRTFromBlockingPool( | 47 void MaybeExecuteSRTFromBlockingPool( |
| 49 const base::FilePath& downloaded_path, | 48 const base::FilePath& downloaded_path, |
| 50 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | 49 const scoped_refptr<SingleThreadTaskRunner>& task_runner, |
| 51 const base::Closure& success_callback, | 50 const base::Closure& success_callback, |
| 52 const base::Closure& failure_callback) { | 51 const base::Closure& failure_callback) { |
| 53 DCHECK(!downloaded_path.empty()); | 52 DCHECK(!downloaded_path.empty()); |
| 54 | 53 |
| 55 if (base::PathExists(downloaded_path)) { | 54 if (base::PathExists(downloaded_path)) { |
| 56 base::FilePath executable_path( | 55 base::FilePath executable_path( |
| 57 downloaded_path.ReplaceExtension(kExecutableExtension)); | 56 downloaded_path.ReplaceExtension(kExecutableExtension)); |
| 58 if (base::ReplaceFile(downloaded_path, executable_path, NULL)) { | 57 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) { |
| 59 base::CommandLine srt_command_line(executable_path); | 58 base::CommandLine srt_command_line(executable_path); |
| 60 srt_command_line.AppendSwitch(kChromePromptSwitch); | 59 srt_command_line.AppendSwitch(kChromePromptSwitch); |
| 61 base::Process srt_process( | 60 base::Process srt_process( |
| 62 base::LaunchProcess(srt_command_line, base::LaunchOptions())); | 61 base::LaunchProcess(srt_command_line, base::LaunchOptions())); |
| 63 if (srt_process.IsValid()) { | 62 if (srt_process.IsValid()) { |
| 64 task_runner->PostTask(FROM_HERE, success_callback); | 63 task_runner->PostTask(FROM_HERE, success_callback); |
| 65 return; | 64 return; |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 } | 67 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (!interacted_) { | 150 if (!interacted_) { |
| 152 // If user didn't interact with the bubble, it means they used the generic | 151 // If user didn't interact with the bubble, it means they used the generic |
| 153 // close bubble button. | 152 // close bubble button. |
| 154 RecordSRTPromptHistogram(SRT_PROMPT_CLOSED); | 153 RecordSRTPromptHistogram(SRT_PROMPT_CLOSED); |
| 155 g_browser_process->local_state()->SetBoolean( | 154 g_browser_process->local_state()->SetBoolean( |
| 156 prefs::kSwReporterPendingPrompt, true); | 155 prefs::kSwReporterPendingPrompt, true); |
| 157 } | 156 } |
| 158 } | 157 } |
| 159 | 158 |
| 160 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | 159 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
| 161 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); | 160 OnUserinteractionStarted(SRT_PROMPT_ACCEPTED); |
| 162 interacted_ = true; | |
| 163 global_error_service_->RemoveGlobalError(this); | |
| 164 MaybeExecuteSRT(); | 161 MaybeExecuteSRT(); |
| 165 } | 162 } |
| 166 | 163 |
| 167 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | 164 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 168 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); | 165 OnUserinteractionStarted(SRT_PROMPT_DENIED); |
| 169 interacted_ = true; | |
| 170 global_error_service_->RemoveGlobalError(this); | |
| 171 | |
| 172 BrowserThread::PostBlockingPoolTask( | 166 BrowserThread::PostBlockingPoolTask( |
| 173 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 167 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 174 OnUserinteractionDone(); | 168 OnUserinteractionDone(); |
| 175 } | 169 } |
| 176 | 170 |
| 177 bool SRTGlobalError::ShouldCloseOnDeactivate() const { | 171 bool SRTGlobalError::ShouldCloseOnDeactivate() const { |
| 178 return false; | 172 return false; |
| 179 } | 173 } |
| 180 | 174 |
| 181 void SRTGlobalError::MaybeExecuteSRT() { | 175 void SRTGlobalError::MaybeExecuteSRT() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 203 browser->OpenURL(content::OpenURLParams( | 197 browser->OpenURL(content::OpenURLParams( |
| 204 GURL(kSRTDownloadURL), content::Referrer(), NEW_FOREGROUND_TAB, | 198 GURL(kSRTDownloadURL), content::Referrer(), NEW_FOREGROUND_TAB, |
| 205 ui::PAGE_TRANSITION_LINK, false)); | 199 ui::PAGE_TRANSITION_LINK, false)); |
| 206 } | 200 } |
| 207 | 201 |
| 208 BrowserThread::PostBlockingPoolTask( | 202 BrowserThread::PostBlockingPoolTask( |
| 209 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 203 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 210 OnUserinteractionDone(); | 204 OnUserinteractionDone(); |
| 211 } | 205 } |
| 212 | 206 |
| 207 void SRTGlobalError::OnUserinteractionStarted( |
| 208 SRTPromptHistogramValue histogram_value) { |
| 209 // This is for cases where the UI doesn't go away quickly enough and user |
| 210 // might click on the button more than once, or more than one button. |
| 211 if (interacted_) |
| 212 return; |
| 213 RecordSRTPromptHistogram(histogram_value); |
| 214 interacted_ = true; |
| 215 if (global_error_service_) { |
| 216 global_error_service_->RemoveGlobalError(this); |
| 217 global_error_service_ = nullptr; |
| 218 } |
| 219 } |
| 220 |
| 213 void SRTGlobalError::OnUserinteractionDone() { | 221 void SRTGlobalError::OnUserinteractionDone() { |
| 214 DCHECK(interacted_); | 222 DCHECK(interacted_); |
| 215 // Once the user interacted with the bubble, we can forget about any pending | 223 // Once the user interacted with the bubble, we can forget about any pending |
| 216 // prompt. | 224 // prompt. |
| 217 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, | 225 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, |
| 218 false); | 226 false); |
| 219 delete this; | 227 delete this; |
| 220 } | 228 } |
| 221 | 229 |
| 222 } // namespace safe_browsing | 230 } // namespace safe_browsing |
| OLD | NEW |