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..ee6dd79f042ada6c3daed3948550c1fe9dab32e2 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; |
|
Nathan Parker
2016/07/14 22:00:24
Rather than defining this in the .h file, can you
stefanocs
2016/07/15 02:04:29
This doesn't seem to work.
I added this:
namespa
Nathan Parker
2016/07/15 23:39:40
I was thinking
std::size_t std::hash<safe_browsin
stefanocs
2016/07/18 06:06:17
Hmmm, that doesn't seem to work. It complains abou
|
| +}; |
| + |
| // 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. |
| + PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, |
| + 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,20 @@ class PermissionReporter { |
| PermissionAction action, |
| std::string* output); |
| + // Returns false if the number of reports sent in the last one minute per |
| + // origin per permission is under a threshold, otherwise true. |
| + bool IsReportThresholdExceeded(content::PermissionType permission, |
| + const GURL& origin); |
| + |
| std::unique_ptr<net::ReportSender> permission_report_sender_; |
| + std::unordered_map<PermissionAndOrigin, |
| + std::queue<base::Time>, |
| + PermissionAndOriginHash> |
| + sent_histories; |
|
Nathan Parker
2016/07/14 22:00:24
Should end in underscore.
How about report_log_?
stefanocs
2016/07/15 02:04:29
Done.
|
| + |
| + std::unique_ptr<base::Clock> clock_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
| }; |