Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/safe_browsing/download_feedback_service.cc

Issue 2696973002: Allow Safe Browsing backend to select downloads to upload. (Closed)
Patch Set: Add unittest for DownloadProtectionService Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
85 } 85 }
86 86
87 DownloadFeedbackService::~DownloadFeedbackService() { 87 DownloadFeedbackService::~DownloadFeedbackService() {
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
89 } 89 }
90 90
91 // static 91 // static
92 void DownloadFeedbackService::MaybeStorePingsForDownload( 92 void DownloadFeedbackService::MaybeStorePingsForDownload(
93 DownloadProtectionService::DownloadCheckResult result, 93 DownloadProtectionService::DownloadCheckResult result,
94 bool upload_requested,
94 content::DownloadItem* download, 95 content::DownloadItem* download,
95 const std::string& ping, 96 const std::string& ping,
96 const std::string& response) { 97 const std::string& response) {
98 // Is this result worthy of triggering an upload?
99 bool upload_due_to_result = false;
97 switch (result) { 100 switch (result) {
98 case DownloadProtectionService::UNKNOWN: 101 case DownloadProtectionService::UNKNOWN:
99 case DownloadProtectionService::SAFE: 102 case DownloadProtectionService::SAFE:
100 case DownloadProtectionService::DANGEROUS: 103 case DownloadProtectionService::DANGEROUS:
101 return; 104 upload_due_to_result = false;
105 break;
102 case DownloadProtectionService::UNCOMMON: 106 case DownloadProtectionService::UNCOMMON:
103 case DownloadProtectionService::DANGEROUS_HOST: 107 case DownloadProtectionService::DANGEROUS_HOST:
104 case DownloadProtectionService::POTENTIALLY_UNWANTED: 108 case DownloadProtectionService::POTENTIALLY_UNWANTED:
109 upload_due_to_result = true;
105 break; // Fall through. 110 break; // Fall through.
106 } 111 }
112
113 if (!upload_requested && !upload_due_to_result)
114 return;
115
116 // Log if the result said no upload, but the server requested it anyway.
117 UMA_HISTOGRAM_BOOLEAN("SBDownloadFeedback.UploadRequestedByServer",
118 !upload_due_to_result && upload_requested);
119
107 UMA_HISTOGRAM_COUNTS("SBDownloadFeedback.SizeEligibleKB", 120 UMA_HISTOGRAM_COUNTS("SBDownloadFeedback.SizeEligibleKB",
108 download->GetReceivedBytes() / 1024); 121 download->GetReceivedBytes() / 1024);
109 if (download->GetReceivedBytes() > DownloadFeedback::kMaxUploadSize) 122 if (download->GetReceivedBytes() > DownloadFeedback::kMaxUploadSize)
110 return; 123 return;
111 124
112 DownloadFeedbackPings::CreateForDownload(download, ping, response); 125 DownloadFeedbackPings::CreateForDownload(download, ping, response);
113 } 126 }
114 127
115 // static 128 // static
116 bool DownloadFeedbackService::IsEnabledForDownload( 129 bool DownloadFeedbackService::IsEnabledForDownload(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void DownloadFeedbackService::FeedbackComplete() { 218 void DownloadFeedbackService::FeedbackComplete() {
206 DVLOG(1) << __func__; 219 DVLOG(1) << __func__;
207 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 220 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
208 DCHECK(!active_feedback_.empty()); 221 DCHECK(!active_feedback_.empty());
209 active_feedback_.pop(); 222 active_feedback_.pop();
210 if (!active_feedback_.empty()) 223 if (!active_feedback_.empty())
211 StartPendingFeedback(); 224 StartPendingFeedback();
212 } 225 }
213 226
214 } // namespace safe_browsing 227 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698