Chromium Code Reviews| Index: chrome/browser/safe_browsing/notification_image_reporter.h |
| diff --git a/chrome/browser/safe_browsing/notification_image_reporter.h b/chrome/browser/safe_browsing/notification_image_reporter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d97613de75b8486c751990011a86729208d496c5 |
| --- /dev/null |
| +++ b/chrome/browser/safe_browsing/notification_image_reporter.h |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_ |
| +#define CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_ |
| + |
| +#include <queue> |
|
Peter Beverloo
2017/01/11 18:23:56
#include <memory>
johnme
2017/01/11 20:05:07
Done.
|
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/time/time.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +class GURL; |
| +class Profile; |
| +class SkBitmap; |
| + |
| +namespace base { |
| +class RefCountedMemory; |
| +} // namespace base |
| + |
| +namespace net { |
| +class ReportSender; |
| +class URLRequestContext; |
| +} // namespace net |
| + |
| +namespace safe_browsing { |
| + |
| +class SafeBrowsingService; |
| + |
| +// Provides functionality for building and sending reports about notification |
| +// content images to the Safe Browsing CSD server. |
| +class NotificationImageReporter |
| + : public base::RefCountedThreadSafe<NotificationImageReporter> { |
| + public: |
| + explicit NotificationImageReporter(net::URLRequestContext* request_context); |
| + |
| + // Reports notification content image to SafeBrowsing CSD server if necessary. |
| + // Can only be called on UI thread. |
| + void ReportNotificationImageOnUI(Profile* profile, |
| + const GURL& origin, |
| + const SkBitmap& image); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<NotificationImageReporter>; |
| + ~NotificationImageReporter(); |
| + |
| + // 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
|
| + void ReportNotificationImageOnIO( |
| + scoped_refptr<SafeBrowsingService> safe_browsing_service, |
| + const GURL& origin, |
| + const SkBitmap& image); |
| + |
| + // Downscales image to fit within 512x512 if necessary, and encodes as it PNG. |
| + void DownscaleNotificationImageOnBlockingPool(const GURL& origin, |
| + const SkBitmap& image); |
| + |
| + // Serializes report using NotificationImageReportRequest protobuf defined in |
| + // chrome/common/safe_browsing/csd.proto and sends it to CSD server. |
| + void SendReportOnIO(const GURL& origin, |
| + scoped_refptr<base::RefCountedMemory> png_data, |
| + gfx::Size dimensions, |
| + 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.
|
| + |
| + std::unique_ptr<net::ReportSender> report_sender_; |
| + |
| + // Timestamps of when we sent notification images. Used to limit the number |
| + // of requests that we send in a day. |
| + // TODO(johnme): Serialize this so that it doesn't reset on browser restart. |
| + std::queue<base::Time> report_times_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NotificationImageReporter); |
| +}; |
| + |
| +} // namespace safe_browsing |
| + |
| +#endif // CHROME_BROWSER_SAFE_BROWSING_NOTIFICATION_IMAGE_REPORTER_H_ |