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 #include "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
6 #include "chrome/browser/safe_browsing/permission_reporter.h" | 6 #include "chrome/browser/safe_browsing/permission_reporter.h" |
7 #include "chrome/common/safe_browsing/permission_report.pb.h" | 7 #include "chrome/common/safe_browsing/permission_report.pb.h" |
8 #include "components/variations/active_field_trials.h" | 8 #include "components/variations/active_field_trials.h" |
9 #include "content/public/browser/permission_type.h" | 9 #include "content/public/browser/permission_type.h" |
10 #include "net/url_request/report_sender.h" | 10 #include "net/url_request/report_sender.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 PermissionReporter::PermissionReporter( | 101 PermissionReporter::PermissionReporter( |
102 std::unique_ptr<net::ReportSender> report_sender) | 102 std::unique_ptr<net::ReportSender> report_sender) |
103 : permission_report_sender_(std::move(report_sender)) {} | 103 : permission_report_sender_(std::move(report_sender)) {} |
104 | 104 |
105 PermissionReporter::~PermissionReporter() {} | 105 PermissionReporter::~PermissionReporter() {} |
106 | 106 |
107 void PermissionReporter::SendReport(const GURL& origin, | 107 void PermissionReporter::SendReport(const GURL& origin, |
108 content::PermissionType permission, | 108 content::PermissionType permission, |
109 PermissionAction action, | 109 PermissionAction action, |
110 PermissionSourceUI source_ui) { | 110 PermissionSourceUI source_ui, |
| 111 bool user_gesture) { |
111 std::string serialized_report; | 112 std::string serialized_report; |
112 BuildReport(origin, permission, action, source_ui, &serialized_report); | 113 BuildReport(origin, permission, action, source_ui, user_gesture, |
| 114 &serialized_report); |
113 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | 115 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
114 serialized_report); | 116 serialized_report); |
115 } | 117 } |
116 | 118 |
117 // static | 119 // static |
118 bool PermissionReporter::BuildReport(const GURL& origin, | 120 bool PermissionReporter::BuildReport(const GURL& origin, |
119 PermissionType permission, | 121 PermissionType permission, |
120 PermissionAction action, | 122 PermissionAction action, |
121 PermissionSourceUI source_ui, | 123 PermissionSourceUI source_ui, |
| 124 bool user_gesture, |
122 std::string* output) { | 125 std::string* output) { |
123 PermissionReport report; | 126 PermissionReport report; |
124 report.set_origin(origin.spec()); | 127 report.set_origin(origin.spec()); |
125 report.set_permission(PermissionTypeForReport(permission)); | 128 report.set_permission(PermissionTypeForReport(permission)); |
126 report.set_action(PermissionActionForReport(action)); | 129 report.set_action(PermissionActionForReport(action)); |
127 report.set_source_ui(SourceUIForReport(source_ui)); | 130 report.set_source_ui(SourceUIForReport(source_ui)); |
| 131 if (user_gesture) |
| 132 report.add_request_trigger(PermissionReport::AFTER_GESTURE); |
128 | 133 |
129 // Collect platform data. | 134 // Collect platform data. |
130 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
131 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); | 136 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); |
132 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 137 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
133 defined(OS_LINUX) | 138 defined(OS_LINUX) |
134 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); | 139 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); |
135 #else | 140 #else |
136 #error Unsupported platform. | 141 #error Unsupported platform. |
137 #endif | 142 #endif |
138 | 143 |
139 // Collect field trial data. | 144 // Collect field trial data. |
140 std::vector<variations::ActiveGroupId> active_group_ids; | 145 std::vector<variations::ActiveGroupId> active_group_ids; |
141 variations::GetFieldTrialActiveGroupIds(&active_group_ids); | 146 variations::GetFieldTrialActiveGroupIds(&active_group_ids); |
142 for (auto active_group_id : active_group_ids) { | 147 for (auto active_group_id : active_group_ids) { |
143 PermissionReport::FieldTrial* field_trial = report.add_field_trials(); | 148 PermissionReport::FieldTrial* field_trial = report.add_field_trials(); |
144 field_trial->set_name_id(active_group_id.name); | 149 field_trial->set_name_id(active_group_id.name); |
145 field_trial->set_group_id(active_group_id.group); | 150 field_trial->set_group_id(active_group_id.group); |
146 } | 151 } |
147 return report.SerializeToString(output); | 152 return report.SerializeToString(output); |
148 } | 153 } |
149 | 154 |
150 } // namespace safe_browsing | 155 } // namespace safe_browsing |
OLD | NEW |