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

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

Issue 2637153002: Submit a sample of notification images to Safe Browsing (Closed)
Patch Set: nits 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/memory/weak_ptr.h"
14 #include "base/time/time.h"
15
16 class GURL;
17 class Profile;
18 class SkBitmap;
19
20 namespace base {
21 class RefCountedMemory;
22 } // namespace base
23
24 namespace gfx {
25 class Size;
26 } // namespace gfx
27
28 namespace net {
29 class ReportSender;
30 class URLRequestContext;
31 } // namespace net
32
33 namespace safe_browsing {
34
35 class SafeBrowsingDatabaseManager;
36
37 // Provides functionality for building and sending reports about notification
38 // content images to the Safe Browsing CSD server.
39 class NotificationImageReporter {
40 public:
41 // CSD server URL to which notification image reports are sent.
42 static const char kReportingUploadUrl[];
43
44 explicit NotificationImageReporter(net::URLRequestContext* request_context);
45 virtual ~NotificationImageReporter();
46
47 // Report notification content image to SafeBrowsing CSD server if the user
48 // has opted in, the origin is not whitelisted, and it is randomly sampled.
49 // Can only be called on IO thread.
50 void ReportNotificationImageOnIO(
51 Profile* profile,
52 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
53 const GURL& origin,
54 const SkBitmap& image);
55
56 protected:
57 explicit NotificationImageReporter(
58 std::unique_ptr<net::ReportSender> report_sender);
59
60 // Get the percentage of images that should be reported from Finch.
61 virtual double GetReportChance() const;
62
63 // Tests may wish to override this to find out if reports are skipped. Called
64 // on the IO thread.
65 virtual void SkippedReporting();
66
67 private:
68 // Report notification content image to SafeBrowsing CSD server if necessary,
69 // by invoking DownscaleNotificationImageOnBlockingPool. This should be
70 // called on the IO thread and will invoke a member function on the IO thread
71 // using the IO-based WeapPtr.
72 static void ReportNotificationImageOnUI(
73 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io,
74 Profile* profile,
75 const GURL& origin,
76 const SkBitmap& image);
77
78 // Downscales image to fit within 512x512 if necessary, and encodes as it PNG,
79 // then invokes SendReportOnIO. This should be called on a blocking pool
80 // thread and will invoke a member function on the IO thread using the
81 // IO-based WeakPtr.
82 static void DownscaleNotificationImageOnBlockingPool(
83 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io,
84 const GURL& origin,
85 const SkBitmap& image);
86
87 // Serializes report using NotificationImageReportRequest protobuf defined in
88 // chrome/common/safe_browsing/csd.proto and sends it to CSD server.
89 void SendReportOnIO(const GURL& origin,
90 scoped_refptr<base::RefCountedMemory> data,
91 const gfx::Size& dimensions,
92 const gfx::Size& original_dimensions);
93
94 std::unique_ptr<net::ReportSender> report_sender_;
95
96 // Timestamps of when we sent notification images. Used to limit the number
97 // of requests that we send in a day. Only access on the IO thread.
98 // TODO(johnme): Serialize this so that it doesn't reset on browser restart.
99 std::queue<base::Time> report_times_;
100
101 // Keep this last. Only dereference these pointers on the IO thread.
102 base::WeakPtrFactory<NotificationImageReporter> weak_factory_on_io_;
103
104 DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter);
105 };
106
107 } // namespace safe_browsing
108
109 #endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698