summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authordeepak.m1 <deepak.m1@samsung.com>2015-08-13 06:33:31 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-13 13:34:27 +0000
commit179fa2991dbcf898490ff86688a628ffaa5af563 (patch)
tree1ce216e00b04f810a40ffcb1c523654f8c248f62 /components
parent63ee954a877f24377263faa5cd0ad6065e9b4b2e (diff)
downloadchromium_src-179fa2991dbcf898490ff86688a628ffaa5af563.zip
chromium_src-179fa2991dbcf898490ff86688a628ffaa5af563.tar.gz
chromium_src-179fa2991dbcf898490ff86688a628ffaa5af563.tar.bz2
Remove the array of Provider Names and Provider Source and replace with a map.
Provider Names and Provider Source are in the form of seprate array. map usage will make it better readability and maintainability. BUG= 520352 Review URL: https://codereview.chromium.org/1287943006 Cr-Commit-Position: refs/heads/master@{#343188}
Diffstat (limited to 'components')
-rw-r--r--components/content_settings/core/browser/host_content_settings_map.cc51
1 files changed, 23 insertions, 28 deletions
diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc
index d11ca9b..9ffe838 100644
--- a/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/components/content_settings/core/browser/host_content_settings_map.cc
@@ -34,16 +34,6 @@ typedef std::vector<content_settings::Rule> Rules;
typedef std::pair<std::string, std::string> StringPair;
-// TODO(bauerb): Expose constants.
-const char* kProviderNames[] = {
- "platform_app",
- "policy",
- "supervised_user",
- "extension",
- "preference",
- "default"
-};
-
// These constants are copied from extensions/common/extension_constants.h and
// content/public/common/url_constants.h to avoid complicated dependencies.
// TODO(vabr): Get these constants through the ContentSettingsClient.
@@ -54,17 +44,24 @@ const char kChromeUIScheme[] = "chrome";
const char kExtensionScheme[] = "chrome-extension";
#endif
-content_settings::SettingSource kProviderSourceMap[] = {
- content_settings::SETTING_SOURCE_EXTENSION,
- content_settings::SETTING_SOURCE_POLICY,
- content_settings::SETTING_SOURCE_SUPERVISED,
- content_settings::SETTING_SOURCE_EXTENSION,
- content_settings::SETTING_SOURCE_USER,
- content_settings::SETTING_SOURCE_USER,
+struct ProviderNamesSourceMapEntry {
+ const char* provider_name;
+ content_settings::SettingSource provider_source;
};
-static_assert(arraysize(kProviderSourceMap) ==
- HostContentSettingsMap::NUM_PROVIDER_TYPES,
- "kProviderSourceMap should have NUM_PROVIDER_TYPES elements");
+
+const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = {
+ {"platform_app", content_settings::SETTING_SOURCE_EXTENSION},
+ {"policy", content_settings::SETTING_SOURCE_POLICY},
+ {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED},
+ {"extension", content_settings::SETTING_SOURCE_EXTENSION},
+ {"preference", content_settings::SETTING_SOURCE_USER},
+ {"default", content_settings::SETTING_SOURCE_USER},
+};
+
+static_assert(
+ arraysize(kProviderNamesSourceMap) ==
+ HostContentSettingsMap::NUM_PROVIDER_TYPES,
+ "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements");
// Returns true if the |content_type| supports a resource identifier.
// Resource identifiers are supported (but not required) for plugins.
@@ -160,7 +157,7 @@ ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
GetDefaultContentSettingFromProvider(content_type, provider->second);
if (default_setting != CONTENT_SETTING_DEFAULT) {
if (provider_id)
- *provider_id = kProviderNames[provider->first];
+ *provider_id = kProviderNamesSourceMap[provider->first].provider_name;
return default_setting;
}
}
@@ -577,10 +574,8 @@ void HostContentSettingsMap::AddSettingsForOneType(
setting_value = content_settings::ValueToContentSetting(rule.value.get());
}
settings->push_back(ContentSettingPatternSource(
- rule.primary_pattern, rule.secondary_pattern,
- setting_value,
- kProviderNames[provider_type],
- incognito));
+ rule.primary_pattern, rule.secondary_pattern, setting_value,
+ kProviderNamesSourceMap[provider_type].provider_name, incognito));
}
}
@@ -662,8 +657,8 @@ scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSetting(
// static
HostContentSettingsMap::ProviderType
HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) {
- for (size_t i = 0; i < arraysize(kProviderNames); ++i) {
- if (source == kProviderNames[i])
+ for (size_t i = 0; i < arraysize(kProviderNamesSourceMap); ++i) {
+ if (source == kProviderNamesSourceMap[i].provider_name)
return static_cast<ProviderType>(i);
}
@@ -711,7 +706,7 @@ scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSettingInternal(
secondary_pattern));
if (value) {
if (info)
- info->source = kProviderSourceMap[provider->first];
+ info->source = kProviderNamesSourceMap[provider->first].provider_source;
return value.Pass();
}
}