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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 years, 10 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 #include "chrome/browser/safe_browsing/permission_reporter.h" 5 #include "chrome/browser/safe_browsing/permission_reporter.h"
6 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/time/default_clock.h" 11 #include "base/time/default_clock.h"
12 #include "chrome/browser/permissions/permission_request.h" 12 #include "chrome/browser/permissions/permission_request.h"
13 #include "chrome/common/safe_browsing/permission_report.pb.h" 13 #include "chrome/common/safe_browsing/permission_report.pb.h"
14 #include "components/variations/active_field_trials.h" 14 #include "components/variations/active_field_trials.h"
15 #include "content/public/browser/permission_type.h"
16 #include "net/url_request/report_sender.h" 15 #include "net/url_request/report_sender.h"
17 16
18 using content::PermissionType;
19
20 namespace safe_browsing { 17 namespace safe_browsing {
21 18
22 namespace { 19 namespace {
23 // URL to upload permission action reports. 20 // URL to upload permission action reports.
24 const char kPermissionActionReportingUploadUrl[] = 21 const char kPermissionActionReportingUploadUrl[] =
25 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" 22 "https://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
26 "chrome-permissions"; 23 "chrome-permissions";
27 24
28 const int kMaximumReportsPerOriginPerPermissionPerMinute = 5; 25 const int kMaximumReportsPerOriginPerPermissionPerMinute = 5;
29 26
30 PermissionReport::PermissionType PermissionTypeForReport( 27 PermissionReport::PermissionType PermissionTypeForReport(
31 PermissionType permission) { 28 ContentSettingsType permission) {
32 switch (permission) { 29 switch (permission) {
33 case PermissionType::MIDI_SYSEX: 30 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
34 return PermissionReport::MIDI_SYSEX; 31 return PermissionReport::MIDI_SYSEX;
35 case PermissionType::PUSH_MESSAGING: 32 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
36 return PermissionReport::PUSH_MESSAGING; 33 return PermissionReport::PUSH_MESSAGING;
37 case PermissionType::NOTIFICATIONS: 34 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
38 return PermissionReport::NOTIFICATIONS; 35 return PermissionReport::NOTIFICATIONS;
39 case PermissionType::GEOLOCATION: 36 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
40 return PermissionReport::GEOLOCATION; 37 return PermissionReport::GEOLOCATION;
41 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: 38 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
42 return PermissionReport::PROTECTED_MEDIA_IDENTIFIER; 39 return PermissionReport::PROTECTED_MEDIA_IDENTIFIER;
43 case PermissionType::MIDI: 40 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
44 return PermissionReport::MIDI;
45 case PermissionType::DURABLE_STORAGE:
46 return PermissionReport::DURABLE_STORAGE; 41 return PermissionReport::DURABLE_STORAGE;
47 case PermissionType::AUDIO_CAPTURE: 42 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
48 return PermissionReport::AUDIO_CAPTURE; 43 return PermissionReport::AUDIO_CAPTURE;
49 case PermissionType::VIDEO_CAPTURE: 44 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
50 return PermissionReport::VIDEO_CAPTURE; 45 return PermissionReport::VIDEO_CAPTURE;
51 case PermissionType::BACKGROUND_SYNC: 46 case CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC:
52 return PermissionReport::BACKGROUND_SYNC; 47 return PermissionReport::BACKGROUND_SYNC;
53 case PermissionType::FLASH: 48 case CONTENT_SETTINGS_TYPE_PLUGINS:
54 return PermissionReport::FLASH; 49 return PermissionReport::FLASH;
55 case PermissionType::NUM: 50 default:
56 break; 51 break;
57 } 52 }
58 53
59 NOTREACHED(); 54 NOTREACHED();
60 return PermissionReport::UNKNOWN_PERMISSION; 55 return PermissionReport::UNKNOWN_PERMISSION;
61 } 56 }
62 57
63 PermissionReport::Action PermissionActionForReport(PermissionAction action) { 58 PermissionReport::Action PermissionActionForReport(PermissionAction action) {
64 switch (action) { 59 switch (action) {
65 case GRANTED: 60 case GRANTED:
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 variations::GetFieldTrialActiveGroupIds(&active_group_ids); 199 variations::GetFieldTrialActiveGroupIds(&active_group_ids);
205 for (auto active_group_id : active_group_ids) { 200 for (auto active_group_id : active_group_ids) {
206 PermissionReport::FieldTrial* field_trial = report.add_field_trials(); 201 PermissionReport::FieldTrial* field_trial = report.add_field_trials();
207 field_trial->set_name_id(active_group_id.name); 202 field_trial->set_name_id(active_group_id.name);
208 field_trial->set_group_id(active_group_id.group); 203 field_trial->set_group_id(active_group_id.group);
209 } 204 }
210 return report.SerializeToString(output); 205 return report.SerializeToString(output);
211 } 206 }
212 207
213 bool PermissionReporter::IsReportThresholdExceeded( 208 bool PermissionReporter::IsReportThresholdExceeded(
214 content::PermissionType permission, 209 ContentSettingsType permission,
215 const GURL& origin) { 210 const GURL& origin) {
216 std::queue<base::Time>& log = report_logs_[{permission, origin}]; 211 std::queue<base::Time>& log = report_logs_[{permission, origin}];
217 base::Time current_time = clock_->Now(); 212 base::Time current_time = clock_->Now();
218 // Remove entries that are sent more than one minute ago. 213 // Remove entries that are sent more than one minute ago.
219 while (!log.empty() && 214 while (!log.empty() &&
220 current_time - log.front() > base::TimeDelta::FromMinutes(1)) { 215 current_time - log.front() > base::TimeDelta::FromMinutes(1)) {
221 log.pop(); 216 log.pop();
222 } 217 }
223 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { 218 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) {
224 log.push(current_time); 219 log.push(current_time);
225 return false; 220 return false;
226 } else { 221 } else {
227 return true; 222 return true;
228 } 223 }
229 } 224 }
230 225
231 } // namespace safe_browsing 226 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/permission_reporter.h ('k') | chrome/browser/safe_browsing/permission_reporter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698