Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 return false; | 287 return false; |
| 288 } | 288 } |
| 289 | 289 |
| 290 int PermissionDecisionAutoBlocker::RecordIgnore( | 290 int PermissionDecisionAutoBlocker::RecordIgnore( |
| 291 const GURL& url, | 291 const GURL& url, |
| 292 ContentSettingsType permission) { | 292 ContentSettingsType permission) { |
| 293 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, | 293 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, |
| 294 profile_); | 294 profile_); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void PermissionDecisionAutoBlocker::RemoveEmbargoByURL( | |
| 298 const GURL& url, | |
| 299 ContentSettingsType permission) { | |
| 300 if (!PermissionUtil::IsPermission(permission)) | |
| 301 return; | |
| 302 | |
| 303 HostContentSettingsMap* map = | |
| 304 HostContentSettingsMapFactory::GetForProfile(profile_); | |
| 305 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url); | |
| 306 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( | |
| 307 dict.get(), PermissionUtil::GetPermissionString(permission)); | |
| 308 // Deleting non-existent entries will return a false value. Since it should be | |
| 309 // impossible for a permission to have been embargoed for two different | |
| 310 // reasons at the same time, check that exactly one deletion was successful. | |
| 311 DCHECK(permission_dict->RemoveWithoutPathExpansion( | |
|
dominickn
2017/04/03 01:35:30
I think you need to do this outside a DCHECK, or e
Patti Lor
2017/04/05 08:34:27
Oh, you're totally right. Thanks Dom, fixed.
| |
| 312 kPermissionDismissalEmbargoKey, nullptr) != | |
| 313 permission_dict->RemoveWithoutPathExpansion( | |
| 314 kPermissionBlacklistEmbargoKey, nullptr)); | |
| 315 map->SetWebsiteSettingDefaultScope( | |
| 316 url, GURL(), CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA, | |
| 317 std::string(), std::move(dict)); | |
| 318 } | |
| 319 | |
| 297 void PermissionDecisionAutoBlocker::RemoveCountsByUrl( | 320 void PermissionDecisionAutoBlocker::RemoveCountsByUrl( |
| 298 base::Callback<bool(const GURL& url)> filter) { | 321 base::Callback<bool(const GURL& url)> filter) { |
| 299 HostContentSettingsMap* map = | 322 HostContentSettingsMap* map = |
| 300 HostContentSettingsMapFactory::GetForProfile(profile_); | 323 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 301 | 324 |
| 302 std::unique_ptr<ContentSettingsForOneType> settings( | 325 std::unique_ptr<ContentSettingsForOneType> settings( |
| 303 new ContentSettingsForOneType); | 326 new ContentSettingsForOneType); |
| 304 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA, | 327 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA, |
| 305 std::string(), settings.get()); | 328 std::string(), settings.get()); |
| 306 | 329 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 386 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 364 int timeout) { | 387 int timeout) { |
| 365 db_manager_ = db_manager; | 388 db_manager_ = db_manager; |
| 366 safe_browsing_timeout_ = timeout; | 389 safe_browsing_timeout_ = timeout; |
| 367 } | 390 } |
| 368 | 391 |
| 369 void PermissionDecisionAutoBlocker::SetClockForTesting( | 392 void PermissionDecisionAutoBlocker::SetClockForTesting( |
| 370 std::unique_ptr<base::Clock> clock) { | 393 std::unique_ptr<base::Clock> clock) { |
| 371 clock_ = std::move(clock); | 394 clock_ = std::move(clock); |
| 372 } | 395 } |
| OLD | NEW |