| 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 <set> | 8 #include <set> |
| 8 #include <utility> | 9 #include <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" | 17 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co
nstants.h" |
| 18 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" | 18 #include "chrome/browser/extensions/api/content_settings/content_settings_helper
s.h" |
| 19 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" | 19 #include "components/content_settings/core/browser/content_settings_origin_ident
ifier_value_map.h" |
| 20 #include "components/content_settings/core/browser/content_settings_rule.h" | 20 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 21 #include "components/content_settings/core/browser/content_settings_utils.h" | 21 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 | 23 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 ContentSettingsStore::ContentSettingsStore() { | 50 ContentSettingsStore::ContentSettingsStore() { |
| 51 DCHECK(OnCorrectThread()); | 51 DCHECK(OnCorrectThread()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ContentSettingsStore::~ContentSettingsStore() { | 54 ContentSettingsStore::~ContentSettingsStore() { |
| 55 STLDeleteValues(&entries_); | 55 STLDeleteValues(&entries_); |
| 56 } | 56 } |
| 57 | 57 |
| 58 scoped_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<scoped_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; |
| 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 scoped_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 = entries_.rbegin(); entry != entries_.rend(); ++entry) { |
| 72 if (!entry->second->enabled) | 72 if (!entry->second->enabled) |
| 73 continue; | 73 continue; |
| 74 | 74 |
| 75 if (incognito) { | 75 if (incognito) { |
| 76 iterators.push_back( | 76 iterators.push_back( |
| 77 entry->second->incognito_session_only_settings.GetRuleIterator( | 77 entry->second->incognito_session_only_settings.GetRuleIterator( |
| 78 type, | 78 type, |
| 79 identifier, | 79 identifier, |
| 80 NULL)); | 80 NULL)); |
| 81 iterators.push_back( | 81 iterators.push_back( |
| 82 entry->second->incognito_persistent_settings.GetRuleIterator( | 82 entry->second->incognito_persistent_settings.GetRuleIterator( |
| 83 type, | 83 type, |
| 84 identifier, | 84 identifier, |
| 85 NULL)); | 85 NULL)); |
| 86 } else { | 86 } else { |
| 87 iterators.push_back( | 87 iterators.push_back( |
| 88 entry->second->settings.GetRuleIterator(type, identifier, NULL)); | 88 entry->second->settings.GetRuleIterator(type, identifier, NULL)); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 return scoped_ptr<RuleIterator>( | 91 return std::unique_ptr<RuleIterator>( |
| 92 new ConcatenationIterator(std::move(iterators), auto_lock.release())); | 92 new ConcatenationIterator(std::move(iterators), auto_lock.release())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ContentSettingsStore::SetExtensionContentSetting( | 95 void ContentSettingsStore::SetExtensionContentSetting( |
| 96 const std::string& ext_id, | 96 const std::string& ext_id, |
| 97 const ContentSettingsPattern& primary_pattern, | 97 const ContentSettingsPattern& primary_pattern, |
| 98 const ContentSettingsPattern& secondary_pattern, | 98 const ContentSettingsPattern& secondary_pattern, |
| 99 ContentSettingsType type, | 99 ContentSettingsType type, |
| 100 const content_settings::ResourceIdentifier& identifier, | 100 const content_settings::ResourceIdentifier& identifier, |
| 101 ContentSetting setting, | 101 ContentSetting setting, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 base::ListValue* ContentSettingsStore::GetSettingsForExtension( | 248 base::ListValue* ContentSettingsStore::GetSettingsForExtension( |
| 249 const std::string& extension_id, | 249 const std::string& extension_id, |
| 250 ExtensionPrefsScope scope) const { | 250 ExtensionPrefsScope scope) const { |
| 251 base::AutoLock lock(lock_); | 251 base::AutoLock lock(lock_); |
| 252 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); | 252 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); |
| 253 if (!map) | 253 if (!map) |
| 254 return NULL; | 254 return NULL; |
| 255 base::ListValue* settings = new base::ListValue(); | 255 base::ListValue* settings = new base::ListValue(); |
| 256 OriginIdentifierValueMap::EntryMap::const_iterator it; | 256 OriginIdentifierValueMap::EntryMap::const_iterator it; |
| 257 for (it = map->begin(); it != map->end(); ++it) { | 257 for (it = map->begin(); it != map->end(); ++it) { |
| 258 scoped_ptr<RuleIterator> rule_iterator( | 258 std::unique_ptr<RuleIterator> rule_iterator(map->GetRuleIterator( |
| 259 map->GetRuleIterator(it->first.content_type, | 259 it->first.content_type, it->first.resource_identifier, |
| 260 it->first.resource_identifier, | 260 NULL)); // We already hold the lock. |
| 261 NULL)); // We already hold the lock. | |
| 262 while (rule_iterator->HasNext()) { | 261 while (rule_iterator->HasNext()) { |
| 263 const Rule& rule = rule_iterator->Next(); | 262 const Rule& rule = rule_iterator->Next(); |
| 264 base::DictionaryValue* setting_dict = new base::DictionaryValue(); | 263 base::DictionaryValue* setting_dict = new base::DictionaryValue(); |
| 265 setting_dict->SetString(keys::kPrimaryPatternKey, | 264 setting_dict->SetString(keys::kPrimaryPatternKey, |
| 266 rule.primary_pattern.ToString()); | 265 rule.primary_pattern.ToString()); |
| 267 setting_dict->SetString(keys::kSecondaryPatternKey, | 266 setting_dict->SetString(keys::kSecondaryPatternKey, |
| 268 rule.secondary_pattern.ToString()); | 267 rule.secondary_pattern.ToString()); |
| 269 setting_dict->SetString( | 268 setting_dict->SetString( |
| 270 keys::kContentSettingsTypeKey, | 269 keys::kContentSettingsTypeKey, |
| 271 helpers::ContentSettingsTypeToString(it->first.content_type)); | 270 helpers::ContentSettingsTypeToString(it->first.content_type)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 ContentSettingsStore::FindEntry(const std::string& ext_id) const { | 372 ContentSettingsStore::FindEntry(const std::string& ext_id) const { |
| 374 ExtensionEntryMap::const_iterator i; | 373 ExtensionEntryMap::const_iterator i; |
| 375 for (i = entries_.begin(); i != entries_.end(); ++i) { | 374 for (i = entries_.begin(); i != entries_.end(); ++i) { |
| 376 if (i->second->id == ext_id) | 375 if (i->second->id == ext_id) |
| 377 return i; | 376 return i; |
| 378 } | 377 } |
| 379 return entries_.end(); | 378 return entries_.end(); |
| 380 } | 379 } |
| 381 | 380 |
| 382 } // namespace extensions | 381 } // namespace extensions |
| OLD | NEW |