OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/notification_image_reporter.h" | 5 #include "chrome/browser/safe_browsing/notification_image_reporter.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 namespace safe_browsing { | 36 namespace safe_browsing { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const size_t kMaxReportsPerDay = 5; | 40 const size_t kMaxReportsPerDay = 5; |
41 const base::Feature kNotificationImageReporterFeature{ | 41 const base::Feature kNotificationImageReporterFeature{ |
42 "NotificationImageReporterFeature", base::FEATURE_ENABLED_BY_DEFAULT}; | 42 "NotificationImageReporterFeature", base::FEATURE_ENABLED_BY_DEFAULT}; |
43 const char kReportChance[] = "ReportChance"; | 43 const char kReportChance[] = "ReportChance"; |
44 const char kDefaultMimeType[] = "image/png"; | 44 const char kDefaultMimeType[] = "image/png"; |
45 | 45 |
46 // Passed to ReportSender::Send as an ErrorCallback, so must take a GURL, but it | 46 // Passed to ReportSender::Send as an ErrorCallback. |
47 // is unused. | 47 void LogReportErrorCallback(const GURL& url, int net_error) { |
48 void LogReportResult(const GURL& url, int net_error) { | |
49 UMA_HISTOGRAM_SPARSE_SLOWLY("SafeBrowsing.NotificationImageReporter.NetError", | 48 UMA_HISTOGRAM_SPARSE_SLOWLY("SafeBrowsing.NotificationImageReporter.NetError", |
50 net_error); | 49 net_error); |
51 } | 50 } |
52 | 51 |
52 // Passed to ReportSender::Send as an SuccessCallback. | |
53 void LogReportSuccessCallback(int response_code) { | |
eroman
2017/04/25 21:02:39
Is it intentional that |response_code| is unused?
meacer
2017/04/25 22:19:07
I intentionally left it unused here, but I think S
| |
54 UMA_HISTOGRAM_SPARSE_SLOWLY("SafeBrowsing.NotificationImageReporter.NetError", | |
55 net::OK); | |
56 } | |
57 | |
53 } // namespace | 58 } // namespace |
54 | 59 |
55 const char NotificationImageReporter::kReportingUploadUrl[] = | 60 const char NotificationImageReporter::kReportingUploadUrl[] = |
56 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" | 61 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
57 "notification-image"; | 62 "notification-image"; |
58 | 63 |
59 NotificationImageReporter::NotificationImageReporter( | 64 NotificationImageReporter::NotificationImageReporter( |
60 net::URLRequestContext* request_context) | 65 net::URLRequestContext* request_context) |
61 : NotificationImageReporter(base::MakeUnique<net::ReportSender>( | 66 : NotificationImageReporter(base::MakeUnique<net::ReportSender>( |
62 request_context, | 67 request_context, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 report.mutable_image()->mutable_dimensions()->set_height(dimensions.height()); | 214 report.mutable_image()->mutable_dimensions()->set_height(dimensions.height()); |
210 if (dimensions != original_dimensions) { | 215 if (dimensions != original_dimensions) { |
211 report.mutable_image()->mutable_original_dimensions()->set_width( | 216 report.mutable_image()->mutable_original_dimensions()->set_width( |
212 original_dimensions.width()); | 217 original_dimensions.width()); |
213 report.mutable_image()->mutable_original_dimensions()->set_height( | 218 report.mutable_image()->mutable_original_dimensions()->set_height( |
214 original_dimensions.height()); | 219 original_dimensions.height()); |
215 } | 220 } |
216 | 221 |
217 std::string serialized_report; | 222 std::string serialized_report; |
218 report.SerializeToString(&serialized_report); | 223 report.SerializeToString(&serialized_report); |
219 report_sender_->Send( | 224 report_sender_->Send(GURL(kReportingUploadUrl), "application/octet-stream", |
220 GURL(kReportingUploadUrl), "application/octet-stream", serialized_report, | 225 serialized_report, base::Bind(&LogReportSuccessCallback), |
221 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), net::OK), | 226 base::Bind(&LogReportErrorCallback)); |
222 base::Bind(&LogReportResult)); | |
223 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. | 227 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. |
224 } | 228 } |
225 | 229 |
226 } // namespace safe_browsing | 230 } // namespace safe_browsing |
OLD | NEW |