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

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

Issue 2624193004: Submit a sample of notification images to Safe Browsing (Closed)
Patch Set: Add basic success test Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
7
8 #include <memory>
9 #include <queue>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h"
14
15 class GURL;
16 class Profile;
17 class SkBitmap;
18
19 namespace base {
20 class RefCountedMemory;
21 } // namespace base
22
23 namespace gfx {
24 class Size;
25 } // namespace gfx
26
27 namespace net {
28 class ReportSender;
29 class URLRequestContext;
30 } // namespace net
31
32 namespace safe_browsing {
33
34 class SafeBrowsingService;
35
36 // Provides functionality for building and sending reports about notification
37 // content images to the Safe Browsing CSD server.
38 class NotificationImageReporter
39 : public base::RefCountedThreadSafe<NotificationImageReporter> {
40 public:
41 explicit NotificationImageReporter(net::URLRequestContext* request_context);
42
43 // Report notification content image to SafeBrowsing CSD server if the user
44 // has opted in, the origin is not whitelisted, and it is randomly sampled.
45 // Can only be called on UI thread.
46 void ReportNotificationImageOnUI(Profile* profile,
47 const GURL& origin,
48 const SkBitmap& image);
49
50 protected:
51 explicit NotificationImageReporter(
52 std::unique_ptr<net::ReportSender> report_sender);
53 virtual ~NotificationImageReporter();
54
55 // Fraction of images to randomly report.
56 virtual double GetReportChance();
57
58 private:
59 friend class base::RefCountedThreadSafe<NotificationImageReporter>;
60
61 // Report notification content image to SafeBrowsing CSD server if necessary.
62 void ReportNotificationImageOnIO(
63 scoped_refptr<SafeBrowsingService> safe_browsing_service,
64 const GURL& origin,
65 const SkBitmap& image);
66
67 // Downscales image to fit within 512x512 if necessary, and encodes as it PNG.
68 void DownscaleNotificationImageOnBlockingPool(const GURL& origin,
69 const SkBitmap& image);
70
71 // Serializes report using NotificationImageReportRequest protobuf defined in
72 // chrome/common/safe_browsing/csd.proto and sends it to CSD server.
73 void SendReportOnIO(const GURL& origin,
74 scoped_refptr<base::RefCountedMemory> png_data,
75 const gfx::Size& dimensions,
76 const gfx::Size& original_dimensions);
77
78 std::unique_ptr<net::ReportSender> report_sender_;
79
80 // Timestamps of when we sent notification images. Used to limit the number
81 // of requests that we send in a day. Only access on the IO thread.
82 // TODO(johnme): Serialize this so that it doesn't reset on browser restart.
83 std::queue<base::Time> report_times_;
84
85 DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter);
86 };
87
88 } // namespace safe_browsing
89
90 #endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698