| 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_registry.h" | 5 #include "components/content_settings/core/browser/content_settings_registry.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/content_settings/core/browser/content_settings_utils.h" | 10 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 11 #include "components/content_settings/core/browser/website_settings_registry.h" | 11 #include "components/content_settings/core/browser/website_settings_registry.h" |
| 12 #include "components/content_settings/core/common/content_settings.h" | 12 #include "components/content_settings/core/common/content_settings.h" |
| 13 | 13 |
| 14 #if defined(ENABLE_PLUGINS) | 14 #if defined(ENABLE_PLUGINS) |
| 15 #include "components/content_settings/core/browser/plugins_field_trial.h" | 15 #include "components/content_settings/core/browser/plugins_field_trial.h" |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 namespace content_settings { | 18 namespace content_settings { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void ContentSettingsRegistry::ResetForTest() { | 79 void ContentSettingsRegistry::ResetForTest() { |
| 80 website_settings_registry_->ResetForTest(); | 80 website_settings_registry_->ResetForTest(); |
| 81 content_settings_info_.clear(); | 81 content_settings_info_.clear(); |
| 82 Init(); | 82 Init(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 ContentSettingsRegistry::~ContentSettingsRegistry() {} | 85 ContentSettingsRegistry::~ContentSettingsRegistry() {} |
| 86 | 86 |
| 87 const ContentSettingsInfo* ContentSettingsRegistry::Get( | 87 const ContentSettingsInfo* ContentSettingsRegistry::Get( |
| 88 ContentSettingsType type) const { | 88 ContentSettingsType type) const { |
| 89 DCHECK_GE(type, 0); | 89 const auto& it = content_settings_info_.find(type); |
| 90 DCHECK_LT(type, static_cast<int>(content_settings_info_.size())); | 90 if (it != content_settings_info_.end()) |
| 91 return content_settings_info_[type]; | 91 return it->second; |
| 92 return nullptr; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void ContentSettingsRegistry::Init() { | 95 void ContentSettingsRegistry::Init() { |
| 95 content_settings_info_.resize(CONTENT_SETTINGS_NUM_TYPES); | |
| 96 | |
| 97 // TODO(raymes): This registration code should not have to be in a single | 96 // TODO(raymes): This registration code should not have to be in a single |
| 98 // location. It should be possible to register a setting from the code | 97 // location. It should be possible to register a setting from the code |
| 99 // associated with it. | 98 // associated with it. |
| 100 | 99 |
| 101 // WARNING: The string names of the permissions passed in below are used to | 100 // WARNING: The string names of the permissions passed in below are used to |
| 102 // generate preference names and should never be changed! | 101 // generate preference names and should never be changed! |
| 103 | 102 |
| 104 // Content settings (those with allow/block/ask/etc. values). | 103 // Content settings (those with allow/block/ask/etc. values). |
| 105 Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies", CONTENT_SETTING_ALLOW, | 104 Register(CONTENT_SETTINGS_TYPE_COOKIES, "cookies", CONTENT_SETTING_ALLOW, |
| 106 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); | 105 WebsiteSettingsInfo::SYNCABLE, WhitelistedForWebUI()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 WebsiteSettingsInfo::SyncStatus sync_status, | 173 WebsiteSettingsInfo::SyncStatus sync_status, |
| 175 const std::vector<std::string>& whitelisted_schemes) { | 174 const std::vector<std::string>& whitelisted_schemes) { |
| 176 // Ensure that nothing has been registered yet for the given type. | 175 // Ensure that nothing has been registered yet for the given type. |
| 177 DCHECK(!website_settings_registry_->Get(type)); | 176 DCHECK(!website_settings_registry_->Get(type)); |
| 178 scoped_ptr<base::Value> default_value( | 177 scoped_ptr<base::Value> default_value( |
| 179 new base::FundamentalValue(static_cast<int>(initial_default_value))); | 178 new base::FundamentalValue(static_cast<int>(initial_default_value))); |
| 180 const WebsiteSettingsInfo* website_settings_info = | 179 const WebsiteSettingsInfo* website_settings_info = |
| 181 website_settings_registry_->Register(type, name, default_value.Pass(), | 180 website_settings_registry_->Register(type, name, default_value.Pass(), |
| 182 sync_status, | 181 sync_status, |
| 183 WebsiteSettingsInfo::NOT_LOSSY); | 182 WebsiteSettingsInfo::NOT_LOSSY); |
| 184 DCHECK_GE(type, 0); | 183 DCHECK(!ContainsKey(content_settings_info_, type)); |
| 185 DCHECK_LT(type, static_cast<int>(content_settings_info_.size())); | 184 content_settings_info_.set( |
| 186 content_settings_info_[type] = | 185 type, make_scoped_ptr(new ContentSettingsInfo(website_settings_info, |
| 187 new ContentSettingsInfo(website_settings_info, whitelisted_schemes); | 186 whitelisted_schemes))); |
| 188 } | 187 } |
| 189 | 188 |
| 190 } // namespace content_settings | 189 } // namespace content_settings |
| OLD | NEW |