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

Side by Side Diff: chrome/browser/permissions/permission_uma_util.cc

Issue 2047253002: Add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-reporter-implementation
Patch Set: Send report to opted-in users only Created 4 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/ping_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/permissions/permission_uma_util.h" 5 #include "chrome/browser/permissions/permission_uma_util.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h"
9 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/permissions/permission_manager.h" 13 #include "chrome/browser/permissions/permission_manager.h"
13 #include "chrome/browser/permissions/permission_util.h" 14 #include "chrome/browser/permissions/permission_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/safe_browsing/permission_reporter.h"
18 #include "chrome/browser/safe_browsing/ping_manager.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 21 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h"
24 #include "components/browser_sync/browser/profile_sync_service.h"
25 #include "components/prefs/pref_service.h"
16 #include "components/rappor/rappor_service.h" 26 #include "components/rappor/rappor_service.h"
17 #include "components/rappor/rappor_utils.h" 27 #include "components/rappor/rappor_utils.h"
18 #include "content/public/browser/permission_type.h" 28 #include "content/public/browser/permission_type.h"
19 #include "content/public/common/origin_util.h" 29 #include "content/public/common/origin_util.h"
20 #include "url/gurl.h" 30 #include "url/gurl.h"
21 31
22 // UMA keys need to be statically initialized so plain function would not 32 // UMA keys need to be statically initialized so plain function would not
23 // work. Use macros instead. 33 // work. Use macros instead.
24 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ 34 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \
25 permission_insecure, action) \ 35 permission_insecure, action) \
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 77 }
68 78
69 std::string permission_str = 79 std::string permission_str =
70 PermissionUtil::GetPermissionString(permission); 80 PermissionUtil::GetPermissionString(permission);
71 if (permission_str.empty()) 81 if (permission_str.empty())
72 return ""; 82 return "";
73 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", 83 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url",
74 permission_str.c_str(), action_str.c_str()); 84 permission_str.c_str(), action_str.c_str());
75 } 85 }
76 86
87 void ReportPermissionAction(const GURL& origin,
88 PermissionType permission,
89 PermissionAction action) {
90 // Do not report permission action when the permission action reporting
91 // flag is not enabled.
92 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
93 switches::kEnablePermissionActionReporting)) {
94 return;
95 }
96
97 Profile* profile = ProfileManager::GetLastUsedProfile();
stefanocs 2016/06/15 05:31:15 Is this the right way to get the profile? Or shoul
98
99 // Do not report when SafeBrowsing is not enabled.
100 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) {
101 return;
102 }
103 // Do not report if profile doesn't have profile sync service.
104 if (!ProfileSyncServiceFactory::HasProfileSyncService(profile)) {
105 return;
106 }
107
108 ProfileSyncService* profile_sync_service =
109 ProfileSyncServiceFactory::GetForProfile(profile);
110 syncer::ModelTypeSet preferred_data_types =
111 profile_sync_service->GetPreferredDataTypes();
112
113 // Do not report if profile can't start sync immediately.
114 if (!profile_sync_service->CanSyncStart()) {
115 return;
116 }
117 // Do not report if Chrome Tab Sync is not enabled.
118 if (!preferred_data_types.Has(syncer::PROXY_TABS)) {
119 return;
120 }
121 // Do not report if Chrome Pref Sync is not enabled.
122 if (!preferred_data_types.Has(syncer::PREFERENCES)) {
123 return;
124 }
125
126 safe_browsing::PermissionReporter* permission_reporter =
127 g_browser_process->safe_browsing_service()
128 ->ping_manager()
stefanocs 2016/06/15 05:31:15 Chrome crashes when ping_manager() is called due t
stefanocs 2016/06/15 07:58:37 Done.
129 ->permission_reporter();
130 permission_reporter->SendReport(origin, permission, action);
131 }
132
77 void RecordPermissionAction(PermissionType permission, 133 void RecordPermissionAction(PermissionType permission,
78 PermissionAction action, 134 PermissionAction action,
79 const GURL& requesting_origin) { 135 const GURL& requesting_origin) {
136 ReportPermissionAction(requesting_origin, permission, action);
137
80 bool secure_origin = content::IsOriginSecure(requesting_origin); 138 bool secure_origin = content::IsOriginSecure(requesting_origin);
81 139
82 switch (permission) { 140 switch (permission) {
83 case PermissionType::GEOLOCATION: 141 case PermissionType::GEOLOCATION:
84 PERMISSION_ACTION_UMA( 142 PERMISSION_ACTION_UMA(
85 secure_origin, 143 secure_origin,
86 "Permissions.Action.Geolocation", 144 "Permissions.Action.Geolocation",
87 "Permissions.Action.SecureOrigin.Geolocation", 145 "Permissions.Action.SecureOrigin.Geolocation",
88 "Permissions.Action.InsecureOrigin.Geolocation", 146 "Permissions.Action.InsecureOrigin.Geolocation",
89 action); 147 action);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 425 }
368 426
369 void PermissionUmaUtil::PermissionPromptDenied( 427 void PermissionUmaUtil::PermissionPromptDenied(
370 const std::vector<PermissionBubbleRequest*>& requests) { 428 const std::vector<PermissionBubbleRequest*>& requests) {
371 DCHECK(!requests.empty()); 429 DCHECK(!requests.empty());
372 DCHECK(requests.size() == 1); 430 DCHECK(requests.size() == 1);
373 431
374 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied, 432 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied,
375 requests[0]->GetPermissionBubbleType()); 433 requests[0]->GetPermissionBubbleType());
376 } 434 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/ping_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698