OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/download/download_danger_prompt.h" | 5 #include "chrome/browser/download/download_danger_prompt.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/download/download_stats.h" | 9 #include "chrome/browser/download/download_stats.h" |
10 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | 10 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 RunDone(DISMISS); | 236 RunDone(DISMISS); |
237 } | 237 } |
238 | 238 |
239 void DownloadDangerPromptImpl::RunDone(Action action) { | 239 void DownloadDangerPromptImpl::RunDone(Action action) { |
240 // Invoking the callback can cause the download item state to change or cause | 240 // Invoking the callback can cause the download item state to change or cause |
241 // the constrained window to close, and |callback| refers to a member | 241 // the constrained window to close, and |callback| refers to a member |
242 // variable. | 242 // variable. |
243 OnDone done = done_; | 243 OnDone done = done_; |
244 done_.Reset(); | 244 done_.Reset(); |
245 if (download_ != NULL) { | 245 if (download_ != NULL) { |
246 const bool accept = action == DownloadDangerPrompt::ACCEPT; | 246 // If this download is no longer dangerous, or is already canceled or |
247 RecordDownloadDangerPrompt(accept, *download_); | 247 // completed, don't send any report. |
248 if (!download_->GetURL().is_empty() && | 248 if (download_->IsDangerous() && !download_->IsDone()) { |
249 !download_->GetBrowserContext()->IsOffTheRecord()) { | 249 const bool accept = action == DownloadDangerPrompt::ACCEPT; |
250 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); | 250 RecordDownloadDangerPrompt(accept, *download_); |
| 251 if (!download_->GetURL().is_empty() && |
| 252 !download_->GetBrowserContext()->IsOffTheRecord()) { |
| 253 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); |
| 254 } |
251 } | 255 } |
252 download_->RemoveObserver(this); | 256 download_->RemoveObserver(this); |
253 download_ = NULL; | 257 download_ = NULL; |
254 } | 258 } |
255 if (!done.is_null()) | 259 if (!done.is_null()) |
256 done.Run(action); | 260 done.Run(action); |
257 } | 261 } |
258 | 262 |
259 } // namespace | 263 } // namespace |
260 | 264 |
261 // static | 265 // static |
262 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 266 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
263 content::DownloadItem* item, | 267 content::DownloadItem* item, |
264 content::WebContents* web_contents, | 268 content::WebContents* web_contents, |
265 bool show_context, | 269 bool show_context, |
266 const OnDone& done) { | 270 const OnDone& done) { |
267 DownloadDangerPromptImpl* prompt = | 271 DownloadDangerPromptImpl* prompt = |
268 new DownloadDangerPromptImpl(item, web_contents, show_context, done); | 272 new DownloadDangerPromptImpl(item, web_contents, show_context, done); |
269 // |prompt| will be deleted when the dialog is done. | 273 // |prompt| will be deleted when the dialog is done. |
270 TabModalConfirmDialog::Create(prompt, web_contents); | 274 TabModalConfirmDialog::Create(prompt, web_contents); |
271 return prompt; | 275 return prompt; |
272 } | 276 } |
OLD | NEW |