| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/permissions/permission_uma_util.h" | 10 #include "chrome/browser/permissions/permission_uma_util.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 class ReportSender; |
| 14 class URLRequestContext; | 15 class URLRequestContext; |
| 15 } // namespace net | 16 } // namespace net |
| 16 | 17 |
| 17 namespace safe_browsing { | 18 namespace safe_browsing { |
| 18 | 19 |
| 19 // Provides functionality for building and serializing reports about permissions | 20 // Provides functionality for building and serializing reports about permissions |
| 20 // to a report collection server. | 21 // to a report collection server. |
| 21 class PermissionReporter { | 22 class PermissionReporter { |
| 22 public: | 23 public: |
| 23 // Creates a permission reporter that will send permission reports to | 24 // Creates a permission reporter that will send permission reports to |
| 24 // the SafeBrowsing permission action server, using |request_context| as the | 25 // the SafeBrowsing permission action server, using |request_context| as the |
| 25 // context for the reports. | 26 // context for the reports. |
| 26 explicit PermissionReporter(net::URLRequestContext* request_context); | 27 explicit PermissionReporter(net::URLRequestContext* request_context); |
| 27 | 28 |
| 28 ~PermissionReporter(); | 29 ~PermissionReporter(); |
| 29 | 30 |
| 30 // Sends a serialized permission report to the report collection server. | 31 // Sends a serialized permission report to the report collection server. |
| 31 // The permission report includes |origin| as the origin of | 32 // The permission report includes |origin| as the origin of |
| 32 // the site requesting permission, |permission| as the type of permission | 33 // the site requesting permission, |permission| as the type of permission |
| 33 // requested, and |action| as the action taken. The report will be serialized | 34 // requested, and |action| as the action taken. The report will be serialized |
| 34 // using protobuf defined in | 35 // using protobuf defined in |
| 35 // //src/chrome/common/safe_browsing/permission_report.proto | 36 // //src/chrome/common/safe_browsing/permission_report.proto |
| 36 void SendReport(const GURL& origin, | 37 void SendReport(const GURL& origin, |
| 37 content::PermissionType permission, | 38 content::PermissionType permission, |
| 38 PermissionAction action); | 39 PermissionAction action); |
| 39 | 40 |
| 41 private: |
| 42 friend class PermissionReporterTest; |
| 43 |
| 44 // Used by tests. This constructor allows tests to have access to the |
| 45 // ReportSender. |
| 46 explicit PermissionReporter(std::unique_ptr<net::ReportSender> report_sender); |
| 47 |
| 40 // Builds and serializes a permission report with |origin| as the origin of | 48 // Builds and serializes a permission report with |origin| as the origin of |
| 41 // the site requesting permission, |permission| as the type of permission | 49 // the site requesting permission, |permission| as the type of permission |
| 42 // requested, and |action| as the action taken. The serialized report is | 50 // requested, and |action| as the action taken. The serialized report is |
| 43 // written into |output|. Returns true if the serialization was successful and | 51 // written into |output|. Returns true if the serialization was successful and |
| 44 // false otherwise. | 52 // false otherwise. |
| 45 static bool BuildReport(const GURL& origin, | 53 static bool BuildReport(const GURL& origin, |
| 46 content::PermissionType permission, | 54 content::PermissionType permission, |
| 47 PermissionAction action, | 55 PermissionAction action, |
| 48 std::string* output); | 56 std::string* output); |
| 49 | 57 |
| 50 private: | 58 std::unique_ptr<net::ReportSender> permission_report_sender_; |
| 59 |
| 51 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); | 60 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 } // namespace safe_browsing | 63 } // namespace safe_browsing |
| 55 | 64 |
| 56 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 65 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
| OLD | NEW |