Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/download_feedback_service.h" | 5 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | |
| 11 #include "base/files/file_util_proxy.h" | 12 #include "base/files/file_util_proxy.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 14 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 15 #include "chrome/browser/safe_browsing/download_feedback.h" | 16 #include "chrome/browser/safe_browsing/download_feedback.h" |
| 16 #include "content/public/browser/download_danger_type.h" | 17 #include "content/public/browser/download_danger_type.h" |
| 17 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
| 18 | 19 |
| 19 namespace safe_browsing { | 20 namespace safe_browsing { |
| 20 | 21 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 134 } |
| 134 | 135 |
| 135 // static | 136 // static |
| 136 void DownloadFeedbackService::RecordEligibleDownloadShown( | 137 void DownloadFeedbackService::RecordEligibleDownloadShown( |
| 137 content::DownloadDangerType danger_type) { | 138 content::DownloadDangerType danger_type) { |
| 138 UMA_HISTOGRAM_ENUMERATION("SBDownloadFeedback.Eligible", | 139 UMA_HISTOGRAM_ENUMERATION("SBDownloadFeedback.Eligible", |
| 139 danger_type, | 140 danger_type, |
| 140 content::DOWNLOAD_DANGER_TYPE_MAX); | 141 content::DOWNLOAD_DANGER_TYPE_MAX); |
| 141 } | 142 } |
| 142 | 143 |
| 143 | |
| 144 void DownloadFeedbackService::BeginFeedbackForDownload( | 144 void DownloadFeedbackService::BeginFeedbackForDownload( |
| 145 content::DownloadItem* download) { | 145 content::DownloadItem* download, |
| 146 DownloadCommands::Command download_command) { | |
| 146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 147 | |
| 148 UMA_HISTOGRAM_ENUMERATION("SBDownloadFeedback.Activations", | 148 UMA_HISTOGRAM_ENUMERATION("SBDownloadFeedback.Activations", |
| 149 download->GetDangerType(), | 149 download->GetDangerType(), |
| 150 content::DOWNLOAD_DANGER_TYPE_MAX); | 150 content::DOWNLOAD_DANGER_TYPE_MAX); |
| 151 | 151 |
| 152 DownloadFeedbackPings* pings = DownloadFeedbackPings::FromDownload(*download); | 152 DownloadFeedbackPings* pings = DownloadFeedbackPings::FromDownload(*download); |
| 153 DCHECK(pings); | 153 DCHECK(pings); |
| 154 | 154 |
| 155 download->StealDangerousDownload( | 155 download->StealDangerousDownload( |
| 156 download_command == DownloadCommands::DISCARD, | |
| 156 base::Bind(&DownloadFeedbackService::BeginFeedbackOrDeleteFile, | 157 base::Bind(&DownloadFeedbackService::BeginFeedbackOrDeleteFile, |
| 157 file_task_runner_, | 158 file_task_runner_, weak_ptr_factory_.GetWeakPtr(), |
| 158 weak_ptr_factory_.GetWeakPtr(), | 159 pings->ping_request(), pings->ping_response())); |
| 159 pings->ping_request(), | 160 if (download_command == DownloadCommands::KEEP) |
| 160 pings->ping_response())); | 161 DownloadCommands(download).ExecuteCommand(download_command); |
| 161 } | 162 } |
| 162 | 163 |
| 163 // static | 164 // static |
| 164 void DownloadFeedbackService::BeginFeedbackOrDeleteFile( | 165 void DownloadFeedbackService::BeginFeedbackOrDeleteFile( |
| 165 const scoped_refptr<base::TaskRunner>& file_task_runner, | 166 const scoped_refptr<base::TaskRunner>& file_task_runner, |
| 166 const base::WeakPtr<DownloadFeedbackService>& service, | 167 const base::WeakPtr<DownloadFeedbackService>& service, |
| 167 const std::string& ping_request, | 168 const std::string& ping_request, |
| 168 const std::string& ping_response, | 169 const std::string& ping_response, |
| 169 const base::FilePath& path) { | 170 const base::FilePath& path) { |
| 170 if (service) { | 171 if (service) { |
| 172 if (path.empty()) { | |
| 173 UMA_HISTOGRAM_BOOLEAN("SBDownloadFeedback.EmptyFilePathFailure", true); | |
|
Steven Holte
2016/11/14 21:34:34
It would be better to consolidate these into singl
Jialiu Lin
2016/11/14 21:55:07
Done.
| |
| 174 return; | |
| 175 } | |
| 176 UMA_HISTOGRAM_BOOLEAN("SBDownloadFeedback.EmptyFilePathFailure", false); | |
| 171 service->BeginFeedback(ping_request, ping_response, path); | 177 service->BeginFeedback(ping_request, ping_response, path); |
| 172 } else { | 178 } else { |
| 173 base::FileUtilProxy::DeleteFile(file_task_runner.get(), | 179 base::FileUtilProxy::DeleteFile(file_task_runner.get(), |
| 174 path, | 180 path, |
| 175 false, | 181 false, |
| 176 base::FileUtilProxy::StatusCallback()); | 182 base::FileUtilProxy::StatusCallback()); |
| 177 } | 183 } |
| 178 } | 184 } |
| 179 | 185 |
| 180 void DownloadFeedbackService::StartPendingFeedback() { | 186 void DownloadFeedbackService::StartPendingFeedback() { |
| 181 DCHECK(!active_feedback_.empty()); | 187 DCHECK(!active_feedback_.empty()); |
| 182 active_feedback_.front()->Start(base::Bind( | 188 active_feedback_.front()->Start(base::Bind( |
| 183 &DownloadFeedbackService::FeedbackComplete, base::Unretained(this))); | 189 &DownloadFeedbackService::FeedbackComplete, base::Unretained(this))); |
| 184 } | 190 } |
| 185 | 191 |
| 186 void DownloadFeedbackService::BeginFeedback( | 192 void DownloadFeedbackService::BeginFeedback(const std::string& ping_request, |
| 187 const std::string& ping_request, | 193 const std::string& ping_response, |
| 188 const std::string& ping_response, | 194 const base::FilePath& path) { |
| 189 const base::FilePath& path) { | |
| 190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 195 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 191 std::unique_ptr<DownloadFeedback> feedback(DownloadFeedback::Create( | 196 std::unique_ptr<DownloadFeedback> feedback(DownloadFeedback::Create( |
| 192 request_context_getter_.get(), file_task_runner_.get(), path, | 197 request_context_getter_.get(), file_task_runner_.get(), path, |
| 193 ping_request, ping_response)); | 198 ping_request, ping_response)); |
| 194 active_feedback_.push(std::move(feedback)); | 199 active_feedback_.push(std::move(feedback)); |
| 195 UMA_HISTOGRAM_COUNTS_100("SBDownloadFeedback.ActiveFeedbacks", | 200 UMA_HISTOGRAM_COUNTS_100("SBDownloadFeedback.ActiveFeedbacks", |
| 196 active_feedback_.size()); | 201 active_feedback_.size()); |
| 197 | 202 |
| 198 if (active_feedback_.size() == 1) | 203 if (active_feedback_.size() == 1) |
| 199 StartPendingFeedback(); | 204 StartPendingFeedback(); |
| 200 } | 205 } |
| 201 | 206 |
| 202 void DownloadFeedbackService::FeedbackComplete() { | 207 void DownloadFeedbackService::FeedbackComplete() { |
| 203 DVLOG(1) << __func__; | 208 DVLOG(1) << __func__; |
| 204 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 209 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 205 DCHECK(!active_feedback_.empty()); | 210 DCHECK(!active_feedback_.empty()); |
| 206 active_feedback_.pop(); | 211 active_feedback_.pop(); |
| 207 if (!active_feedback_.empty()) | 212 if (!active_feedback_.empty()) |
| 208 StartPendingFeedback(); | 213 StartPendingFeedback(); |
| 209 } | 214 } |
| 210 | 215 |
| 211 } // namespace safe_browsing | 216 } // namespace safe_browsing |
| OLD | NEW |