OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
7 | 7 |
8 #include <queue> | |
8 #include <string> | 9 #include <string> |
10 #include <unordered_map> | |
9 | 11 |
12 #include "base/time/time.h" | |
10 #include "chrome/browser/permissions/permission_uma_util.h" | 13 #include "chrome/browser/permissions/permission_uma_util.h" |
11 #include "url/gurl.h" | 14 #include "url/gurl.h" |
12 | 15 |
13 namespace net { | 16 namespace net { |
14 class ReportSender; | 17 class ReportSender; |
15 class URLRequestContext; | 18 class URLRequestContext; |
16 } // namespace net | 19 } // namespace net |
17 | 20 |
18 namespace safe_browsing { | 21 namespace safe_browsing { |
19 | 22 |
23 struct PermissionAndOrigin { | |
24 bool operator==(const PermissionAndOrigin& other) const; | |
25 | |
26 content::PermissionType permission; | |
27 GURL origin; | |
28 }; | |
29 | |
30 struct PermissionAndOriginHash { | |
31 std::size_t operator()( | |
32 const PermissionAndOrigin& permission_and_origin) const; | |
33 }; | |
34 | |
20 // Provides functionality for building and serializing reports about permissions | 35 // Provides functionality for building and serializing reports about permissions |
21 // to a report collection server. | 36 // to a report collection server. |
22 class PermissionReporter { | 37 class PermissionReporter { |
23 public: | 38 public: |
24 // Creates a permission reporter that will send permission reports to | 39 // Creates a permission reporter that will send permission reports to |
25 // the SafeBrowsing permission action server, using |request_context| as the | 40 // the SafeBrowsing permission action server, using |request_context| as the |
26 // context for the reports. | 41 // context for the reports. |
27 explicit PermissionReporter(net::URLRequestContext* request_context); | 42 explicit PermissionReporter(net::URLRequestContext* request_context); |
28 | 43 |
29 ~PermissionReporter(); | 44 ~PermissionReporter(); |
(...skipping 18 matching lines...) Expand all Loading... | |
48 // Builds and serializes a permission report with |origin| as the origin of | 63 // Builds and serializes a permission report with |origin| as the origin of |
49 // the site requesting permission, |permission| as the type of permission | 64 // the site requesting permission, |permission| as the type of permission |
50 // requested, and |action| as the action taken. The serialized report is | 65 // requested, and |action| as the action taken. The serialized report is |
51 // written into |output|. Returns true if the serialization was successful and | 66 // written into |output|. Returns true if the serialization was successful and |
52 // false otherwise. | 67 // false otherwise. |
53 static bool BuildReport(const GURL& origin, | 68 static bool BuildReport(const GURL& origin, |
54 content::PermissionType permission, | 69 content::PermissionType permission, |
55 PermissionAction action, | 70 PermissionAction action, |
56 std::string* output); | 71 std::string* output); |
57 | 72 |
73 // Returns true if the number of reports sent in the last one minute per | |
74 // origin per permission is less than |kMaximumReportPerOriginPerPermission|, | |
75 // otherwise false. | |
raymes
2016/06/27 06:26:56
nit: probably don't reference the constant here, s
stefanocs
2016/06/27 07:34:57
Done.
| |
76 bool IsAllowedToSend(content::PermissionType permission, const GURL& origin); | |
77 | |
58 std::unique_ptr<net::ReportSender> permission_report_sender_; | 78 std::unique_ptr<net::ReportSender> permission_report_sender_; |
59 | 79 |
80 std::unordered_map<PermissionAndOrigin, | |
81 std::queue<base::Time>, | |
raymes
2016/06/27 06:26:56
I think perhaps we can simplify this a little bit.
stefanocs
2016/06/27 07:34:57
I think it would be possible to have more than fiv
| |
82 PermissionAndOriginHash> | |
83 sent_histories; | |
84 | |
60 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); | 85 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
61 }; | 86 }; |
62 | 87 |
63 } // namespace safe_browsing | 88 } // namespace safe_browsing |
64 | 89 |
65 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 90 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
OLD | NEW |