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

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

Issue 2648713002: Add response code to the success callback of ReportSender (Closed)
Patch Set: eroman and estark comments Created 3 years, 8 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 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"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "components/safe_browsing/csd.pb.h" 21 #include "components/safe_browsing/csd.pb.h"
22 #include "components/safe_browsing_db/database_manager.h" 22 #include "components/safe_browsing_db/database_manager.h"
23 #include "components/safe_browsing_db/safe_browsing_prefs.h" 23 #include "components/safe_browsing_db/safe_browsing_prefs.h"
24 #include "components/variations/variations_associated_data.h" 24 #include "components/variations/variations_associated_data.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/http/http_status_code.h"
27 #include "net/url_request/report_sender.h" 28 #include "net/url_request/report_sender.h"
28 #include "skia/ext/image_operations.h" 29 #include "skia/ext/image_operations.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 30 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "ui/gfx/codec/png_codec.h" 31 #include "ui/gfx/codec/png_codec.h"
31 #include "ui/gfx/geometry/size.h" 32 #include "ui/gfx/geometry/size.h"
32 #include "url/gurl.h" 33 #include "url/gurl.h"
33 34
34 using content::BrowserThread; 35 using content::BrowserThread;
35 36
36 namespace safe_browsing { 37 namespace safe_browsing {
37 38
38 namespace { 39 namespace {
39 40
40 const size_t kMaxReportsPerDay = 5; 41 const size_t kMaxReportsPerDay = 5;
41 const base::Feature kNotificationImageReporterFeature{ 42 const base::Feature kNotificationImageReporterFeature{
42 "NotificationImageReporterFeature", base::FEATURE_ENABLED_BY_DEFAULT}; 43 "NotificationImageReporterFeature", base::FEATURE_ENABLED_BY_DEFAULT};
43 const char kReportChance[] = "ReportChance"; 44 const char kReportChance[] = "ReportChance";
44 const char kDefaultMimeType[] = "image/png"; 45 const char kDefaultMimeType[] = "image/png";
45 46
46 // Passed to ReportSender::Send as an ErrorCallback, so must take a GURL, but it 47 // Passed to ReportSender::Send as an ErrorCallback, so must take a GURL, but it
47 // is unused. 48 // is unused.
48 void LogReportResult(const GURL& url, int net_error) { 49 void LogReportResult(const GURL& url, int net_error, int http_response_code) {
49 UMA_HISTOGRAM_SPARSE_SLOWLY("SafeBrowsing.NotificationImageReporter.NetError", 50 UMA_HISTOGRAM_SPARSE_SLOWLY("SafeBrowsing.NotificationImageReporter.NetError",
50 net_error); 51 net_error);
51 } 52 }
52 53
53 } // namespace 54 } // namespace
54 55
55 const char NotificationImageReporter::kReportingUploadUrl[] = 56 const char NotificationImageReporter::kReportingUploadUrl[] =
56 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" 57 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
57 "notification-image"; 58 "notification-image";
58 59
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 report.mutable_image()->mutable_dimensions()->set_height(dimensions.height()); 210 report.mutable_image()->mutable_dimensions()->set_height(dimensions.height());
210 if (dimensions != original_dimensions) { 211 if (dimensions != original_dimensions) {
211 report.mutable_image()->mutable_original_dimensions()->set_width( 212 report.mutable_image()->mutable_original_dimensions()->set_width(
212 original_dimensions.width()); 213 original_dimensions.width());
213 report.mutable_image()->mutable_original_dimensions()->set_height( 214 report.mutable_image()->mutable_original_dimensions()->set_height(
214 original_dimensions.height()); 215 original_dimensions.height());
215 } 216 }
216 217
217 std::string serialized_report; 218 std::string serialized_report;
218 report.SerializeToString(&serialized_report); 219 report.SerializeToString(&serialized_report);
219 report_sender_->Send( 220 report_sender_->Send(GURL(kReportingUploadUrl), "application/octet-stream",
220 GURL(kReportingUploadUrl), "application/octet-stream", serialized_report, 221 serialized_report,
221 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), net::OK), 222 base::Bind(&LogReportResult, GURL(kReportingUploadUrl),
222 base::Bind(&LogReportResult)); 223 net::OK, net::HTTP_OK),
224 base::Bind(&LogReportResult));
223 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. 225 // TODO(johnme): Consider logging bandwidth and/or duration to UMA.
224 } 226 }
225 227
226 } // namespace safe_browsing 228 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/mock_permission_report_sender.cc ('k') | chrome/browser/safe_browsing/permission_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698