| 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/chrome_cleaner/srt_global_error_win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 SRTGlobalError::SRTGlobalError(GlobalErrorService* global_error_service, | 105 SRTGlobalError::SRTGlobalError(GlobalErrorService* global_error_service, |
| 106 const base::FilePath& downloaded_path) | 106 const base::FilePath& downloaded_path) |
| 107 : global_error_service_(global_error_service), | 107 : global_error_service_(global_error_service), |
| 108 downloaded_path_(downloaded_path) { | 108 downloaded_path_(downloaded_path) { |
| 109 DCHECK(global_error_service_); | 109 DCHECK(global_error_service_); |
| 110 } | 110 } |
| 111 | 111 |
| 112 SRTGlobalError::~SRTGlobalError() { | 112 SRTGlobalError::~SRTGlobalError() { |
| 113 if (!interacted_) { | 113 if (!interacted_) { |
| 114 base::PostTaskWithTraits( | 114 base::PostTaskWithTraits( |
| 115 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 115 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 116 base::TaskPriority::BACKGROUND), | |
| 117 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 116 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 | 119 |
| 121 bool SRTGlobalError::HasMenuItem() { | 120 bool SRTGlobalError::HasMenuItem() { |
| 122 return true; | 121 return true; |
| 123 } | 122 } |
| 124 | 123 |
| 125 int SRTGlobalError::MenuItemCommandID() { | 124 int SRTGlobalError::MenuItemCommandID() { |
| 126 return IDC_SHOW_SRT_BUBBLE; | 125 return IDC_SHOW_SRT_BUBBLE; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 182 } |
| 184 | 183 |
| 185 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | 184 void SRTGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
| 186 OnUserinteractionStarted(SRT_PROMPT_ACCEPTED); | 185 OnUserinteractionStarted(SRT_PROMPT_ACCEPTED); |
| 187 MaybeExecuteSRT(); | 186 MaybeExecuteSRT(); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | 189 void SRTGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 191 OnUserinteractionStarted(SRT_PROMPT_DENIED); | 190 OnUserinteractionStarted(SRT_PROMPT_DENIED); |
| 192 base::PostTaskWithTraits( | 191 base::PostTaskWithTraits( |
| 193 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 192 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 194 base::TaskPriority::BACKGROUND), | |
| 195 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 193 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 196 OnUserinteractionDone(); | 194 OnUserinteractionDone(); |
| 197 } | 195 } |
| 198 | 196 |
| 199 bool SRTGlobalError::ShouldCloseOnDeactivate() const { | 197 bool SRTGlobalError::ShouldCloseOnDeactivate() const { |
| 200 return false; | 198 return false; |
| 201 } | 199 } |
| 202 | 200 |
| 203 void SRTGlobalError::MaybeExecuteSRT() { | 201 void SRTGlobalError::MaybeExecuteSRT() { |
| 204 if (downloaded_path_.empty()) { | 202 if (downloaded_path_.empty()) { |
| 205 FallbackToDownloadPage(); | 203 FallbackToDownloadPage(); |
| 206 return; | 204 return; |
| 207 } | 205 } |
| 208 // At this point, this object owns itself, since ownership has been taken back | 206 // At this point, this object owns itself, since ownership has been taken back |
| 209 // from the global_error_service_ in the call to OnUserInteractionStarted. | 207 // from the global_error_service_ in the call to OnUserInteractionStarted. |
| 210 // This means that it is safe to use base::Unretained here. | 208 // This means that it is safe to use base::Unretained here. |
| 211 base::PostTaskWithTraitsAndReplyWithResult( | 209 base::PostTaskWithTraitsAndReplyWithResult( |
| 212 FROM_HERE, | 210 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 213 base::TaskTraits().MayBlock().WithPriority( | |
| 214 base::TaskPriority::BACKGROUND), | |
| 215 base::Bind( | 211 base::Bind( |
| 216 &MaybeExecuteSRTFromBlockingPool, downloaded_path_, | 212 &MaybeExecuteSRTFromBlockingPool, downloaded_path_, |
| 217 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), | 213 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(), |
| 218 SafeBrowsingExtendedReportingEnabled(), | 214 SafeBrowsingExtendedReportingEnabled(), |
| 219 bubble_shown_from_menu_ | 215 bubble_shown_from_menu_ |
| 220 ? chrome_cleaner::ChromePromptValue::kShownFromMenu | 216 ? chrome_cleaner::ChromePromptValue::kShownFromMenu |
| 221 : chrome_cleaner::ChromePromptValue::kPrompted), | 217 : chrome_cleaner::ChromePromptValue::kPrompted), |
| 222 base::Bind( | 218 base::Bind( |
| 223 [](SRTGlobalError* self, bool success) { | 219 [](SRTGlobalError* self, bool success) { |
| 224 if (success) | 220 if (success) |
| 225 self->OnUserinteractionDone(); | 221 self->OnUserinteractionDone(); |
| 226 else | 222 else |
| 227 self->FallbackToDownloadPage(); | 223 self->FallbackToDownloadPage(); |
| 228 }, | 224 }, |
| 229 base::Unretained(this))); | 225 base::Unretained(this))); |
| 230 } | 226 } |
| 231 | 227 |
| 232 void SRTGlobalError::FallbackToDownloadPage() { | 228 void SRTGlobalError::FallbackToDownloadPage() { |
| 233 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK); | 229 RecordSRTPromptHistogram(SRT_PROMPT_FALLBACK); |
| 234 | 230 |
| 235 Browser* browser = chrome::FindLastActive(); | 231 Browser* browser = chrome::FindLastActive(); |
| 236 if (browser) { | 232 if (browser) { |
| 237 browser->OpenURL( | 233 browser->OpenURL( |
| 238 content::OpenURLParams(GURL(kSRTDownloadURL), content::Referrer(), | 234 content::OpenURLParams(GURL(kSRTDownloadURL), content::Referrer(), |
| 239 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 235 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 240 ui::PAGE_TRANSITION_LINK, false)); | 236 ui::PAGE_TRANSITION_LINK, false)); |
| 241 } | 237 } |
| 242 | 238 |
| 243 base::PostTaskWithTraits( | 239 base::PostTaskWithTraits( |
| 244 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 240 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 245 base::TaskPriority::BACKGROUND), | |
| 246 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); | 241 base::Bind(&DeleteFilesFromBlockingPool, downloaded_path_)); |
| 247 OnUserinteractionDone(); | 242 OnUserinteractionDone(); |
| 248 } | 243 } |
| 249 | 244 |
| 250 void SRTGlobalError::OnUserinteractionStarted( | 245 void SRTGlobalError::OnUserinteractionStarted( |
| 251 SRTPromptHistogramValue histogram_value) { | 246 SRTPromptHistogramValue histogram_value) { |
| 252 // This is for cases where the UI doesn't go away quickly enough and user | 247 // This is for cases where the UI doesn't go away quickly enough and user |
| 253 // might click on the button more than once, or more than one button. | 248 // might click on the button more than once, or more than one button. |
| 254 if (interacted_) | 249 if (interacted_) |
| 255 return; | 250 return; |
| 256 RecordSRTPromptHistogram(histogram_value); | 251 RecordSRTPromptHistogram(histogram_value); |
| 257 interacted_ = true; | 252 interacted_ = true; |
| 258 if (global_error_service_) { | 253 if (global_error_service_) { |
| 259 global_error_service_->RemoveGlobalError(this).release(); | 254 global_error_service_->RemoveGlobalError(this).release(); |
| 260 global_error_service_ = nullptr; | 255 global_error_service_ = nullptr; |
| 261 } | 256 } |
| 262 } | 257 } |
| 263 | 258 |
| 264 void SRTGlobalError::OnUserinteractionDone() { | 259 void SRTGlobalError::OnUserinteractionDone() { |
| 265 DCHECK(interacted_); | 260 DCHECK(interacted_); |
| 266 // Once the user interacted with the bubble, we can forget about any pending | 261 // Once the user interacted with the bubble, we can forget about any pending |
| 267 // prompt. | 262 // prompt. |
| 268 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, | 263 g_browser_process->local_state()->SetBoolean(prefs::kSwReporterPendingPrompt, |
| 269 false); | 264 false); |
| 270 delete this; | 265 delete this; |
| 271 } | 266 } |
| 272 | 267 |
| 273 } // namespace safe_browsing | 268 } // namespace safe_browsing |
| OLD | NEW |