 Chromium Code Reviews
 Chromium Code Reviews Issue 2938163002:
  Store base::Value in ContentSettingPatternSource instead of an enum  (Closed)
    
  
    Issue 2938163002:
  Store base::Value in ContentSettingPatternSource instead of an enum  (Closed) 
  | 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 <algorithm> | 7 #include <algorithm> | 
| 8 #include <memory> | 8 #include <memory> | 
| 9 #include <set> | 9 #include <set> | 
| 10 #include <utility> | 10 #include <utility> | 
| 11 | 11 | 
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" | 
| 13 #include "base/logging.h" | 13 #include "base/logging.h" | 
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_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 "components/content_settings/core/common/content_settings_utils.h" | |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" | 
| 23 | 24 | 
| 24 using content::BrowserThread; | 25 using content::BrowserThread; | 
| 25 using content_settings::ConcatenationIterator; | 26 using content_settings::ConcatenationIterator; | 
| 26 using content_settings::Rule; | 27 using content_settings::Rule; | 
| 27 using content_settings::RuleIterator; | 28 using content_settings::RuleIterator; | 
| 28 using content_settings::OriginIdentifierValueMap; | 29 using content_settings::OriginIdentifierValueMap; | 
| 29 using content_settings::ResourceIdentifier; | 30 using content_settings::ResourceIdentifier; | 
| 30 using content_settings::ValueToContentSetting; | |
| 31 | 31 | 
| 32 namespace extensions { | 32 namespace extensions { | 
| 33 | 33 | 
| 34 namespace helpers = content_settings_helpers; | 34 namespace helpers = content_settings_helpers; | 
| 35 namespace keys = content_settings_api_constants; | 35 namespace keys = content_settings_api_constants; | 
| 36 | 36 | 
| 37 struct ContentSettingsStore::ExtensionEntry { | 37 struct ContentSettingsStore::ExtensionEntry { | 
| 38 // Extension id. | 38 // Extension id. | 
| 39 std::string id; | 39 std::string id; | 
| 40 // Installation time. | 40 // Installation time. | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 return; | 239 return; | 
| 240 } | 240 } | 
| 241 notify = !map->empty(); | 241 notify = !map->empty(); | 
| 242 map->clear(); | 242 map->clear(); | 
| 243 } | 243 } | 
| 244 if (notify) { | 244 if (notify) { | 
| 245 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); | 245 NotifyOfContentSettingChanged(ext_id, scope != kExtensionPrefsScopeRegular); | 
| 246 } | 246 } | 
| 247 } | 247 } | 
| 248 | 248 | 
| 249 std::unique_ptr<base::ListValue> ContentSettingsStore::GetSettingsForExtension( | 249 std::unique_ptr<base::ListValue> ContentSettingsStore::GetSettingsForExtension( | 
| 
lazyboy
2017/06/30 18:11:40
Since this touches persistent extension preference
 
tbansal1
2017/06/30 18:32:31
Correct, this CL should not affect any consumers.
 | |
| 250 const std::string& extension_id, | 250 const std::string& extension_id, | 
| 251 ExtensionPrefsScope scope) const { | 251 ExtensionPrefsScope scope) const { | 
| 252 base::AutoLock lock(lock_); | 252 base::AutoLock lock(lock_); | 
| 253 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); | 253 const OriginIdentifierValueMap* map = GetValueMap(extension_id, scope); | 
| 254 if (!map) | 254 if (!map) | 
| 255 return nullptr; | 255 return nullptr; | 
| 256 | 256 | 
| 257 auto settings = base::MakeUnique<base::ListValue>(); | 257 auto settings = base::MakeUnique<base::ListValue>(); | 
| 258 for (const auto& it : *map) { | 258 for (const auto& it : *map) { | 
| 259 const auto& key = it.first; | 259 const auto& key = it.first; | 
| 260 std::unique_ptr<RuleIterator> rule_iterator( | 260 std::unique_ptr<RuleIterator> rule_iterator( | 
| 261 map->GetRuleIterator(key.content_type, key.resource_identifier, | 261 map->GetRuleIterator(key.content_type, key.resource_identifier, | 
| 262 nullptr)); // We already hold the lock. | 262 nullptr)); // We already hold the lock. | 
| 263 if (!rule_iterator) | 263 if (!rule_iterator) | 
| 264 continue; | 264 continue; | 
| 265 | 265 | 
| 266 while (rule_iterator->HasNext()) { | 266 while (rule_iterator->HasNext()) { | 
| 267 const Rule& rule = rule_iterator->Next(); | 267 const Rule& rule = rule_iterator->Next(); | 
| 268 std::unique_ptr<base::DictionaryValue> setting_dict( | 268 std::unique_ptr<base::DictionaryValue> setting_dict( | 
| 269 new base::DictionaryValue()); | 269 new base::DictionaryValue()); | 
| 270 setting_dict->SetString(keys::kPrimaryPatternKey, | 270 setting_dict->SetString(keys::kPrimaryPatternKey, | 
| 271 rule.primary_pattern.ToString()); | 271 rule.primary_pattern.ToString()); | 
| 272 setting_dict->SetString(keys::kSecondaryPatternKey, | 272 setting_dict->SetString(keys::kSecondaryPatternKey, | 
| 273 rule.secondary_pattern.ToString()); | 273 rule.secondary_pattern.ToString()); | 
| 274 setting_dict->SetString( | 274 setting_dict->SetString( | 
| 275 keys::kContentSettingsTypeKey, | 275 keys::kContentSettingsTypeKey, | 
| 276 helpers::ContentSettingsTypeToString(key.content_type)); | 276 helpers::ContentSettingsTypeToString(key.content_type)); | 
| 277 setting_dict->SetString(keys::kResourceIdentifierKey, | 277 setting_dict->SetString(keys::kResourceIdentifierKey, | 
| 278 key.resource_identifier); | 278 key.resource_identifier); | 
| 279 ContentSetting content_setting = ValueToContentSetting(rule.value.get()); | 279 ContentSetting content_setting = | 
| 280 content_settings::ValueToContentSetting(rule.value.get()); | |
| 280 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); | 281 DCHECK_NE(CONTENT_SETTING_DEFAULT, content_setting); | 
| 281 | 282 | 
| 282 std::string setting_string = | 283 std::string setting_string = | 
| 283 content_settings::ContentSettingToString(content_setting); | 284 content_settings::ContentSettingToString(content_setting); | 
| 284 DCHECK(!setting_string.empty()); | 285 DCHECK(!setting_string.empty()); | 
| 285 | 286 | 
| 286 setting_dict->SetString(keys::kContentSettingKey, setting_string); | 287 setting_dict->SetString(keys::kContentSettingKey, setting_string); | 
| 287 settings->Append(std::move(setting_dict)); | 288 settings->Append(std::move(setting_dict)); | 
| 288 } | 289 } | 
| 289 } | 290 } | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 | 385 | 
| 385 ContentSettingsStore::ExtensionEntries::iterator | 386 ContentSettingsStore::ExtensionEntries::iterator | 
| 386 ContentSettingsStore::FindIterator(const std::string& ext_id) { | 387 ContentSettingsStore::FindIterator(const std::string& ext_id) { | 
| 387 return std::find_if(entries_.begin(), entries_.end(), | 388 return std::find_if(entries_.begin(), entries_.end(), | 
| 388 [ext_id](const std::unique_ptr<ExtensionEntry>& entry) { | 389 [ext_id](const std::unique_ptr<ExtensionEntry>& entry) { | 
| 389 return entry->id == ext_id; | 390 return entry->id == ext_id; | 
| 390 }); | 391 }); | 
| 391 } | 392 } | 
| 392 | 393 | 
| 393 } // namespace extensions | 394 } // namespace extensions | 
| OLD | NEW |