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 <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 private: | |
| 51 friend class base::RefCountedThreadSafe<NotificationImageReporter>; | |
| 52 ~NotificationImageReporter(); | |
| 53 | |
| 54 // Report notification content image to SafeBrowsing CSD server if necessary. | |
| 55 void ReportNotificationImageOnIO( | |
| 56 scoped_refptr<SafeBrowsingService> safe_browsing_service, | |
| 57 const GURL& origin, | |
| 58 const SkBitmap& image); | |
| 59 | |
| 60 // Downscales image to fit within 512x512 if necessary, and encodes as it PNG. | |
| 61 void DownscaleNotificationImageOnBlockingPool(const GURL& origin, | |
|
Nathan Parker
2017/01/11 22:34:38
What's the output of this? (i.e. does it invoke Se
johnme
2017/01/13 02:38:17
Done.
| |
| 62 const SkBitmap& image); | |
| 63 | |
| 64 // Serializes report using NotificationImageReportRequest protobuf defined in | |
| 65 // chrome/common/safe_browsing/csd.proto and sends it to CSD server. | |
| 66 void SendReportOnIO(const GURL& origin, | |
| 67 scoped_refptr<base::RefCountedMemory> png_data, | |
| 68 const gfx::Size& dimensions, | |
| 69 const gfx::Size& original_dimensions); | |
| 70 | |
| 71 std::unique_ptr<net::ReportSender> report_sender_; | |
| 72 | |
| 73 // Timestamps of when we sent notification images. Used to limit the number | |
| 74 // of requests that we send in a day. Only access on the IO thread. | |
| 75 // TODO(johnme): Serialize this so that it doesn't reset on browser restart. | |
| 76 std::queue<base::Time> report_times_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter); | |
| 79 }; | |
| 80 | |
| 81 } // namespace safe_browsing | |
| 82 | |
| 83 #endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_ | |
| OLD | NEW |