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

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

Issue 2651163002: Add UMA for autoblocking and embargoing. (Closed)
Patch Set: Review 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/permissions/permission_decision_auto_blocker.h" 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/permissions/permission_blacklist_client.h" 16 #include "chrome/browser/permissions/permission_blacklist_client.h"
17 #include "chrome/browser/permissions/permission_uma_util.h"
17 #include "chrome/browser/permissions/permission_util.h" 18 #include "chrome/browser/permissions/permission_util.h"
18 #include "chrome/browser/profiles/incognito_helpers.h" 19 #include "chrome/browser/profiles/incognito_helpers.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "chrome/common/chrome_features.h" 22 #include "chrome/common/chrome_features.h"
22 #include "components/content_settings/core/browser/host_content_settings_map.h" 23 #include "components/content_settings/core/browser/host_content_settings_map.h"
23 #include "components/keyed_service/content/browser_context_dependency_manager.h" 24 #include "components/keyed_service/content/browser_context_dependency_manager.h"
24 #include "components/safe_browsing_db/database_manager.h" 25 #include "components/safe_browsing_db/database_manager.h"
25 #include "components/variations/variations_associated_data.h" 26 #include "components/variations/variations_associated_data.h"
26 #include "content/public/browser/permission_type.h" 27 #include "content/public/browser/permission_type.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 HostContentSettingsMapFactory::GetForProfile(profile); 107 HostContentSettingsMapFactory::GetForProfile(profile);
107 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url); 108 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url);
108 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( 109 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict(
109 dict.get(), PermissionUtil::GetPermissionString(permission)); 110 dict.get(), PermissionUtil::GetPermissionString(permission));
110 111
111 int current_count = 0; 112 int current_count = 0;
112 permission_dict->GetInteger(key, &current_count); 113 permission_dict->GetInteger(key, &current_count);
113 return current_count; 114 return current_count;
114 } 115 }
115 116
117 // Returns true if |url| has been embargoed from requesting |permission| for the
118 // reason corresponding to |key|.
119 bool WasPreviouslyEmbargoed(Profile* profile,
120 const GURL& url,
121 content::PermissionType permission,
122 const char* key) {
123 HostContentSettingsMap* map =
124 HostContentSettingsMapFactory::GetForProfile(profile);
125 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url);
126 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict(
127 dict.get(), PermissionUtil::GetPermissionString(permission));
128 return permission_dict->HasKey(key);
129 }
130
116 } // namespace 131 } // namespace
117 132
118 // PermissionDecisionAutoBlocker::Factory -------------------------------------- 133 // PermissionDecisionAutoBlocker::Factory --------------------------------------
119 134
120 // static 135 // static
121 PermissionDecisionAutoBlocker* 136 PermissionDecisionAutoBlocker*
122 PermissionDecisionAutoBlocker::Factory::GetForProfile(Profile* profile) { 137 PermissionDecisionAutoBlocker::Factory::GetForProfile(Profile* profile) {
123 return static_cast<PermissionDecisionAutoBlocker*>( 138 return static_cast<PermissionDecisionAutoBlocker*>(
124 GetInstance()->GetServiceForBrowserContext(profile, true)); 139 GetInstance()->GetServiceForBrowserContext(profile, true));
125 } 140 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 235 }
221 236
222 bool PermissionDecisionAutoBlocker::RecordDismissAndEmbargo( 237 bool PermissionDecisionAutoBlocker::RecordDismissAndEmbargo(
223 const GURL& url, 238 const GURL& url,
224 content::PermissionType permission) { 239 content::PermissionType permission) {
225 int current_dismissal_count = RecordActionInWebsiteSettings( 240 int current_dismissal_count = RecordActionInWebsiteSettings(
226 url, permission, kPromptDismissCountKey, profile_); 241 url, permission, kPromptDismissCountKey, profile_);
227 242
228 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && 243 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) &&
229 current_dismissal_count >= g_prompt_dismissals_before_block) { 244 current_dismissal_count >= g_prompt_dismissals_before_block) {
245 if (WasPreviouslyEmbargoed(profile_, url, permission,
246 kPermissionDismissalEmbargoKey)) {
247 PermissionUmaUtil::RecordRepeatedEmbargo(
248 PermissionEmbargoReason::REPEATED_DISMISSALS);
249 }
250
230 PlaceUnderEmbargo(permission, url, kPermissionDismissalEmbargoKey); 251 PlaceUnderEmbargo(permission, url, kPermissionDismissalEmbargoKey);
252 PermissionUmaUtil::RecordPermissionEmbargoReason(
253 PermissionEmbargoReason::REPEATED_DISMISSALS);
raymes 2017/02/01 19:15:44 Can these added lines be moved into PlaceUnderEmba
meredithl 2017/02/01 22:52:37 Done. I used strcmp, is that allowable?
231 return true; 254 return true;
232 } 255 }
233 return false; 256 return false;
234 } 257 }
235 258
236 int PermissionDecisionAutoBlocker::RecordIgnore( 259 int PermissionDecisionAutoBlocker::RecordIgnore(
237 const GURL& url, 260 const GURL& url,
238 content::PermissionType permission) { 261 content::PermissionType permission) {
239 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, 262 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey,
240 profile_); 263 profile_);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return is_under_dismiss_embargo || is_under_blacklist_embargo; 357 return is_under_dismiss_embargo || is_under_blacklist_embargo;
335 } 358 }
336 359
337 // static 360 // static
338 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( 361 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult(
339 content::PermissionType permission, 362 content::PermissionType permission,
340 const GURL& request_origin, 363 const GURL& request_origin,
341 base::Callback<void(bool)> callback, 364 base::Callback<void(bool)> callback,
342 bool should_be_embargoed) { 365 bool should_be_embargoed) {
343 if (should_be_embargoed) { 366 if (should_be_embargoed) {
344 // Requesting site is blacklisted for this permission, update the content 367 if (WasPreviouslyEmbargoed(profile_, request_origin, permission,
345 // setting to place it under embargo. 368 kPermissionBlacklistEmbargoKey)) {
369 PermissionUmaUtil::RecordRepeatedEmbargo(
370 PermissionEmbargoReason::PERMISSIONS_BLACKLISTING);
371 }
372
346 PlaceUnderEmbargo(permission, request_origin, 373 PlaceUnderEmbargo(permission, request_origin,
347 kPermissionBlacklistEmbargoKey); 374 kPermissionBlacklistEmbargoKey);
375 PermissionUmaUtil::RecordPermissionEmbargoReason(
376 PermissionEmbargoReason::PERMISSIONS_BLACKLISTING);
348 } 377 }
349 callback.Run(should_be_embargoed /* permission blocked */); 378
379 callback.Run(should_be_embargoed);
350 } 380 }
351 381
352 // static 382 // static
353 void PermissionDecisionAutoBlocker::PlaceUnderEmbargo( 383 void PermissionDecisionAutoBlocker::PlaceUnderEmbargo(
354 content::PermissionType permission, 384 content::PermissionType permission,
355 const GURL& request_origin, 385 const GURL& request_origin,
356 const char* key) { 386 const char* key) {
357 HostContentSettingsMap* map = 387 HostContentSettingsMap* map =
358 HostContentSettingsMapFactory::GetForProfile(profile_); 388 HostContentSettingsMapFactory::GetForProfile(profile_);
359 std::unique_ptr<base::DictionaryValue> dict = 389 std::unique_ptr<base::DictionaryValue> dict =
(...skipping 11 matching lines...) Expand all
371 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, 401 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
372 int timeout) { 402 int timeout) {
373 db_manager_ = db_manager; 403 db_manager_ = db_manager;
374 safe_browsing_timeout_ = timeout; 404 safe_browsing_timeout_ = timeout;
375 } 405 }
376 406
377 void PermissionDecisionAutoBlocker::SetClockForTesting( 407 void PermissionDecisionAutoBlocker::SetClockForTesting(
378 std::unique_ptr<base::Clock> clock) { 408 std::unique_ptr<base::Clock> clock) {
379 clock_ = std::move(clock); 409 clock_ = std::move(clock);
380 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698