Chromium Code Reviews| Index: chrome/browser/safe_browsing/permission_reporter.h |
| diff --git a/chrome/browser/safe_browsing/permission_reporter.h b/chrome/browser/safe_browsing/permission_reporter.h |
| index 523de8e57057aa67d749f31333c690896448f132..2c78887813c9a58d22ccb4a9acf8771f55e26268 100644 |
| --- a/chrome/browser/safe_browsing/permission_reporter.h |
| +++ b/chrome/browser/safe_browsing/permission_reporter.h |
| @@ -5,11 +5,18 @@ |
| #ifndef CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
| #define CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
| +#include <queue> |
| #include <string> |
| +#include <unordered_map> |
| +#include "base/time/time.h" |
| #include "chrome/browser/permissions/permission_uma_util.h" |
| #include "url/gurl.h" |
| +namespace base { |
| +class Clock; |
| +} // namespace base |
| + |
| namespace net { |
| class ReportSender; |
| class URLRequestContext; |
| @@ -17,6 +24,18 @@ class URLRequestContext; |
| namespace safe_browsing { |
| +struct PermissionAndOrigin { |
| + bool operator==(const PermissionAndOrigin& other) const; |
| + |
| + content::PermissionType permission; |
| + GURL origin; |
| +}; |
| + |
| +struct PermissionAndOriginHash { |
| + std::size_t operator()( |
| + const PermissionAndOrigin& permission_and_origin) const; |
| +}; |
| + |
| // Provides functionality for building and serializing reports about permissions |
| // to a report collection server. |
| class PermissionReporter { |
| @@ -42,8 +61,9 @@ class PermissionReporter { |
| friend class PermissionReporterTest; |
| // Used by tests. This constructor allows tests to have access to the |
| - // ReportSender. |
| - explicit PermissionReporter(std::unique_ptr<net::ReportSender> report_sender); |
| + // ReportSender and use a test Clock. |
| + explicit PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, |
|
kcarattini
2016/07/06 06:28:20
This no longer needs to be explicit with 2 argumen
stefanocs
2016/07/06 07:17:38
Done.
|
| + std::unique_ptr<base::Clock> clock); |
| // Builds and serializes a permission report with |origin| as the origin of |
| // the site requesting permission, |permission| as the type of permission |
| @@ -55,8 +75,19 @@ class PermissionReporter { |
| PermissionAction action, |
| std::string* output); |
| + // Returns true if the number of reports sent in the last one minute per |
| + // origin per permission is under a threshold, otherwise false. |
| + bool IsAllowedToSend(content::PermissionType permission, const GURL& origin); |
|
kcarattini
2016/07/06 06:28:20
How about something a bit more descriptive to what
stefanocs
2016/07/06 07:17:38
Done.
|
| + |
| std::unique_ptr<net::ReportSender> permission_report_sender_; |
| + std::unordered_map<PermissionAndOrigin, |
| + std::queue<base::Time>, |
| + PermissionAndOriginHash> |
| + sent_histories; |
| + |
| + std::unique_ptr<base::Clock> clock_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
| }; |