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

Side by Side Diff: chrome/browser/safe_browsing/permission_reporter.h

Issue 2178213003: Update RequestTrigger to GestureType in permission report (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 namespace base { 16 namespace base {
17 class Clock; 17 class Clock;
18 } // namespace base 18 } // namespace base
19 19
20 namespace net { 20 namespace net {
21 class ReportSender; 21 class ReportSender;
22 class URLRequestContext; 22 class URLRequestContext;
23 } // namespace net 23 } // namespace net
24 24
25 enum class PermissionRequestGestureType;
raymes 2016/07/27 01:42:05 AFAIK if you pass an argument by value then you ca
stefanocs 2016/07/27 02:58:18 Done.
26
25 namespace safe_browsing { 27 namespace safe_browsing {
26 28
27 struct PermissionAndOrigin { 29 struct PermissionAndOrigin {
28 bool operator==(const PermissionAndOrigin& other) const; 30 bool operator==(const PermissionAndOrigin& other) const;
29 31
30 content::PermissionType permission; 32 content::PermissionType permission;
31 GURL origin; 33 GURL origin;
32 }; 34 };
33 35
34 struct PermissionAndOriginHash { 36 struct PermissionAndOriginHash {
35 std::size_t operator()( 37 std::size_t operator()(
36 const PermissionAndOrigin& permission_and_origin) const; 38 const PermissionAndOrigin& permission_and_origin) const;
37 }; 39 };
38 40
39 // Provides functionality for building and serializing reports about permissions 41 // Provides functionality for building and serializing reports about permissions
40 // to a report collection server. 42 // to a report collection server.
41 class PermissionReporter { 43 class PermissionReporter {
42 public: 44 public:
43 // Creates a permission reporter that will send permission reports to 45 // Creates a permission reporter that will send permission reports to
44 // the SafeBrowsing permission action server, using |request_context| as the 46 // the SafeBrowsing permission action server, using |request_context| as the
45 // context for the reports. 47 // context for the reports.
46 explicit PermissionReporter(net::URLRequestContext* request_context); 48 explicit PermissionReporter(net::URLRequestContext* request_context);
47 49
48 ~PermissionReporter(); 50 ~PermissionReporter();
49 51
50 // Sends a serialized permission report to the report collection server. 52 // Sends a serialized permission report to the report collection server.
51 // The permission report includes |origin| as the origin of 53 // The permission report includes |origin| as the origin of
52 // the site requesting permission, |permission| as the type of permission 54 // the site requesting permission, |permission| as the type of permission
53 // requested, |action| as the action taken, and |user_gesture| in the list of 55 // requested, |action| as the action taken, and |gesture_type| as to whether
54 // request triggers if the action occurred after a user gesture. The report 56 // the action occurred after a user gesture. The report will be serialized
55 // will be serialized using protobuf defined in 57 // using protobuf defined in
56 // //src/chrome/common/safe_browsing/permission_report.proto 58 // //src/chrome/common/safe_browsing/permission_report.proto
57 void SendReport(const GURL& origin, 59 void SendReport(const GURL& origin,
58 content::PermissionType permission, 60 content::PermissionType permission,
59 PermissionAction action, 61 PermissionAction action,
60 PermissionSourceUI source_ui, 62 PermissionSourceUI source_ui,
61 bool user_gesture); 63 PermissionRequestGestureType gesture_type);
62 64
63 private: 65 private:
64 friend class PermissionReporterTest; 66 friend class PermissionReporterTest;
65 67
66 // Used by tests. This constructor allows tests to have access to the 68 // Used by tests. This constructor allows tests to have access to the
67 // ReportSender and use a test Clock. 69 // ReportSender and use a test Clock.
68 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, 70 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender,
69 std::unique_ptr<base::Clock> clock); 71 std::unique_ptr<base::Clock> clock);
70 72
71 // Builds and serializes a permission report with |origin| as the origin of 73 // Builds and serializes a permission report with |origin| as the origin of
72 // the site requesting permission, |permission| as the type of permission 74 // the site requesting permission, |permission| as the type of permission
73 // requested, and |action| as the action taken. The serialized report is 75 // requested, and |action| as the action taken. The serialized report is
74 // written into |output|. Returns true if the serialization was successful and 76 // written into |output|. Returns true if the serialization was successful and
75 // false otherwise. 77 // false otherwise.
76 static bool BuildReport(const GURL& origin, 78 static bool BuildReport(const GURL& origin,
77 content::PermissionType permission, 79 content::PermissionType permission,
78 PermissionAction action, 80 PermissionAction action,
79 PermissionSourceUI source_ui, 81 PermissionSourceUI source_ui,
80 bool user_gesture, 82 PermissionRequestGestureType gesture_type,
81 std::string* output); 83 std::string* output);
82 84
83 // Returns false if the number of reports sent in the last one minute per 85 // Returns false if the number of reports sent in the last one minute per
84 // origin per permission is under a threshold, otherwise true. 86 // origin per permission is under a threshold, otherwise true.
85 bool IsReportThresholdExceeded(content::PermissionType permission, 87 bool IsReportThresholdExceeded(content::PermissionType permission,
86 const GURL& origin); 88 const GURL& origin);
87 89
88 std::unique_ptr<net::ReportSender> permission_report_sender_; 90 std::unique_ptr<net::ReportSender> permission_report_sender_;
89 91
90 // TODO(stefanocs): This might introduce a memory issue since older entries 92 // TODO(stefanocs): This might introduce a memory issue since older entries
91 // are not removed until a new report with the corresponding key is added. We 93 // are not removed until a new report with the corresponding key is added. We
92 // should address this issue if that becomes a problem in the future. 94 // should address this issue if that becomes a problem in the future.
93 std::unordered_map<PermissionAndOrigin, 95 std::unordered_map<PermissionAndOrigin,
94 std::queue<base::Time>, 96 std::queue<base::Time>,
95 PermissionAndOriginHash> 97 PermissionAndOriginHash>
96 report_logs_; 98 report_logs_;
97 99
98 std::unique_ptr<base::Clock> clock_; 100 std::unique_ptr<base::Clock> clock_;
99 101
100 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); 102 DISALLOW_COPY_AND_ASSIGN(PermissionReporter);
101 }; 103 };
102 104
103 } // namespace safe_browsing 105 } // namespace safe_browsing
104 106
105 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ 107 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698