OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/content_settings/content_settings_store. h" | 5 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 base::STLDeleteValues(&entries_); | 55 base::STLDeleteValues(&entries_); |
56 } | 56 } |
57 | 57 |
58 std::unique_ptr<RuleIterator> ContentSettingsStore::GetRuleIterator( | 58 std::unique_ptr<RuleIterator> ContentSettingsStore::GetRuleIterator( |
59 ContentSettingsType type, | 59 ContentSettingsType type, |
60 const content_settings::ResourceIdentifier& identifier, | 60 const content_settings::ResourceIdentifier& identifier, |
61 bool incognito) const { | 61 bool incognito) const { |
62 std::vector<std::unique_ptr<RuleIterator>> iterators; | 62 std::vector<std::unique_ptr<RuleIterator>> iterators; |
63 // Iterate the extensions based on install time (last installed extensions | 63 // Iterate the extensions based on install time (last installed extensions |
64 // first). | 64 // first). |
65 ExtensionEntryMap::const_reverse_iterator entry; | 65 ExtensionEntryMap::const_reverse_iterator entry_it; |
66 | 66 |
67 // The individual |RuleIterators| shouldn't lock; pass |lock_| to the | 67 // The individual |RuleIterators| shouldn't lock; pass |lock_| to the |
68 // |ConcatenationIterator| in a locked state. | 68 // |ConcatenationIterator| in a locked state. |
69 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); | 69 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); |
70 | 70 |
71 for (entry = entries_.rbegin(); entry != entries_.rend(); ++entry) { | 71 for (entry_it = entries_.rbegin(); entry_it != entries_.rend(); ++entry_it) { |
72 if (!entry->second->enabled) | 72 auto* entry = entry_it->second; |
73 if (!entry->enabled) | |
73 continue; | 74 continue; |
74 | 75 |
76 std::unique_ptr<RuleIterator> rule_it; | |
75 if (incognito) { | 77 if (incognito) { |
76 iterators.push_back( | 78 rule_it = entry->incognito_session_only_settings.GetRuleIterator( |
77 entry->second->incognito_session_only_settings.GetRuleIterator( | 79 type, identifier, nullptr); |
78 type, | 80 if (rule_it) |
79 identifier, | 81 iterators.push_back(std::move(rule_it)); |
80 NULL)); | 82 rule_it = entry->incognito_persistent_settings.GetRuleIterator( |
81 iterators.push_back( | 83 type, identifier, nullptr); |
82 entry->second->incognito_persistent_settings.GetRuleIterator( | 84 if (rule_it) |
83 type, | 85 iterators.push_back(std::move(rule_it)); |
84 identifier, | |
85 NULL)); | |
86 } else { | 86 } else { |
87 iterators.push_back( | 87 rule_it = entry->settings.GetRuleIterator(type, identifier, nullptr); |
88 entry->second->settings.GetRuleIterator(type, identifier, NULL)); | 88 if (rule_it) |
89 iterators.push_back(std::move(rule_it)); | |
89 } | 90 } |
90 } | 91 } |
91 return std::unique_ptr<RuleIterator>( | 92 return std::unique_ptr<RuleIterator>( |
92 new ConcatenationIterator(std::move(iterators), auto_lock.release())); | 93 new ConcatenationIterator(std::move(iterators), auto_lock.release())); |
Bernhard Bauer
2016/09/08 09:30:31
You could shortcut here as well and just return nu
Lei Zhang
2016/09/08 21:04:29
Done.
| |
93 } | 94 } |
94 | 95 |
95 void ContentSettingsStore::SetExtensionContentSetting( | 96 void ContentSettingsStore::SetExtensionContentSetting( |
96 const std::string& ext_id, | 97 const std::string& ext_id, |
97 const ContentSettingsPattern& primary_pattern, | 98 const ContentSettingsPattern& primary_pattern, |
98 const ContentSettingsPattern& secondary_pattern, | 99 const ContentSettingsPattern& secondary_pattern, |
99 ContentSettingsType type, | 100 ContentSettingsType type, |
100 const content_settings::ResourceIdentifier& identifier, | 101 const content_settings::ResourceIdentifier& identifier, |
101 ContentSetting setting, | 102 ContentSetting setting, |
102 ExtensionPrefsScope scope) { | 103 ExtensionPrefsScope scope) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); | 245 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); |
245 } | 246 } |
246 } | 247 } |
247 | 248 |
248 base::ListValue* ContentSettingsStore::GetSettingsForExtension( | 249 base::ListValue* ContentSettingsStore::GetSettingsForExtension( |
249 const std::string& extension_id, | 250 const std::string& extension_id, |
250 ExtensionPrefsScope scope) const { | 251 ExtensionPrefsScope scope) const { |
251 base::AutoLock lock(lock_); | 252 base::AutoLock lock(lock_); |
252 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); | 253 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); |
253 if (!map) | 254 if (!map) |
254 return NULL; | 255 return nullptr; |
256 | |
255 base::ListValue* settings = new base::ListValue(); | 257 base::ListValue* settings = new base::ListValue(); |
256 OriginIdentifierValueMap::EntryMap::const_iterator it; | 258 for (const auto& it : *map) { |
257 for (it = map->begin(); it != map->end(); ++it) { | 259 const auto& key = it.first; |
258 std::unique_ptr<RuleIterator> rule_iterator(map->GetRuleIterator( | 260 std::unique_ptr<RuleIterator> rule_iterator( |
259 it->first.content_type, it->first.resource_identifier, | 261 map->GetRuleIterator(key.content_type, key.resource_identifier, |
260 NULL)); // We already hold the lock. | 262 nullptr)); // We already hold the lock. |
263 if (!rule_iterator) | |
264 continue; | |
265 | |
261 while (rule_iterator->HasNext()) { | 266 while (rule_iterator->HasNext()) { |
262 const Rule& rule = rule_iterator->Next(); | 267 const Rule& rule = rule_iterator->Next(); |
263 std::unique_ptr<base::DictionaryValue> setting_dict( | 268 std::unique_ptr<base::DictionaryValue> setting_dict( |
264 new base::DictionaryValue()); | 269 new base::DictionaryValue()); |
265 setting_dict->SetString(keys::kPrimaryPatternKey, | 270 setting_dict->SetString(keys::kPrimaryPatternKey, |
266 rule.primary_pattern.ToString()); | 271 rule.primary_pattern.ToString()); |
267 setting_dict->SetString(keys::kSecondaryPatternKey, | 272 setting_dict->SetString(keys::kSecondaryPatternKey, |
268 rule.secondary_pattern.ToString()); | 273 rule.secondary_pattern.ToString()); |
269 setting_dict->SetString( | 274 setting_dict->SetString( |
270 keys::kContentSettingsTypeKey, | 275 keys::kContentSettingsTypeKey, |
271 helpers::ContentSettingsTypeToString(it->first.content_type)); | 276 helpers::ContentSettingsTypeToString(key.content_type)); |
272 setting_dict->SetString(keys::kResourceIdentifierKey, | 277 setting_dict->SetString(keys::kResourceIdentifierKey, |
273 it->first.resource_identifier); | 278 key.resource_identifier); |
274 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); | 279 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); |
275 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); | 280 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); |
276 | 281 |
277 std::string setting_string = | 282 std::string setting_string = |
278 content_settings::ContentSettingToString(content_setting); | 283 content_settings::ContentSettingToString(content_setting); |
279 DCHECK(!setting_string.empty()); | 284 DCHECK(!setting_string.empty()); |
280 | 285 |
281 setting_dict->SetString(keys::kContentSettingKey, setting_string); | 286 setting_dict->SetString(keys::kContentSettingKey, setting_string); |
282 settings->Append(std::move(setting_dict)); | 287 settings->Append(std::move(setting_dict)); |
283 } | 288 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 ContentSettingsStore::FindEntry(const std::string& ext_id) const { | 377 ContentSettingsStore::FindEntry(const std::string& ext_id) const { |
373 ExtensionEntryMap::const_iterator i; | 378 ExtensionEntryMap::const_iterator i; |
374 for (i = entries_.begin(); i != entries_.end(); ++i) { | 379 for (i = entries_.begin(); i != entries_.end(); ++i) { |
375 if (i->second->id == ext_id) | 380 if (i->second->id == ext_id) |
376 return i; | 381 return i; |
377 } | 382 } |
378 return entries_.end(); | 383 return entries_.end(); |
379 } | 384 } |
380 | 385 |
381 } // namespace extensions | 386 } // namespace extensions |
OLD | NEW |