Chromium Code Reviews| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 void MaybeExecuteSRTFromBlockingPool( | 48 void MaybeExecuteSRTFromBlockingPool( |
| 49 const base::FilePath& downloaded_path, | 49 const base::FilePath& downloaded_path, |
| 50 const scoped_refptr<SingleThreadTaskRunner>& task_runner, | 50 const scoped_refptr<SingleThreadTaskRunner>& task_runner, |
| 51 const base::Closure& success_callback, | 51 const base::Closure& success_callback, |
| 52 const base::Closure& failure_callback) { | 52 const base::Closure& failure_callback) { |
| 53 DCHECK(!downloaded_path.empty()); | 53 DCHECK(!downloaded_path.empty()); |
| 54 | 54 |
| 55 if (base::PathExists(downloaded_path)) { | 55 if (base::PathExists(downloaded_path)) { |
| 56 base::FilePath executable_path( | 56 base::FilePath executable_path( |
| 57 downloaded_path.ReplaceExtension(kExecutableExtension)); | 57 downloaded_path.ReplaceExtension(kExecutableExtension)); |
| 58 if (base::ReplaceFile(downloaded_path, executable_path, NULL)) { | 58 if (base::ReplaceFile(downloaded_path, executable_path, nullptr)) { |
| 59 base::CommandLine srt_command_line(executable_path); | 59 base::CommandLine srt_command_line(executable_path); |
| 60 srt_command_line.AppendSwitch(kChromePromptSwitch); | 60 srt_command_line.AppendSwitch(kChromePromptSwitch); |
| 61 base::Process srt_process( | 61 base::Process srt_process( |
| 62 base::LaunchProcess(srt_command_line, base::LaunchOptions())); | 62 base::LaunchProcess(srt_command_line, base::LaunchOptions())); |
| 63 if (srt_process.IsValid()) { | 63 if (srt_process.IsValid()) { |
| 64 task_runner->PostTask(FROM_HERE, success_callback); | 64 task_runner->PostTask(FROM_HERE, success_callback); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 if (!interacted_) { | 151 if (!interacted_) { |
| 152 // If user didn't interact with the bubble, it means they used the generic | 152 // If user didn't interact with the bubble, it means they used the generic |
| 153 // close bubble button. | 153 // close bubble button. |
| 154 RecordSRTPromptHistogram(SRT_PROMPT_CLOSED); | 154 RecordSRTPromptHistogram(SRT_PROMPT_CLOSED); |
| 155 g_browser_process->local_state()->SetBoolean( | 155 g_browser_process->local_state()->SetBoolean( |
| 156 prefs::kSwReporterPendingPrompt, true); | 156 prefs::kSwReporterPendingPrompt, true); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | 160 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
| 161 // This is for cases where the UI doesn't go away quickly enough and user | |
|
macourteau
2016/04/20 17:46:39
nit: this function and the one below have a lot of
MAD
2016/04/20 17:48:12
I wouldn't call this a lot of common code... Just
macourteau
2016/04/20 18:04:03
It's still 10 lines that are exactly the same exce
| |
| 162 // might click on the button more than once, or more than one button. | |
| 163 if (interacted_) | |
| 164 return; | |
| 161 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); | 165 RecordSRTPromptHistogram(SRT_PROMPT_ACCEPTED); |
| 162 interacted_ = true; | 166 interacted_ = true; |
| 163 global_error_service_->RemoveGlobalError(this); | 167 if (global_error_service_) { |
| 168 global_error_service_->RemoveGlobalError(this); | |
| 169 global_error_service_ = nullptr; | |
| 170 } | |
| 164 MaybeExecuteSRT(); | 171 MaybeExecuteSRT(); |
| 165 } | 172 } |
| 166 | 173 |
| 167 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | 174 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 175 // This is for cases where the UI doesn't go away quickly enough and user | |
| 176 // might click on the button more than once, or more than one button. | |
| 177 if (interacted_) | |
| 178 return; | |
| 168 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); | 179 RecordSRTPromptHistogram(SRT_PROMPT_DENIED); |
| 169 interacted_ = true; | 180 interacted_ = true; |
| 170 global_error_service_->RemoveGlobalError(this); | 181 if (global_error_service_) { |
| 182 global_error_service_->RemoveGlobalError(this); | |
| 183 global_error_service_ = nullptr; | |
| 184 } | |
| 171 | 185 |
| 172 BrowserThread::PostBlockingPoolTask( | 186 BrowserThread::PostBlockingPoolTask( |
| 173 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 187 FROM_HERE, base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 174 OnUserinteractionDone(); | 188 OnUserinteractionDone(); |
| 175 } | 189 } |
| 176 | 190 |
| 177 bool SRTGlobalError::ShouldCloseOnDeactivate() const { | 191 bool SRTGlobalError::ShouldCloseOnDeactivate() const { |
| 178 return false; | 192 return false; |
| 179 } | 193 } |
| 180 | 194 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 void SRTGlobalError::OnUserinteractionDone() { | 227 void SRTGlobalError::OnUserinteractionDone() { |
| 214 DCHECK(interacted_); | 228 DCHECK(interacted_); |
| 215 // Once the user interacted with the bubble, we can forget about any pending | 229 // Once the user interacted with the bubble, we can forget about any pending |
| 216 // prompt. | 230 // prompt. |
| 217 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, | 231 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, |
| 218 false); | 232 false); |
| 219 delete this; | 233 delete this; |
| 220 } | 234 } |
| 221 | 235 |
| 222 } // namespace safe_browsing | 236 } // namespace safe_browsing |
| OLD | NEW |