Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7332)

Unified Diff: chrome/browser/safe_browsing/permission_reporter.h

Issue 2089383005: Add throttling to permission reporter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add-hooks-to-permission-layer
Patch Set: Add comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+};
raymes 2016/06/29 07:09:17 nit: If we define these as nested classes within P
stefanocs 2016/06/30 00:24:51 Do you mean these structs should be forward declar
+
// 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,
+ 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);
+
std::unique_ptr<net::ReportSender> permission_report_sender_;
+ std::unordered_map<PermissionAndOrigin,
+ std::queue<base::Time>,
+ PermissionAndOriginHash>
+ sent_histories;
raymes 2016/06/29 07:09:17 It seems like we might need this complexity then u
stefanocs 2016/06/30 00:24:51 Acknowledged.
+
+ std::unique_ptr<base::Clock> clock_;
+
DISALLOW_COPY_AND_ASSIGN(PermissionReporter);
};

Powered by Google App Engine
This is Rietveld 408576698