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

Side by Side Diff: chrome/browser/android/preferences/website_preference_bridge.cc

Issue 952463002: Add UMA to track permission changes from the content settings menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/preferences/website_preference_bridge.h" 5 #include "chrome/browser/android/preferences/website_preference_bridge.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/strings/string_util.h" 13 #include "base/metrics/histogram.h"
Ilya Sherman 2015/02/23 22:55:20 nit: Please include histogram_macros instead.
Miguel Garcia 2015/02/24 13:25:24 Done.
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
16 #include "chrome/browser/browsing_data/cookies_tree_model.h" 16 #include "chrome/browser/browsing_data/cookies_tree_model.h"
17 #include "chrome/browser/browsing_data/local_data_container.h" 17 #include "chrome/browser/browsing_data/local_data_container.h"
18 #include "chrome/browser/content_settings/cookie_settings.h" 18 #include "chrome/browser/content_settings/cookie_settings.h"
19 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 19 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "components/content_settings/core/browser/host_content_settings_map.h" 22 #include "components/content_settings/core/browser/host_content_settings_map.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
25 #include "jni/WebsitePreferenceBridge_jni.h" 25 #include "jni/WebsitePreferenceBridge_jni.h"
26 #include "storage/browser/quota/quota_client.h" 26 #include "storage/browser/quota/quota_client.h"
27 #include "storage/browser/quota/quota_manager.h" 27 #include "storage/browser/quota/quota_manager.h"
28 #include "url/url_constants.h" 28 #include "url/url_constants.h"
29 29
30 using base::android::ConvertJavaStringToUTF8; 30 using base::android::ConvertJavaStringToUTF8;
31 using base::android::ConvertUTF8ToJavaString; 31 using base::android::ConvertUTF8ToJavaString;
32 using base::android::JavaRef; 32 using base::android::JavaRef;
33 using base::android::ScopedJavaGlobalRef; 33 using base::android::ScopedJavaGlobalRef;
34 using base::android::ScopedJavaLocalRef; 34 using base::android::ScopedJavaLocalRef;
35 using content::BrowserThread; 35 using content::BrowserThread;
36 36
37 namespace {
38
39 static void LogPermissionChange(ContentSettingsType type,
Ilya Sherman 2015/02/23 22:55:20 nit: No need for "static" in an anonymous namespac
Miguel Garcia 2015/02/24 13:25:24 Done.
40 ContentSetting setting) {
41 ContentSettingsTypeHistogram histogram_value =
42 ContentSettingTypeToHistogramValue(type);
43 DCHECK_NE(histogram_value, CONTENT_SETTINGS_TYPE_HISTOGRAM_INVALID)
44 << "Invalid content setting type specified.";
Ilya Sherman 2015/02/23 22:55:20 nit: Please omit this string. It adds weight to t
Miguel Garcia 2015/02/24 13:25:24 Done.
45 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged",
46 histogram_value,
47 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
48
49 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
50 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Allowed",
51 histogram_value,
52 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
53 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
54 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Blocked",
55 histogram_value,
56 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
57 } else if (setting == ContentSetting::CONTENT_SETTING_DEFAULT) {
58 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Menu.PermissionChanged.Reset",
59 histogram_value,
60 CONTENT_SETTINGS_HISTOGRAM_NUM_TYPES);
61 } else {
62 NOTREACHED() << "Requested to log permission change " << type << " to "
63 << setting;
64 }
65 }
66 } // namespace
67
37 static HostContentSettingsMap* GetHostContentSettingsMap() { 68 static HostContentSettingsMap* GetHostContentSettingsMap() {
38 Profile* profile = ProfileManager::GetActiveUserProfile(); 69 Profile* profile = ProfileManager::GetActiveUserProfile();
39 return profile->GetHostContentSettingsMap(); 70 return profile->GetHostContentSettingsMap();
40 } 71 }
41 72
42 static void GetOrigins(JNIEnv* env, 73 static void GetOrigins(JNIEnv* env,
43 ContentSettingsType content_type, 74 ContentSettingsType content_type,
44 jobject list, 75 jobject list,
45 jboolean managedOnly) { 76 jboolean managedOnly) {
46 ContentSettingsForOneType all_settings; 77 ContentSettingsForOneType all_settings;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 case 2: setting = CONTENT_SETTING_BLOCK; break; 176 case 2: setting = CONTENT_SETTING_BLOCK; break;
146 default: 177 default:
147 NOTREACHED(); 178 NOTREACHED();
148 } 179 }
149 GetHostContentSettingsMap()->SetContentSetting( 180 GetHostContentSettingsMap()->SetContentSetting(
150 ContentSettingsPattern::FromURLNoWildcard(url), 181 ContentSettingsPattern::FromURLNoWildcard(url),
151 secondary_pattern, 182 secondary_pattern,
152 content_type, 183 content_type,
153 std::string(), 184 std::string(),
154 setting); 185 setting);
186 LogPermissionChange(content_type, setting);
155 } 187 }
156 188
157 static void GetGeolocationOrigins(JNIEnv* env, 189 static void GetGeolocationOrigins(JNIEnv* env,
158 jclass clazz, 190 jclass clazz,
159 jobject list, 191 jobject list,
160 jboolean managedOnly) { 192 jboolean managedOnly) {
161 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly); 193 GetOrigins(env, CONTENT_SETTINGS_TYPE_GEOLOCATION, list, managedOnly);
162 } 194 }
163 195
164 static jint GetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz, 196 static jint GetGeolocationSettingForOrigin(JNIEnv* env, jclass clazz,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ProfileManager::GetActiveUserProfile(), 254 ProfileManager::GetActiveUserProfile(),
223 GURL(ConvertJavaStringToUTF8(env, origin))); 255 GURL(ConvertJavaStringToUTF8(env, origin)));
224 } 256 }
225 257
226 static void SetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz, 258 static void SetPushNotificationSettingForOrigin(JNIEnv* env, jclass clazz,
227 jstring origin, jstring embedder, jint value) { 259 jstring origin, jstring embedder, jint value) {
228 // TODO(peter): Web Notification permission behaves differently from all other 260 // TODO(peter): Web Notification permission behaves differently from all other
229 // permission types. See https://crbug.com/416894. 261 // permission types. See https://crbug.com/416894.
230 Profile* profile = ProfileManager::GetActiveUserProfile(); 262 Profile* profile = ProfileManager::GetActiveUserProfile();
231 GURL url = GURL(ConvertJavaStringToUTF8(env, origin)); 263 GURL url = GURL(ConvertJavaStringToUTF8(env, origin));
232 264 ContentSetting setting = CONTENT_SETTING_DEFAULT;
233 switch (value) { 265 switch (value) {
234 case -1: 266 case -1:
235 DesktopNotificationProfileUtil::ClearSetting( 267 DesktopNotificationProfileUtil::ClearSetting(
236 profile, ContentSettingsPattern::FromURLNoWildcard(url)); 268 profile, ContentSettingsPattern::FromURLNoWildcard(url));
237 break; 269 break;
238 case 1: 270 case 1:
239 DesktopNotificationProfileUtil::GrantPermission(profile, url); 271 DesktopNotificationProfileUtil::GrantPermission(profile, url);
272 setting = CONTENT_SETTING_ALLOW;
240 break; 273 break;
241 case 2: 274 case 2:
242 DesktopNotificationProfileUtil::DenyPermission(profile, url); 275 DesktopNotificationProfileUtil::DenyPermission(profile, url);
276 setting = CONTENT_SETTING_BLOCK;
243 break; 277 break;
244 default: 278 default:
245 NOTREACHED(); 279 NOTREACHED();
246 } 280 }
281 LogPermissionChange(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
247 } 282 }
248 283
249 static void GetVoiceAndVideoCaptureOrigins(JNIEnv* env, 284 static void GetVoiceAndVideoCaptureOrigins(JNIEnv* env,
250 jclass clazz, 285 jclass clazz,
251 jobject list, 286 jobject list,
252 jboolean managedOnly) { 287 jboolean managedOnly) {
253 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly); 288 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, list, managedOnly);
254 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly); 289 GetOrigins(env, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, list, managedOnly);
255 } 290 }
256 291
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin, 350 return GetSettingForOrigin(env, CONTENT_SETTINGS_TYPE_COOKIES, origin,
316 embedder); 351 embedder);
317 } 352 }
318 353
319 static void SetCookieSettingForOrigin(JNIEnv* env, jclass clazz, 354 static void SetCookieSettingForOrigin(JNIEnv* env, jclass clazz,
320 jstring origin, jstring embedder, jint value) { 355 jstring origin, jstring embedder, jint value) {
321 GURL url(ConvertJavaStringToUTF8(env, origin)); 356 GURL url(ConvertJavaStringToUTF8(env, origin));
322 ContentSettingsPattern primary_pattern( 357 ContentSettingsPattern primary_pattern(
323 ContentSettingsPattern::FromURLNoWildcard(url)); 358 ContentSettingsPattern::FromURLNoWildcard(url));
324 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard()); 359 ContentSettingsPattern secondary_pattern(ContentSettingsPattern::Wildcard());
360 ContentSetting setting = CONTENT_SETTING_DEFAULT;
325 if (value == -1) { 361 if (value == -1) {
326 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern); 362 GetCookieSettings()->ResetCookieSetting(primary_pattern, secondary_pattern);
327 } else { 363 } else {
364 setting = value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
328 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern, 365 GetCookieSettings()->SetCookieSetting(primary_pattern, secondary_pattern,
329 value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); 366 value ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
Finnur 2015/02/23 14:47:19 nit: Probably more readable to use |setting| here.
Miguel Garcia 2015/02/24 13:25:24 Done.
330 } 367 }
368 LogPermissionChange(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
331 } 369 }
332 370
333 namespace { 371 namespace {
334 372
335 class SiteDataDeleteHelper : 373 class SiteDataDeleteHelper :
336 public base::RefCountedThreadSafe<SiteDataDeleteHelper>, 374 public base::RefCountedThreadSafe<SiteDataDeleteHelper>,
337 public CookiesTreeModel::Observer { 375 public CookiesTreeModel::Observer {
338 public: 376 public:
339 SiteDataDeleteHelper(Profile* profile, const GURL& domain) 377 SiteDataDeleteHelper(Profile* profile, const GURL& domain)
340 : profile_(profile), domain_(domain), ending_batch_processing_(false) { 378 : profile_(profile), domain_(domain), ending_batch_processing_(false) {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 684 GURL url(ConvertJavaStringToUTF8(env, jorigin));
647 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 685 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
648 new SiteDataDeleteHelper(profile, url)); 686 new SiteDataDeleteHelper(profile, url));
649 site_data_deleter->Run(); 687 site_data_deleter->Run();
650 } 688 }
651 689
652 // Register native methods 690 // Register native methods
653 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 691 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
654 return RegisterNativesImpl(env); 692 return RegisterNativesImpl(env);
655 } 693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698