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 <queue> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
11 | 11 |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/permissions/permission_uma_util.h" | 13 #include "chrome/browser/permissions/permission_uma_util.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class Clock; | 18 class Clock; |
18 } // namespace base | 19 } // namespace base |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 class ReportSender; | 22 class ReportSender; |
22 class URLRequestContext; | 23 class URLRequestContext; |
23 } // namespace net | 24 } // namespace net |
24 | 25 |
25 namespace safe_browsing { | 26 namespace safe_browsing { |
26 | 27 |
27 struct PermissionAndOrigin { | 28 struct PermissionAndOrigin { |
28 bool operator==(const PermissionAndOrigin& other) const; | 29 bool operator==(const PermissionAndOrigin& other) const; |
29 | 30 |
30 content::PermissionType permission; | 31 ContentSettingsType permission; |
31 GURL origin; | 32 GURL origin; |
32 }; | 33 }; |
33 | 34 |
34 struct PermissionAndOriginHash { | 35 struct PermissionAndOriginHash { |
35 std::size_t operator()( | 36 std::size_t operator()( |
36 const PermissionAndOrigin& permission_and_origin) const; | 37 const PermissionAndOrigin& permission_and_origin) const; |
37 }; | 38 }; |
38 | 39 |
39 // Provides functionality for building and serializing reports about permissions | 40 // Provides functionality for building and serializing reports about permissions |
40 // to a report collection server. | 41 // to a report collection server. |
(...skipping 23 matching lines...) Expand all Loading... |
64 std::unique_ptr<base::Clock> clock); | 65 std::unique_ptr<base::Clock> clock); |
65 | 66 |
66 // Builds and serializes a permission report with |report_info| included. | 67 // Builds and serializes a permission report with |report_info| included. |
67 // The serialized report is written into |output|. Returns true if the | 68 // The serialized report is written into |output|. Returns true if the |
68 // serialization was successful and false otherwise. | 69 // serialization was successful and false otherwise. |
69 static bool BuildReport(const PermissionReportInfo& report_info, | 70 static bool BuildReport(const PermissionReportInfo& report_info, |
70 std::string* output); | 71 std::string* output); |
71 | 72 |
72 // Returns false if the number of reports sent in the last one minute per | 73 // Returns false if the number of reports sent in the last one minute per |
73 // origin per permission is under a threshold, otherwise true. | 74 // origin per permission is under a threshold, otherwise true. |
74 bool IsReportThresholdExceeded(content::PermissionType permission, | 75 bool IsReportThresholdExceeded(ContentSettingsType permission, |
75 const GURL& origin); | 76 const GURL& origin); |
76 | 77 |
77 std::unique_ptr<net::ReportSender> permission_report_sender_; | 78 std::unique_ptr<net::ReportSender> permission_report_sender_; |
78 | 79 |
79 // TODO(stefanocs): This might introduce a memory issue since older entries | 80 // TODO(stefanocs): This might introduce a memory issue since older entries |
80 // are not removed until a new report with the corresponding key is added. We | 81 // are not removed until a new report with the corresponding key is added. We |
81 // should address this issue if that becomes a problem in the future. | 82 // should address this issue if that becomes a problem in the future. |
82 std::unordered_map<PermissionAndOrigin, | 83 std::unordered_map<PermissionAndOrigin, |
83 std::queue<base::Time>, | 84 std::queue<base::Time>, |
84 PermissionAndOriginHash> | 85 PermissionAndOriginHash> |
85 report_logs_; | 86 report_logs_; |
86 | 87 |
87 std::unique_ptr<base::Clock> clock_; | 88 std::unique_ptr<base::Clock> clock_; |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); | 90 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
90 }; | 91 }; |
91 | 92 |
92 } // namespace safe_browsing | 93 } // namespace safe_browsing |
93 | 94 |
94 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 95 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
OLD | NEW |