Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <queue> | |
|
Peter Beverloo
2017/01/11 18:23:56
#include <memory>
johnme
2017/01/11 20:05:07
Done.
| |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/time/time.h" | |
| 13 #include "ui/gfx/geometry/size.h" | |
| 14 | |
| 15 class GURL; | |
| 16 class Profile; | |
| 17 class SkBitmap; | |
| 18 | |
| 19 namespace base { | |
| 20 class RefCountedMemory; | |
| 21 } // namespace base | |
| 22 | |
| 23 namespace net { | |
| 24 class ReportSender; | |
| 25 class URLRequestContext; | |
| 26 } // namespace net | |
| 27 | |
| 28 namespace safe_browsing { | |
| 29 | |
| 30 class SafeBrowsingService; | |
| 31 | |
| 32 // Provides functionality for building and sending reports about notification | |
| 33 // content images to the Safe Browsing CSD server. | |
| 34 class NotificationImageReporter | |
| 35 : public base::RefCountedThreadSafe<NotificationImageReporter> { | |
| 36 public: | |
| 37 explicit NotificationImageReporter(net::URLRequestContext* request_context); | |
| 38 | |
| 39 // Reports notification content image to SafeBrowsing CSD server if necessary. | |
| 40 // Can only be called on UI thread. | |
| 41 void ReportNotificationImageOnUI(Profile* profile, | |
| 42 const GURL& origin, | |
| 43 const SkBitmap& image); | |
| 44 | |
| 45 private: | |
| 46 friend class base::RefCountedThreadSafe<NotificationImageReporter>; | |
| 47 ~NotificationImageReporter(); | |
| 48 | |
| 49 // Report notification content image to SafeBrowsing CSD server if necessary. | |
|
Peter Beverloo
2017/01/11 18:23:56
"if necessary" -> would be cool to give a one sent
johnme
2017/01/11 20:05:07
Done ("if the user has opted in, the origin is not
| |
| 50 void ReportNotificationImageOnIO( | |
| 51 scoped_refptr<SafeBrowsingService> safe_browsing_service, | |
| 52 const GURL& origin, | |
| 53 const SkBitmap& image); | |
| 54 | |
| 55 // Downscales image to fit within 512x512 if necessary, and encodes as it PNG. | |
| 56 void DownscaleNotificationImageOnBlockingPool(const GURL& origin, | |
| 57 const SkBitmap& image); | |
| 58 | |
| 59 // Serializes report using NotificationImageReportRequest protobuf defined in | |
| 60 // chrome/common/safe_browsing/csd.proto and sends it to CSD server. | |
| 61 void SendReportOnIO(const GURL& origin, | |
| 62 scoped_refptr<base::RefCountedMemory> png_data, | |
| 63 gfx::Size dimensions, | |
| 64 gfx::Size original_dimensions); | |
|
Peter Beverloo
2017/01/11 18:23:56
micro nit: we usually pass gfx::Size as a const&
johnme
2017/01/11 20:05:07
Done.
| |
| 65 | |
| 66 std::unique_ptr<net::ReportSender> report_sender_; | |
| 67 | |
| 68 // Timestamps of when we sent notification images. Used to limit the number | |
| 69 // of requests that we send in a day. | |
| 70 // TODO(johnme): Serialize this so that it doesn't reset on browser restart. | |
| 71 std::queue<base::Time> report_times_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter); | |
| 74 }; | |
| 75 | |
| 76 } // namespace safe_browsing | |
| 77 | |
| 78 #endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_ | |
| OLD | NEW |