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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/ping_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/permissions/permission_uma_util.cc
diff --git a/chrome/browser/permissions/permission_uma_util.cc b/chrome/browser/permissions/permission_uma_util.cc
index efbdf5f04b6c65ff92efbb88a5fa6d95f2c44fb1..42b1b65947007374dce806fa44944983b8708f60 100644
--- a/chrome/browser/permissions/permission_uma_util.cc
+++ b/chrome/browser/permissions/permission_uma_util.cc
@@ -6,13 +6,23 @@
#include <utility>
+#include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/permissions/permission_util.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/safe_browsing/permission_reporter.h"
+#include "chrome/browser/safe_browsing/ping_manager.h"
+#include "chrome/browser/safe_browsing/safe_browsing_service.h"
+#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/website_settings/permission_bubble_request.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "components/browser_sync/browser/profile_sync_service.h"
+#include "components/prefs/pref_service.h"
#include "components/rappor/rappor_service.h"
#include "components/rappor/rappor_utils.h"
#include "content/public/browser/permission_type.h"
@@ -74,9 +84,57 @@ const std::string GetRapporMetric(PermissionType permission,
permission_str.c_str(), action_str.c_str());
}
+void ReportPermissionAction(const GURL& origin,
+ PermissionType permission,
+ PermissionAction action) {
+ // Do not report permission action when the permission action reporting
+ // flag is not enabled.
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnablePermissionActionReporting)) {
+ return;
+ }
+
+ Profile* profile = ProfileManager::GetLastUsedProfile();
stefanocs 2016/06/15 05:31:15 Is this the right way to get the profile? Or shoul
+
+ // Do not report when SafeBrowsing is not enabled.
+ if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) {
+ return;
+ }
+ // Do not report if profile doesn't have profile sync service.
+ if (!ProfileSyncServiceFactory::HasProfileSyncService(profile)) {
+ return;
+ }
+
+ ProfileSyncService* profile_sync_service =
+ ProfileSyncServiceFactory::GetForProfile(profile);
+ syncer::ModelTypeSet preferred_data_types =
+ profile_sync_service->GetPreferredDataTypes();
+
+ // Do not report if profile can't start sync immediately.
+ if (!profile_sync_service->CanSyncStart()) {
+ return;
+ }
+ // Do not report if Chrome Tab Sync is not enabled.
+ if (!preferred_data_types.Has(syncer::PROXY_TABS)) {
+ return;
+ }
+ // Do not report if Chrome Pref Sync is not enabled.
+ if (!preferred_data_types.Has(syncer::PREFERENCES)) {
+ return;
+ }
+
+ safe_browsing::PermissionReporter* permission_reporter =
+ g_browser_process->safe_browsing_service()
+ ->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.
+ ->permission_reporter();
+ permission_reporter->SendReport(origin, permission, action);
+}
+
void RecordPermissionAction(PermissionType permission,
PermissionAction action,
const GURL& requesting_origin) {
+ ReportPermissionAction(requesting_origin, permission, action);
+
bool secure_origin = content::IsOriginSecure(requesting_origin);
switch (permission) {
« 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