| OLD | NEW |
| 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 "components/content_settings/core/browser/content_settings_pref.h" | 5 #include "components/content_settings/core/browser/content_settings_pref.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 namespace content_settings { | 69 namespace content_settings { |
| 70 | 70 |
| 71 ContentSettingsPref::ContentSettingsPref( | 71 ContentSettingsPref::ContentSettingsPref( |
| 72 ContentSettingsType content_type, | 72 ContentSettingsType content_type, |
| 73 PrefService* prefs, | 73 PrefService* prefs, |
| 74 PrefChangeRegistrar* registrar, | 74 PrefChangeRegistrar* registrar, |
| 75 const std::string& pref_name, | 75 const std::string& pref_name, |
| 76 bool incognito, | 76 bool incognito, |
| 77 bool store_last_modified, | |
| 78 NotifyObserversCallback notify_callback) | 77 NotifyObserversCallback notify_callback) |
| 79 : content_type_(content_type), | 78 : content_type_(content_type), |
| 80 prefs_(prefs), | 79 prefs_(prefs), |
| 81 registrar_(registrar), | 80 registrar_(registrar), |
| 82 pref_name_(pref_name), | 81 pref_name_(pref_name), |
| 83 is_incognito_(incognito), | 82 is_incognito_(incognito), |
| 84 store_last_modified_(store_last_modified), | |
| 85 updating_preferences_(false), | 83 updating_preferences_(false), |
| 86 notify_callback_(notify_callback) { | 84 notify_callback_(notify_callback) { |
| 87 DCHECK(prefs_); | 85 DCHECK(prefs_); |
| 88 | 86 |
| 89 ReadContentSettingsFromPref(); | 87 ReadContentSettingsFromPref(); |
| 90 | 88 |
| 91 registrar_->Add( | 89 registrar_->Add( |
| 92 pref_name_, | 90 pref_name_, |
| 93 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this))); | 91 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this))); |
| 94 } | 92 } |
| 95 | 93 |
| 96 ContentSettingsPref::~ContentSettingsPref() { | 94 ContentSettingsPref::~ContentSettingsPref() { |
| 97 } | 95 } |
| 98 | 96 |
| 99 std::unique_ptr<RuleIterator> ContentSettingsPref::GetRuleIterator( | 97 std::unique_ptr<RuleIterator> ContentSettingsPref::GetRuleIterator( |
| 100 const ResourceIdentifier& resource_identifier, | 98 const ResourceIdentifier& resource_identifier, |
| 101 bool incognito) const { | 99 bool incognito) const { |
| 102 if (incognito) | 100 if (incognito) |
| 103 return incognito_value_map_.GetRuleIterator(content_type_, | 101 return incognito_value_map_.GetRuleIterator(content_type_, |
| 104 resource_identifier, | 102 resource_identifier, |
| 105 &lock_); | 103 &lock_); |
| 106 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_); | 104 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_); |
| 107 } | 105 } |
| 108 | 106 |
| 109 bool ContentSettingsPref::SetWebsiteSetting( | 107 bool ContentSettingsPref::SetWebsiteSetting( |
| 110 const ContentSettingsPattern& primary_pattern, | 108 const ContentSettingsPattern& primary_pattern, |
| 111 const ContentSettingsPattern& secondary_pattern, | 109 const ContentSettingsPattern& secondary_pattern, |
| 112 const ResourceIdentifier& resource_identifier, | 110 const ResourceIdentifier& resource_identifier, |
| 111 base::Time modified_time, |
| 113 base::Value* in_value) { | 112 base::Value* in_value) { |
| 114 DCHECK(!in_value || IsValueAllowedForType(in_value, content_type_)); | 113 DCHECK(!in_value || IsValueAllowedForType(in_value, content_type_)); |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
| 116 DCHECK(prefs_); | 115 DCHECK(prefs_); |
| 117 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() || | 116 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() || |
| 118 secondary_pattern != ContentSettingsPattern::Wildcard() || | 117 secondary_pattern != ContentSettingsPattern::Wildcard() || |
| 119 !resource_identifier.empty()); | 118 !resource_identifier.empty()); |
| 120 | 119 |
| 121 // At this point take the ownership of the |in_value|. | 120 // At this point take the ownership of the |in_value|. |
| 122 std::unique_ptr<base::Value> value(in_value); | 121 std::unique_ptr<base::Value> value(in_value); |
| 123 | 122 |
| 124 // Update in memory value map. | 123 // Update in memory value map. |
| 125 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 124 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 126 if (!is_incognito_) | 125 if (!is_incognito_) |
| 127 map_to_modify = &value_map_; | 126 map_to_modify = &value_map_; |
| 128 | 127 |
| 129 base::Time modified_time = | |
| 130 store_last_modified_ ? base::Time::Now() : base::Time(); | |
| 131 | |
| 132 { | 128 { |
| 133 base::AutoLock auto_lock(lock_); | 129 base::AutoLock auto_lock(lock_); |
| 134 if (value.get()) { | 130 if (value.get()) { |
| 135 map_to_modify->SetValue(primary_pattern, secondary_pattern, content_type_, | 131 map_to_modify->SetValue(primary_pattern, secondary_pattern, content_type_, |
| 136 resource_identifier, modified_time, | 132 resource_identifier, modified_time, |
| 137 value->DeepCopy()); | 133 value->DeepCopy()); |
| 138 } else { | 134 } else { |
| 139 map_to_modify->DeleteValue( | 135 map_to_modify->DeleteValue( |
| 140 primary_pattern, | 136 primary_pattern, |
| 141 secondary_pattern, | 137 secondary_pattern, |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 480 |
| 485 void ContentSettingsPref::AssertLockNotHeld() const { | 481 void ContentSettingsPref::AssertLockNotHeld() const { |
| 486 #if !defined(NDEBUG) | 482 #if !defined(NDEBUG) |
| 487 // |Lock::Acquire()| will assert if the lock is held by this thread. | 483 // |Lock::Acquire()| will assert if the lock is held by this thread. |
| 488 lock_.Acquire(); | 484 lock_.Acquire(); |
| 489 lock_.Release(); | 485 lock_.Release(); |
| 490 #endif | 486 #endif |
| 491 } | 487 } |
| 492 | 488 |
| 493 } // namespace content_settings | 489 } // namespace content_settings |
| OLD | NEW |