diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 22:12:39 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 22:12:39 +0000 |
commit | aea9fa18d6b83fa89042d9b16d70a9d1ade82d75 (patch) | |
tree | 12141767349b89e3f602cd16e87668d2637e3234 /chrome | |
parent | de617a9345708fff10c79c99b9c9279d84013f4e (diff) | |
download | chromium_src-aea9fa18d6b83fa89042d9b16d70a9d1ade82d75.zip chromium_src-aea9fa18d6b83fa89042d9b16d70a9d1ade82d75.tar.gz chromium_src-aea9fa18d6b83fa89042d9b16d70a9d1ade82d75.tar.bz2 |
Generate Chrome policy definition list from policy_templates.json.
The struct and static array is now generated into policy_constants.h.
Added policy::GetChromePolicyDefinitionList() and policy::GetPolicyName().
Removed ConfigurationPolicyProvider::PolicyDefinitionList.
Removed PolicyStates::GetPolicyName().
Removed ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList().
BUG=None
TEST=Everything works as before, nothing breaks
Review URL: http://codereview.chromium.org/8258018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105388 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
32 files changed, 234 insertions, 408 deletions
diff --git a/chrome/app/policy/cloud_policy_codegen.gyp b/chrome/app/policy/cloud_policy_codegen.gyp index 1f93409..52daac4 100644 --- a/chrome/app/policy/cloud_policy_codegen.gyp +++ b/chrome/app/policy/cloud_policy_codegen.gyp @@ -181,6 +181,9 @@ '<(policy_constant_source_path)', '<(configuration_policy_type_header_path)', ], + 'include_dirs': [ + '<(DEPTH)', + ], 'direct_dependent_settings': { 'include_dirs': [ '<(policy_out_dir)' diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index 54073ac..e2fc49e 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -69,18 +69,24 @@ # platform name, e.g.: 'chrome.win' is read as 'Chrome on Windows'. Version # numbers can be any string that does not contain ':' or '-' characters. # -# Currently supported product names: -# 'chrome_frame', 'chrome_os' -# 'chrome.win', 'chrome.linux', 'chrome.mac', 'chrome.*' -# For example if 'chrome.*:5-10' is specified for a policy, then it should -# be read as: -# 'chrome.linux:5-10', 'chrome.mac:5-10', 'chrome.win:5-10' -# The product name also affects in which templates will the policy be included. -# chrome.*, chrome.win, chrome_frame -> ADM,ADMX,ADML,doc -# chrome.*, chrome.linux -> JSON,doc -# chrome.*, chrome.mac -> plist, plist_strings,doc +# Currently supported product names: +# 'chrome_frame', 'chrome_os' +# 'chrome.win', 'chrome.linux', 'chrome.mac', 'chrome.*' +# For example if 'chrome.*:5-10' is specified for a policy, then it should +# be read as: +# 'chrome.linux:5-10', 'chrome.mac:5-10', 'chrome.win:5-10' +# +# The product name also affects in which templates the policy is included: +# chrome.*, chrome.win, chrome_frame -> ADM, ADMX, ADML, doc +# chrome.*, chrome.linux -> JSON, doc +# chrome.*, chrome.mac -> plist, plist_strings, doc # everything else -> doc # +# The default list of policies supported by Chrome is also generated based +# on the product names: +# chrome.* -> Chrome policy definition list +# chrome_os -> Chrome policy definition list, when building OS_CHROMEOS +# # Annotations: # Additional information is specified under keys 'features' and # 'example_value'. These are used in the generated documentation and example @@ -384,7 +390,7 @@ { 'name': 'CloudPrintProxyEnabled', 'type': 'main', - 'supported_on': [], + 'supported_on': ['chrome.*:X-'], 'features': {'dynamic_refresh': 1}, 'future': True, 'example_value': True, diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 50faa3c..2237ffa 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -126,9 +126,9 @@ #if defined(ENABLE_CONFIGURATION_POLICY) #include "chrome/browser/policy/browser_policy_connector.h" -#include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/configuration_policy_provider.h" #include "chrome/browser/policy/policy_map.h" +#include "policy/policy_constants.h" #endif #if defined(OS_CHROMEOS) @@ -5867,8 +5867,8 @@ void TestingAutomationProvider::SetPolicies( #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) reply.SendError("Configuration Policy disabled"); #else - const policy::ConfigurationPolicyProvider::PolicyDefinitionList* list = - policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + const policy::PolicyDefinitionList* list = + policy::GetChromePolicyDefinitionList(); policy::BrowserPolicyConnector* connector = g_browser_process->browser_policy_connector(); struct { @@ -5913,8 +5913,8 @@ void TestingAutomationProvider::GetPolicyDefinitionList( #else DictionaryValue response; - const policy::ConfigurationPolicyProvider::PolicyDefinitionList* list = - policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + const policy::PolicyDefinitionList* list = + policy::GetChromePolicyDefinitionList(); // Value::Type to python type. std::map<Value::Type, std::string> types; types[Value::TYPE_BOOLEAN] = "bool"; @@ -5922,7 +5922,7 @@ void TestingAutomationProvider::GetPolicyDefinitionList( types[Value::TYPE_STRING] = "str"; types[Value::TYPE_LIST] = "list"; - const policy::ConfigurationPolicyProvider::PolicyDefinitionList::Entry* entry; + const policy::PolicyDefinitionList::Entry* entry; for (entry = list->begin; entry != list->end; ++entry) { if (types.find(entry->value_type) == types.end()) { std::string error("Unrecognized policy type for policy "); diff --git a/chrome/browser/automation/testing_automation_provider_chromeos.cc b/chrome/browser/automation/testing_automation_provider_chromeos.cc index 38ccb97..5196114 100644 --- a/chrome/browser/automation/testing_automation_provider_chromeos.cc +++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc @@ -201,7 +201,7 @@ DictionaryValue* CreateDictionaryWithPolicies( if (policy_map) { policy::PolicyMap::const_iterator i; for (i = policy_map->begin(); i != policy_map->end(); i++) - dict->Set(policy::key::kMapPolicyString[i->first], + dict->Set(policy::GetPolicyName(i->first), i->second->DeepCopy()); } } diff --git a/chrome/browser/policy/asynchronous_policy_provider_unittest.cc b/chrome/browser/policy/asynchronous_policy_provider_unittest.cc index 1b7c1e1..fec42a1 100644 --- a/chrome/browser/policy/asynchronous_policy_provider_unittest.cc +++ b/chrome/browser/policy/asynchronous_policy_provider_unittest.cc @@ -24,7 +24,7 @@ TEST_F(AsynchronousPolicyTestBase, Provide) { policies->SetBoolean(policy::key::kSyncDisabled, true); EXPECT_CALL(*delegate_, Load()).WillOnce(Return(policies)); AsynchronousPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), + GetChromePolicyDefinitionList(), new AsynchronousPolicyLoader(delegate_.release(), 10)); PolicyMap policy_map; provider.Provide(&policy_map); @@ -46,9 +46,7 @@ TEST_F(AsynchronousPolicyTestBase, ProvideAfterRefresh) { EXPECT_CALL(*delegate_, Load()).WillOnce(Return(refresh_policies)); AsynchronousPolicyLoader* loader = new AsynchronousPolicyLoader(delegate_.release(), 10); - AsynchronousPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - loader); + AsynchronousPolicyProvider provider(GetChromePolicyDefinitionList(), loader); loop_.RunAllPending(); loader->Reload(); PolicyMap policy_map; diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc index 38ed053..25315d3 100644 --- a/chrome/browser/policy/browser_policy_connector.cc +++ b/chrome/browser/policy/browser_policy_connector.cc @@ -23,6 +23,7 @@ #include "chrome/common/pref_names.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" +#include "policy/policy_constants.h" #if defined(OS_WIN) #include "chrome/browser/policy/configuration_policy_provider_win.h" @@ -313,10 +314,10 @@ BrowserPolicyConnector::BrowserPolicyConnector() recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); managed_cloud_provider_.reset(new CloudPolicyProviderImpl( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), + GetChromePolicyDefinitionList(), CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY)); recommended_cloud_provider_.reset(new CloudPolicyProviderImpl( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), + GetChromePolicyDefinitionList(), CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED)); #if defined(OS_CHROMEOS) @@ -421,8 +422,7 @@ BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { // static ConfigurationPolicyProvider* BrowserPolicyConnector::CreateManagedPlatformProvider() { - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); #if defined(OS_WIN) return new ConfigurationPolicyProviderWin(policy_list); #elif defined(OS_MACOSX) @@ -445,8 +445,7 @@ ConfigurationPolicyProvider* ConfigurationPolicyProvider* BrowserPolicyConnector::CreateRecommendedPlatformProvider() { #if defined(OS_POSIX) && !defined(OS_MACOSX) - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + const PolicyDefinitionList* policy_list = GetChromePolicyDefinitionList(); FilePath config_dir_path; if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { return new ConfigDirPolicyProvider( diff --git a/chrome/browser/policy/cloud_policy_provider.cc b/chrome/browser/policy/cloud_policy_provider.cc index d8b3c79..a5f5c2c 100644 --- a/chrome/browser/policy/cloud_policy_provider.cc +++ b/chrome/browser/policy/cloud_policy_provider.cc @@ -7,7 +7,7 @@ namespace policy { CloudPolicyProvider::CloudPolicyProvider( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list) + const PolicyDefinitionList* policy_list) : ConfigurationPolicyProvider(policy_list) { } diff --git a/chrome/browser/policy/cloud_policy_provider.h b/chrome/browser/policy/cloud_policy_provider.h index 7c7228e..a9bc606 100644 --- a/chrome/browser/policy/cloud_policy_provider.h +++ b/chrome/browser/policy/cloud_policy_provider.h @@ -25,8 +25,7 @@ class CloudPolicyCacheBase; // AppendCache(cache): adds |cache| to the back (i.e. least important cache). class CloudPolicyProvider : public ConfigurationPolicyProvider { public: - explicit CloudPolicyProvider( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list); + explicit CloudPolicyProvider(const PolicyDefinitionList* policy_list); virtual ~CloudPolicyProvider(); // Adds a new instance of CloudPolicyCacheBase to the end of |caches_|. diff --git a/chrome/browser/policy/cloud_policy_provider_impl.cc b/chrome/browser/policy/cloud_policy_provider_impl.cc index 9063ca70..d1c3f3b 100644 --- a/chrome/browser/policy/cloud_policy_provider_impl.cc +++ b/chrome/browser/policy/cloud_policy_provider_impl.cc @@ -9,7 +9,7 @@ namespace policy { CloudPolicyProviderImpl::CloudPolicyProviderImpl( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, + const PolicyDefinitionList* policy_list, CloudPolicyCacheBase::PolicyLevel level) : CloudPolicyProvider(policy_list), level_(level), diff --git a/chrome/browser/policy/cloud_policy_provider_unittest.cc b/chrome/browser/policy/cloud_policy_provider_unittest.cc index 11454f1..3be811e 100644 --- a/chrome/browser/policy/cloud_policy_provider_unittest.cc +++ b/chrome/browser/policy/cloud_policy_provider_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/policy/cloud_policy_cache_base.h" #include "chrome/browser/policy/cloud_policy_provider_impl.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "policy/policy_constants.h" #include "testing/gmock/include/gmock/gmock.h" using testing::AnyNumber; @@ -58,7 +59,7 @@ class CloudPolicyProviderTest : public testing::Test { protected: void CreateCloudPolicyProvider(CloudPolicyCacheBase::PolicyLevel level) { cloud_policy_provider_.reset(new CloudPolicyProviderImpl( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), level)); + GetChromePolicyDefinitionList(), level)); } // Appends the caches to a provider and then provides the policies to @@ -66,7 +67,7 @@ class CloudPolicyProviderTest : public testing::Test { void RunCachesThroughProvider(MockCloudPolicyCache caches[], int n, CloudPolicyCacheBase::PolicyLevel level) { CloudPolicyProviderImpl provider( - policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), + GetChromePolicyDefinitionList(), level); for (int i = 0; i < n; i++) { provider.AppendCache(&caches[i]); @@ -222,12 +223,12 @@ TEST_F(CloudPolicyProviderTest, CombineTwoPolicyMapsProxies) { PolicyMap A, B, C; CreateCloudPolicyProvider(CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED); - A.Set(policy::kPolicyProxyMode, Value::CreateIntegerValue(a_value)); + A.Set(kPolicyProxyMode, Value::CreateIntegerValue(a_value)); - B.Set(policy::kPolicyProxyServerMode, Value::CreateIntegerValue(b_value)); - B.Set(policy::kPolicyProxyServer, Value::CreateIntegerValue(b_value)); - B.Set(policy::kPolicyProxyPacUrl, Value::CreateIntegerValue(b_value)); - B.Set(policy::kPolicyProxyBypassList, Value::CreateIntegerValue(b_value)); + B.Set(kPolicyProxyServerMode, Value::CreateIntegerValue(b_value)); + B.Set(kPolicyProxyServer, Value::CreateIntegerValue(b_value)); + B.Set(kPolicyProxyPacUrl, Value::CreateIntegerValue(b_value)); + B.Set(kPolicyProxyBypassList, Value::CreateIntegerValue(b_value)); CombineTwoPolicyMaps(A, B, &C); diff --git a/chrome/browser/policy/config_dir_policy_provider.cc b/chrome/browser/policy/config_dir_policy_provider.cc index 36d89d8..86dde7f 100644 --- a/chrome/browser/policy/config_dir_policy_provider.cc +++ b/chrome/browser/policy/config_dir_policy_provider.cc @@ -80,7 +80,7 @@ base::Time ConfigDirPolicyProviderDelegate::GetLastModification() { } ConfigDirPolicyProvider::ConfigDirPolicyProvider( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, + const PolicyDefinitionList* policy_list, const FilePath& config_dir) : FileBasedPolicyProvider( policy_list, diff --git a/chrome/browser/policy/config_dir_policy_provider.h b/chrome/browser/policy/config_dir_policy_provider.h index 3535ad9..e397da3 100644 --- a/chrome/browser/policy/config_dir_policy_provider.h +++ b/chrome/browser/policy/config_dir_policy_provider.h @@ -17,9 +17,8 @@ namespace policy { // Policy provider backed by JSON files in a configuration directory. class ConfigDirPolicyProvider : public FileBasedPolicyProvider { public: - ConfigDirPolicyProvider( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, - const FilePath& config_dir); + ConfigDirPolicyProvider(const PolicyDefinitionList* policy_list, + const FilePath& config_dir); private: DISALLOW_COPY_AND_ASSIGN(ConfigDirPolicyProvider); diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_provider_unittest.cc index 9fffad6..4663991 100644 --- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc +++ b/chrome/browser/policy/config_dir_policy_provider_unittest.cc @@ -186,9 +186,7 @@ class ConfigDirPolicyProviderValueTest }; TEST_P(ConfigDirPolicyProviderValueTest, Default) { - ConfigDirPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - test_dir()); + ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir()); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_TRUE(policy_map.empty()); @@ -198,9 +196,7 @@ TEST_P(ConfigDirPolicyProviderValueTest, NullValue) { DictionaryValue dict; dict.Set(GetParam().policy_key(), Value::CreateNullValue()); WriteConfigFile(dict, "empty"); - ConfigDirPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - test_dir()); + ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir()); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_TRUE(policy_map.empty()); @@ -210,9 +206,7 @@ TEST_P(ConfigDirPolicyProviderValueTest, TestValue) { DictionaryValue dict; dict.Set(GetParam().policy_key(), GetParam().test_value()->DeepCopy()); WriteConfigFile(dict, "policy"); - ConfigDirPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - test_dir()); + ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir()); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_EQ(1U, policy_map.size()); @@ -221,7 +215,9 @@ TEST_P(ConfigDirPolicyProviderValueTest, TestValue) { EXPECT_TRUE(GetParam().test_value()->Equals(value)); } -// Test parameters for all supported policies. +// Test parameters for all supported policies. testing::Values() has a limit of +// 50 parameters which is reached in this instantiation; new policies should go +// in a new instantiation. INSTANTIATE_TEST_CASE_P( ConfigDirPolicyProviderValueTestInstance, ConfigDirPolicyProviderValueTest, @@ -328,12 +324,6 @@ INSTANTIATE_TEST_CASE_P( ValueTestParams::ForBooleanPolicy( kPolicyPrintingEnabled, key::kPrintingEnabled), - ValueTestParams::ForIntegerPolicy( - kPolicyDevicePolicyRefreshRate, - key::kDevicePolicyRefreshRate), - ValueTestParams::ForIntegerPolicy( - kPolicyPolicyRefreshRate, - key::kPolicyRefreshRate), ValueTestParams::ForBooleanPolicy( kPolicyInstantEnabled, key::kInstantEnabled), @@ -375,14 +365,7 @@ INSTANTIATE_TEST_CASE_P( key::kDisabledSchemes), ValueTestParams::ForStringPolicy( kPolicyDiskCacheDir, - key::kDiskCacheDir))); - -// testing::Values has a limit of 50 test templates, which is reached by the -// instantiations above. Add tests for new policies here: -INSTANTIATE_TEST_CASE_P( - ConfigDirPolicyProviderValueTestInstance2, - ConfigDirPolicyProviderValueTest, - testing::Values( + key::kDiskCacheDir), ValueTestParams::ForListPolicy( kPolicyURLBlacklist, key::kURLBlacklist), @@ -390,4 +373,15 @@ INSTANTIATE_TEST_CASE_P( kPolicyURLWhitelist, key::kURLWhitelist))); +// Test parameters for all policies that are supported on ChromeOS only. +#if defined(OS_CHROMEOS) +INSTANTIATE_TEST_CASE_P( + ConfigDirPolicyProviderValueTestChromeOSInstance, + ConfigDirPolicyProviderValueTest, + testing::Values( + ValueTestParams::ForIntegerPolicy( + kPolicyPolicyRefreshRate, + key::kPolicyRefreshRate))); +#endif + } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 875a6fa..4f110f8 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -1044,202 +1044,6 @@ ConfigurationPolicyPrefStore::CreateRecommendedCloudPolicyPrefStore() { GetRecommendedCloudProvider()); } -/* static */ -const ConfigurationPolicyProvider::PolicyDefinitionList* -ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { - static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { - { kPolicyHomepageLocation, Value::TYPE_STRING, key::kHomepageLocation }, - { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, - key::kHomepageIsNewTabPage }, - { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, - { kPolicyRestoreOnStartupURLs, Value::TYPE_LIST, - key::kRestoreOnStartupURLs }, - { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, - key::kDefaultSearchProviderEnabled }, - { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, - key::kDefaultSearchProviderName }, - { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, - key::kDefaultSearchProviderKeyword }, - { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, - key::kDefaultSearchProviderSearchURL }, - { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, - key::kDefaultSearchProviderSuggestURL }, - { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, - key::kDefaultSearchProviderInstantURL }, - { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, - key::kDefaultSearchProviderIconURL }, - { kPolicyDefaultSearchProviderEncodings, Value::TYPE_LIST, - key::kDefaultSearchProviderEncodings }, - { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, - { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, - { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, - { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, - { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, - { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, - key::kAlternateErrorPagesEnabled }, - { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, - key::kSearchSuggestEnabled }, - { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, - key::kDnsPrefetchingEnabled }, - { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, - { kPolicyDisabledSchemes, Value::TYPE_LIST, key::kDisabledSchemes }, - { kPolicySafeBrowsingEnabled, Value::TYPE_BOOLEAN, - key::kSafeBrowsingEnabled }, - { kPolicyMetricsReportingEnabled, Value::TYPE_BOOLEAN, - key::kMetricsReportingEnabled }, - { kPolicyPasswordManagerEnabled, Value::TYPE_BOOLEAN, - key::kPasswordManagerEnabled }, - { kPolicyPasswordManagerAllowShowPasswords, Value::TYPE_BOOLEAN, - key::kPasswordManagerAllowShowPasswords }, - { kPolicyAutoFillEnabled, Value::TYPE_BOOLEAN, key::kAutoFillEnabled }, - { kPolicyDisabledPlugins, Value::TYPE_LIST, key::kDisabledPlugins }, - { kPolicyDisabledPluginsExceptions, Value::TYPE_LIST, - key::kDisabledPluginsExceptions }, - { kPolicyEnabledPlugins, Value::TYPE_LIST, key::kEnabledPlugins }, - { kPolicyApplicationLocaleValue, Value::TYPE_STRING, - key::kApplicationLocaleValue }, - { kPolicySyncDisabled, Value::TYPE_BOOLEAN, key::kSyncDisabled }, - { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST, - key::kExtensionInstallWhitelist }, - { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST, - key::kExtensionInstallBlacklist }, - { kPolicyExtensionInstallForcelist, Value::TYPE_LIST, - key::kExtensionInstallForcelist }, - { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, - { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, - { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, - { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, - { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER, - key::kIncognitoModeAvailability }, - { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, - key::kSavingBrowserHistoryDisabled }, - { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN, - key::kClearSiteDataOnExit }, - { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, - key::kDeveloperToolsDisabled }, - { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, - key::kBlockThirdPartyCookies }, - { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, - key::kDefaultCookiesSetting }, - { kPolicyDefaultImagesSetting, Value::TYPE_INTEGER, - key::kDefaultImagesSetting }, - { kPolicyDefaultJavaScriptSetting, Value::TYPE_INTEGER, - key::kDefaultJavaScriptSetting }, - { kPolicyDefaultPluginsSetting, Value::TYPE_INTEGER, - key::kDefaultPluginsSetting }, - { kPolicyDefaultPopupsSetting, Value::TYPE_INTEGER, - key::kDefaultPopupsSetting }, - { kPolicyDefaultNotificationsSetting, Value::TYPE_INTEGER, - key::kDefaultNotificationsSetting }, - { kPolicyDefaultGeolocationSetting, Value::TYPE_INTEGER, - key::kDefaultGeolocationSetting }, - { kPolicyAutoSelectCertificateForUrls, Value::TYPE_LIST, - key::kAutoSelectCertificateForUrls}, - { kPolicyCookiesAllowedForUrls, Value::TYPE_LIST, - key::kCookiesAllowedForUrls }, - { kPolicyCookiesBlockedForUrls, Value::TYPE_LIST, - key::kCookiesBlockedForUrls }, - { kPolicyCookiesSessionOnlyForUrls, Value::TYPE_LIST, - key::kCookiesSessionOnlyForUrls }, - { kPolicyImagesAllowedForUrls, Value::TYPE_LIST, - key::kImagesAllowedForUrls }, - { kPolicyImagesBlockedForUrls, Value::TYPE_LIST, - key::kImagesBlockedForUrls }, - { kPolicyJavaScriptAllowedForUrls, Value::TYPE_LIST, - key::kJavaScriptAllowedForUrls }, - { kPolicyJavaScriptBlockedForUrls, Value::TYPE_LIST, - key::kJavaScriptBlockedForUrls }, - { kPolicyPluginsAllowedForUrls, Value::TYPE_LIST, - key::kPluginsAllowedForUrls }, - { kPolicyPluginsBlockedForUrls, Value::TYPE_LIST, - key::kPluginsBlockedForUrls }, - { kPolicyPopupsAllowedForUrls, Value::TYPE_LIST, - key::kPopupsAllowedForUrls }, - { kPolicyPopupsBlockedForUrls, Value::TYPE_LIST, - key::kPopupsBlockedForUrls }, - { kPolicyNotificationsAllowedForUrls, Value::TYPE_LIST, - key::kNotificationsAllowedForUrls }, - { kPolicyNotificationsBlockedForUrls, Value::TYPE_LIST, - key::kNotificationsBlockedForUrls }, - { kPolicyAuthSchemes, Value::TYPE_STRING, key::kAuthSchemes }, - { kPolicyDisableAuthNegotiateCnameLookup, Value::TYPE_BOOLEAN, - key::kDisableAuthNegotiateCnameLookup }, - { kPolicyEnableAuthNegotiatePort, Value::TYPE_BOOLEAN, - key::kEnableAuthNegotiatePort }, - { kPolicyAuthServerWhitelist, Value::TYPE_STRING, - key::kAuthServerWhitelist }, - { kPolicyAuthNegotiateDelegateWhitelist, Value::TYPE_STRING, - key::kAuthNegotiateDelegateWhitelist }, - { kPolicyGSSAPILibraryName, Value::TYPE_STRING, - key::kGSSAPILibraryName }, - { kPolicyAllowCrossOriginAuthPrompt, Value::TYPE_BOOLEAN, - key::kAllowCrossOriginAuthPrompt }, - { kPolicyDisable3DAPIs, Value::TYPE_BOOLEAN, - key::kDisable3DAPIs }, - { kPolicyDisablePluginFinder, Value::TYPE_BOOLEAN, - key::kDisablePluginFinder }, - { kPolicyPolicyRefreshRate, Value::TYPE_INTEGER, - key::kPolicyRefreshRate }, - { kPolicyDevicePolicyRefreshRate, Value::TYPE_INTEGER, - key::kDevicePolicyRefreshRate }, - { kPolicyInstantEnabled, Value::TYPE_BOOLEAN, key::kInstantEnabled }, - { kPolicyDefaultBrowserSettingEnabled, Value::TYPE_BOOLEAN, - key::kDefaultBrowserSettingEnabled }, - { kPolicyRemoteAccessClientFirewallTraversal, Value::TYPE_BOOLEAN, - key::kRemoteAccessClientFirewallTraversal }, - { kPolicyRemoteAccessHostFirewallTraversal, Value::TYPE_BOOLEAN, - key::kRemoteAccessHostFirewallTraversal }, - { kPolicyCloudPrintProxyEnabled, Value::TYPE_BOOLEAN, - key::kCloudPrintProxyEnabled }, - { kPolicyDownloadDirectory, Value::TYPE_STRING, - key::kDownloadDirectory }, - { kPolicyTranslateEnabled, Value::TYPE_BOOLEAN, key::kTranslateEnabled }, - { kPolicyAllowOutdatedPlugins, Value::TYPE_BOOLEAN, - key::kAllowOutdatedPlugins }, - { kPolicyAlwaysAuthorizePlugins, Value::TYPE_BOOLEAN, - key::kAlwaysAuthorizePlugins }, - { kPolicyBookmarkBarEnabled, Value::TYPE_BOOLEAN, - key::kBookmarkBarEnabled }, - { kPolicyEditBookmarksEnabled, Value::TYPE_BOOLEAN, - key::kEditBookmarksEnabled }, - { kPolicyAllowFileSelectionDialogs, Value::TYPE_BOOLEAN, - key::kAllowFileSelectionDialogs }, - { kPolicyDiskCacheDir, Value::TYPE_STRING, - key::kDiskCacheDir }, - { kPolicyImportBookmarks, Value::TYPE_BOOLEAN, - key::kImportBookmarks }, - { kPolicyImportHistory, Value::TYPE_BOOLEAN, - key::kImportHistory }, - { kPolicyImportHomepage, Value::TYPE_BOOLEAN, - key::kImportHomepage }, - { kPolicyImportSearchEngine, Value::TYPE_BOOLEAN, - key::kImportSearchEngine }, - { kPolicyImportSavedPasswords, Value::TYPE_BOOLEAN, - key::kImportSavedPasswords }, - { kPolicyMaxConnectionsPerProxy, Value::TYPE_INTEGER, - key::kMaxConnectionsPerProxy }, - { kPolicyHideWebStorePromo, Value::TYPE_BOOLEAN, - key::kHideWebStorePromo }, - { kPolicyURLBlacklist, Value::TYPE_LIST, - key::kURLBlacklist }, - { kPolicyURLWhitelist, Value::TYPE_LIST, - key::kURLWhitelist }, - -#if defined(OS_CHROMEOS) - { kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN, - key::kChromeOsLockOnIdleSuspend }, - { kPolicyChromeOsReleaseChannel, Value::TYPE_STRING, - key::kChromeOsReleaseChannel }, -#endif - }; - - static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { - entries, - entries + arraysize(entries), - }; - return &policy_list; -} - bool ConfigurationPolicyPrefStore::IsProxyPolicy(ConfigurationPolicyType policy) { return policy == kPolicyProxyMode || diff --git a/chrome/browser/policy/configuration_policy_pref_store.h b/chrome/browser/policy/configuration_policy_pref_store.h index fca8ad6..4b570b2 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.h +++ b/chrome/browser/policy/configuration_policy_pref_store.h @@ -71,10 +71,6 @@ class ConfigurationPolicyPrefStore // Creates a ConfigurationPolicyPrefStore that reads recommended cloud policy. static ConfigurationPolicyPrefStore* CreateRecommendedCloudPolicyPrefStore(); - // Returns the default policy definition list for Chrome. - static const ConfigurationPolicyProvider::PolicyDefinitionList* - GetChromePolicyDefinitionList(); - // Returns true if the given policy is a proxy policy. static bool IsProxyPolicy(ConfigurationPolicyType policy); @@ -83,9 +79,6 @@ class ConfigurationPolicyPrefStore // sending out change notifications as appropriate. void Refresh(); - static const ConfigurationPolicyProvider::PolicyDefinitionList - kPolicyDefinitionList; - // The policy provider from which policy settings are read. ConfigurationPolicyProvider* provider_; diff --git a/chrome/browser/policy/configuration_policy_provider.h b/chrome/browser/policy/configuration_policy_provider.h index 4ad5c1a..3eb0a7d 100644 --- a/chrome/browser/policy/configuration_policy_provider.h +++ b/chrome/browser/policy/configuration_policy_provider.h @@ -17,6 +17,7 @@ namespace policy { +struct PolicyDefinitionList; class PolicyMap; // A mostly-abstract super class for platform-specific policy providers. @@ -31,19 +32,6 @@ class ConfigurationPolicyProvider { virtual void OnProviderGoingAway() = 0; }; - // Used for static arrays of policy values that is used to initialize an - // instance of the ConfigurationPolicyProvider. - struct PolicyDefinitionList { - struct Entry { - ConfigurationPolicyType policy_type; - base::Value::Type value_type; - const char* name; - }; - - const Entry* begin; - const Entry* end; - }; - explicit ConfigurationPolicyProvider(const PolicyDefinitionList* policy_list); virtual ~ConfigurationPolicyProvider(); diff --git a/chrome/browser/policy/configuration_policy_provider_delegate_win.cc b/chrome/browser/policy/configuration_policy_provider_delegate_win.cc index 185c18e..a7f47cb 100644 --- a/chrome/browser/policy/configuration_policy_provider_delegate_win.cc +++ b/chrome/browser/policy/configuration_policy_provider_delegate_win.cc @@ -46,14 +46,13 @@ bool ReadRegistryStringValue(RegKey* key, const string16& name, namespace policy { ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin( - const ConfigurationPolicyProvider::PolicyDefinitionList* - policy_definition_list) + const PolicyDefinitionList* policy_definition_list) : policy_definition_list_(policy_definition_list) { } DictionaryValue* ConfigurationPolicyProviderDelegateWin::Load() { DictionaryValue* result = new DictionaryValue(); - const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* current; + const PolicyDefinitionList::Entry* current; for (current = policy_definition_list_->begin; current != policy_definition_list_->end; ++current) { diff --git a/chrome/browser/policy/configuration_policy_provider_delegate_win.h b/chrome/browser/policy/configuration_policy_provider_delegate_win.h index ac00cca9..2685591 100644 --- a/chrome/browser/policy/configuration_policy_provider_delegate_win.h +++ b/chrome/browser/policy/configuration_policy_provider_delegate_win.h @@ -14,8 +14,7 @@ class ConfigurationPolicyProviderDelegateWin : public AsynchronousPolicyProvider::Delegate { public: explicit ConfigurationPolicyProviderDelegateWin( - const ConfigurationPolicyProvider::PolicyDefinitionList* - policy_definition_list); + const PolicyDefinitionList* policy_definition_list); virtual ~ConfigurationPolicyProviderDelegateWin() {} // AsynchronousPolicyProvider::Delegate overrides: @@ -36,8 +35,7 @@ class ConfigurationPolicyProviderDelegateWin bool GetRegistryPolicyInteger(const string16& value_name, uint32* result) const; - const ConfigurationPolicyProvider::PolicyDefinitionList* - policy_definition_list_; + const PolicyDefinitionList* policy_definition_list_; DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderDelegateWin); }; diff --git a/chrome/browser/policy/configuration_policy_provider_mac.cc b/chrome/browser/policy/configuration_policy_provider_mac.cc index b7e12aa..3964c61 100644 --- a/chrome/browser/policy/configuration_policy_provider_mac.cc +++ b/chrome/browser/policy/configuration_policy_provider_mac.cc @@ -12,6 +12,7 @@ #include "base/sys_string_conversions.h" #include "chrome/browser/preferences_mac.h" #include "chrome/common/chrome_paths.h" +#include "policy/policy_constants.h" namespace policy { @@ -42,7 +43,7 @@ FilePath GetManagedPolicyPath() { MacPreferencesPolicyProviderDelegate::MacPreferencesPolicyProviderDelegate( MacPreferences* preferences, - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list) + const PolicyDefinitionList* policy_list) : FileBasedPolicyProvider::ProviderDelegate(GetManagedPolicyPath()), policy_list_(policy_list), preferences_(preferences) { @@ -54,7 +55,7 @@ DictionaryValue* MacPreferencesPolicyProviderDelegate::Load() { preferences_->AppSynchronize(kCFPreferencesCurrentApplication); DictionaryValue* policy = new DictionaryValue; - const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* current; + const PolicyDefinitionList::Entry* current; for (current = policy_list_->begin; current != policy_list_->end; ++current) { base::mac::ScopedCFTypeRef<CFStringRef> name( base::SysUTF8ToCFStringRef(current->name)); @@ -129,14 +130,14 @@ base::Time MacPreferencesPolicyProviderDelegate::GetLastModification() { } ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list) + const PolicyDefinitionList* policy_list) : FileBasedPolicyProvider(policy_list, new MacPreferencesPolicyProviderDelegate(new MacPreferences, policy_list)) { } ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, + const PolicyDefinitionList* policy_list, MacPreferences* preferences) : FileBasedPolicyProvider(policy_list, new MacPreferencesPolicyProviderDelegate(preferences, diff --git a/chrome/browser/policy/configuration_policy_provider_mac.h b/chrome/browser/policy/configuration_policy_provider_mac.h index 531335f..95f737b 100644 --- a/chrome/browser/policy/configuration_policy_provider_mac.h +++ b/chrome/browser/policy/configuration_policy_provider_mac.h @@ -20,7 +20,7 @@ class MacPreferencesPolicyProviderDelegate // Takes ownership of |preferences|. MacPreferencesPolicyProviderDelegate( MacPreferences* preferences, - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list); + const PolicyDefinitionList* policy_list); virtual ~MacPreferencesPolicyProviderDelegate(); // FileBasedPolicyLoader::Delegate implementation. @@ -33,7 +33,7 @@ class MacPreferencesPolicyProviderDelegate // Unfortunately, we cannot get the policy list at load time from the // provider, because the loader may outlive the provider, so we store our own // pointer to the list. - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list_; + const PolicyDefinitionList* policy_list_; scoped_ptr<MacPreferences> preferences_; @@ -45,11 +45,10 @@ class MacPreferencesPolicyProviderDelegate class ConfigurationPolicyProviderMac : public FileBasedPolicyProvider { public: explicit ConfigurationPolicyProviderMac( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list); + const PolicyDefinitionList* policy_list); // For testing; takes ownership of |preferences|. - ConfigurationPolicyProviderMac( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, - MacPreferences* preferences); + ConfigurationPolicyProviderMac(const PolicyDefinitionList* policy_list, + MacPreferences* preferences); DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderMac); }; diff --git a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc index 6583355..f1dfe82 100644 --- a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc +++ b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc @@ -140,7 +140,7 @@ class ConfigurationPolicyProviderMacTest TEST_P(ConfigurationPolicyProviderMacTest, Default) { ConfigurationPolicyProviderMac provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); + GetChromePolicyDefinitionList(), prefs_); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_TRUE(policy_map.empty()); @@ -155,7 +155,7 @@ TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { // Create the provider and have it read |prefs_|. ConfigurationPolicyProviderMac provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); + GetChromePolicyDefinitionList(), prefs_); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_TRUE(policy_map.empty()); @@ -171,7 +171,7 @@ TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { // Create the provider and have it read |prefs_|. ConfigurationPolicyProviderMac provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); + GetChromePolicyDefinitionList(), prefs_); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); EXPECT_TRUE(policy_map.empty()); @@ -187,7 +187,7 @@ TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { // Create the provider and have it read |prefs_|. ConfigurationPolicyProviderMac provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); + GetChromePolicyDefinitionList(), prefs_); PolicyMap policy_map; EXPECT_TRUE(provider.Provide(&policy_map)); ASSERT_EQ(1U, policy_map.size()); @@ -196,7 +196,9 @@ TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { EXPECT_TRUE(GetParam().test_value()->Equals(value)); } -// Instantiate the test case for all policies. +// Test parameters for all supported policies. testing::Values() has a limit of +// 50 parameters which is reached in this instantiation; new policies should go +// in the next instantiation after this one. INSTANTIATE_TEST_CASE_P( ConfigurationPolicyProviderMacTestInstance, ConfigurationPolicyProviderMacTest, @@ -306,9 +308,6 @@ INSTANTIATE_TEST_CASE_P( PolicyTestParams::ForBooleanPolicy( kPolicyInstantEnabled, key::kInstantEnabled), - PolicyTestParams::ForIntegerPolicy( - kPolicyPolicyRefreshRate, - key::kPolicyRefreshRate), PolicyTestParams::ForBooleanPolicy( kPolicyDisablePluginFinder, key::kDisablePluginFinder), @@ -350,7 +349,10 @@ INSTANTIATE_TEST_CASE_P( key::kDiskCacheDir), PolicyTestParams::ForIntegerPolicy( kPolicyMaxConnectionsPerProxy, - key::kMaxConnectionsPerProxy))); + key::kMaxConnectionsPerProxy), + PolicyTestParams::ForListPolicy( + kPolicyURLBlacklist, + key::kURLBlacklist))); // testing::Values has a limit of 50 test templates, which is reached by the // instantiations above. Add tests for new policies here: @@ -359,9 +361,6 @@ INSTANTIATE_TEST_CASE_P( ConfigurationPolicyProviderMacTest, testing::Values( PolicyTestParams::ForListPolicy( - kPolicyURLBlacklist, - key::kURLBlacklist), - PolicyTestParams::ForListPolicy( kPolicyURLWhitelist, key::kURLWhitelist))); diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc index 20dd8ba..7c04ffa 100644 --- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc +++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc @@ -193,7 +193,7 @@ void ConfigurationPolicyProviderWinTest::SetUp() { ActivateOverrides(); provider_.reset(new ConfigurationPolicyProviderWin( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList())); + GetChromePolicyDefinitionList())); } void ConfigurationPolicyProviderWinTest::TearDown() { @@ -355,7 +355,9 @@ TEST_P(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { EXPECT_TRUE(value->Equals(GetParam().hklm_value())); } -// Instantiate the test case for all supported policies. +// Test parameters for all supported policies. testing::Values() has a limit of +// 50 parameters which is reached in this instantiation; new policies should go +// in the next instantiation after this one. INSTANTIATE_TEST_CASE_P( ConfigurationPolicyProviderWinTestInstance, ConfigurationPolicyProviderWinTest, @@ -459,9 +461,6 @@ INSTANTIATE_TEST_CASE_P( PolicyTestParams::ForBooleanPolicy( kPolicyPrintingEnabled, key::kPrintingEnabled), - PolicyTestParams::ForIntegerPolicy( - kPolicyPolicyRefreshRate, - key::kPolicyRefreshRate), PolicyTestParams::ForBooleanPolicy( kPolicyInstantEnabled, key::kInstantEnabled), @@ -509,7 +508,10 @@ INSTANTIATE_TEST_CASE_P( key::kDiskCacheDir), PolicyTestParams::ForIntegerPolicy( kPolicyMaxConnectionsPerProxy, - key::kMaxConnectionsPerProxy))); + key::kMaxConnectionsPerProxy), + PolicyTestParams::ForListPolicy( + kPolicyURLBlacklist, + key::kURLBlacklist))); // testing::Values has a limit of 50 test templates, which is reached by the // instantiations above. Add tests for new policies here: @@ -518,9 +520,6 @@ INSTANTIATE_TEST_CASE_P( ConfigurationPolicyProviderWinTest, testing::Values( PolicyTestParams::ForListPolicy( - kPolicyURLBlacklist, - key::kURLBlacklist), - PolicyTestParams::ForListPolicy( kPolicyURLWhitelist, key::kURLWhitelist))); diff --git a/chrome/browser/policy/configuration_policy_reader.cc b/chrome/browser/policy/configuration_policy_reader.cc index 49d957c..1854969 100644 --- a/chrome/browser/policy/configuration_policy_reader.cc +++ b/chrome/browser/policy/configuration_policy_reader.cc @@ -15,6 +15,7 @@ #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/policy_map.h" +#include "policy/policy_constants.h" namespace policy { @@ -34,9 +35,6 @@ class ConfigurationPolicyStatusKeeper { private: typedef std::map<ConfigurationPolicyType, PolicyStatusInfo*> PolicyStatusMap; - typedef std::map<ConfigurationPolicyType, string16> PolicyNameMap; - typedef ConfigurationPolicyProvider::PolicyDefinitionList - PolicyDefinitionList; // Calls Provide() on the passed in |provider| to get policy values. void GetPoliciesFromProvider(ConfigurationPolicyProvider* provider); @@ -78,8 +76,7 @@ void ConfigurationPolicyStatusKeeper::GetPoliciesFromProvider( PolicyMap::const_iterator policy = policies->begin(); for ( ; policy != policies->end(); ++policy) { - string16 name = PolicyStatus::GetPolicyName(policy->first); - DCHECK(!name.empty()); + string16 name = ASCIIToUTF16(GetPolicyName(policy->first)); // TODO(simo) actually determine whether the policy is a user or a device // one and whether the policy could be enforced or not once this information @@ -221,7 +218,7 @@ ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_set) const { *any_policies_set = false; const PolicyDefinitionList* supported_policies = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + GetChromePolicyDefinitionList(); const PolicyDefinitionList::Entry* policy = supported_policies->begin; for ( ; policy != supported_policies->end; ++policy) { if (!AddPolicyFromReaders(policy->policy_type, result)) { @@ -245,32 +242,6 @@ ListValue* PolicyStatus::GetPolicyStatusList(bool* any_policies_set) const { return result; } -// static -string16 PolicyStatus::GetPolicyName(ConfigurationPolicyType policy_type) { - static std::map<ConfigurationPolicyType, string16> name_map; - static const ConfigurationPolicyProvider::PolicyDefinitionList* - supported_policies = NULL; - - if (!supported_policies) { - supported_policies = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); - - // Create mapping from ConfigurationPolicyTypes to actual policy names. - const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* entry = - supported_policies->begin; - for ( ; entry != supported_policies->end; ++entry) - name_map[entry->policy_type] = ASCIIToUTF16(entry->name); - } - - std::map<ConfigurationPolicyType, string16>::const_iterator entry = - name_map.find(policy_type); - - if (entry == name_map.end()) - return string16(); - - return entry->second; -} - bool PolicyStatus::AddPolicyFromReaders( ConfigurationPolicyType policy, ListValue* list) const { DictionaryValue* mp_policy = diff --git a/chrome/browser/policy/configuration_policy_reader.h b/chrome/browser/policy/configuration_policy_reader.h index 80d9cea..dcd36bb 100644 --- a/chrome/browser/policy/configuration_policy_reader.h +++ b/chrome/browser/policy/configuration_policy_reader.h @@ -116,15 +116,7 @@ class PolicyStatus { // it is set to false. This is for the about:policy UI to display. ListValue* GetPolicyStatusList(bool* any_policies_set) const; - // Returns a string16 containing the actual name of the policy corresponding - // to |policy_type|. Returns an empty string if there is no such policy_type - // among the policies supported by the client. - static string16 GetPolicyName(ConfigurationPolicyType policy_type); - private: - typedef ConfigurationPolicyProvider::PolicyDefinitionList - PolicyDefinitionList; - // Add the policy information for |policy| to the ListValue pointed to be // |list| as it is returned by the different ConfigurationPolicyReader // objects. Returns true if a policy was added and false otherwise. diff --git a/chrome/browser/policy/configuration_policy_reader_unittest.cc b/chrome/browser/policy/configuration_policy_reader_unittest.cc index dc76a92..670c0b5 100644 --- a/chrome/browser/policy/configuration_policy_reader_unittest.cc +++ b/chrome/browser/policy/configuration_policy_reader_unittest.cc @@ -148,9 +148,6 @@ TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { class PolicyStatusTest : public testing::Test { protected: - typedef ConfigurationPolicyProvider::PolicyDefinitionList - PolicyDefinitionList; - PolicyStatusTest() { managed_platform_ = new MockConfigurationPolicyReader(); managed_cloud_ = new MockConfigurationPolicyReader(); @@ -163,8 +160,7 @@ class PolicyStatusTest : public testing::Test { recommended_cloud_)); status_ok_ = ASCIIToUTF16("ok"); - policy_list_ = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); + policy_list_ = GetChromePolicyDefinitionList(); policy_list_size_ = static_cast<size_t>(policy_list_->end - policy_list_->begin); } @@ -347,12 +343,4 @@ TEST_F(PolicyStatusTest, GetPolicyStatusListSetPolicies) { } } -TEST_F(PolicyStatusTest, GetPolicyName) { - for (const PolicyDefinitionList::Entry* entry = policy_list_->begin; - entry != policy_list_->end; ++entry) { - EXPECT_EQ(ASCIIToUTF16(entry->name), - PolicyStatus::GetPolicyName(entry->policy_type)); - } -} - } // namespace policy diff --git a/chrome/browser/policy/file_based_policy_provider.cc b/chrome/browser/policy/file_based_policy_provider.cc index 488f19f..09bdcd7 100644 --- a/chrome/browser/policy/file_based_policy_provider.cc +++ b/chrome/browser/policy/file_based_policy_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,7 +15,7 @@ FileBasedPolicyProvider::ProviderDelegate::ProviderDelegate( FileBasedPolicyProvider::ProviderDelegate::~ProviderDelegate() {} FileBasedPolicyProvider::FileBasedPolicyProvider( - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, + const PolicyDefinitionList* policy_list, FileBasedPolicyProvider::ProviderDelegate* delegate) : AsynchronousPolicyProvider( policy_list, diff --git a/chrome/browser/policy/file_based_policy_provider_unittest.cc b/chrome/browser/policy/file_based_policy_provider_unittest.cc index 45ef9fe..a6537d2 100644 --- a/chrome/browser/policy/file_based_policy_provider_unittest.cc +++ b/chrome/browser/policy/file_based_policy_provider_unittest.cc @@ -41,9 +41,8 @@ TEST_F(AsynchronousPolicyTestBase, ProviderInit) { // when the file watcher is initialized, since this file may have changed // between the initial load and creating watcher. EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return(policies)); - FileBasedPolicyProvider provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - provider_delegate); + FileBasedPolicyProvider provider(GetChromePolicyDefinitionList(), + provider_delegate); loop_.RunAllPending(); PolicyMap policy_map; provider.Provide(&policy_map); @@ -60,9 +59,8 @@ TEST_F(AsynchronousPolicyTestBase, ProviderRefresh) { InSequence s; EXPECT_CALL(*provider_delegate, Load()).WillOnce(Return( new DictionaryValue)); - FileBasedPolicyProvider file_based_provider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), - provider_delegate); + FileBasedPolicyProvider file_based_provider(GetChromePolicyDefinitionList(), + provider_delegate); // A second call to Load gets triggered during the provider's construction // when the file watcher is initialized, since this file may have changed // between the initial load and creating watcher. diff --git a/chrome/browser/policy/mock_configuration_policy_provider.cc b/chrome/browser/policy/mock_configuration_policy_provider.cc index d36a00d..eeee46f 100644 --- a/chrome/browser/policy/mock_configuration_policy_provider.cc +++ b/chrome/browser/policy/mock_configuration_policy_provider.cc @@ -5,12 +5,12 @@ #include "chrome/browser/policy/mock_configuration_policy_provider.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "policy/policy_constants.h" namespace policy { MockConfigurationPolicyProvider::MockConfigurationPolicyProvider() - : ConfigurationPolicyProvider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()), + : ConfigurationPolicyProvider(GetChromePolicyDefinitionList()), initialization_complete_(false) { } diff --git a/chrome/browser/policy/policy_map.cc b/chrome/browser/policy/policy_map.cc index a9c16d9..e923701 100644 --- a/chrome/browser/policy/policy_map.cc +++ b/chrome/browser/policy/policy_map.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "base/stl_util.h" +#include "policy/policy_constants.h" namespace policy { @@ -48,8 +49,8 @@ void PolicyMap::CopyFrom(const PolicyMap& other) { void PolicyMap::LoadFrom( const DictionaryValue* policies, - const ConfigurationPolicyProvider::PolicyDefinitionList* list) { - const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* entry; + const PolicyDefinitionList* list) { + const PolicyDefinitionList::Entry* entry; for (entry = list->begin; entry != list->end; ++entry) { Value* value; if (policies->Get(entry->name, &value) && value->IsType(entry->value_type)) diff --git a/chrome/browser/policy/policy_map.h b/chrome/browser/policy/policy_map.h index 765d0fa..02ee163 100644 --- a/chrome/browser/policy/policy_map.h +++ b/chrome/browser/policy/policy_map.h @@ -8,11 +8,12 @@ #include <map> #include "base/values.h" -#include "chrome/browser/policy/configuration_policy_provider.h" #include "policy/configuration_policy_type.h" namespace policy { +struct PolicyDefinitionList; + // Wrapper class around a std::map<ConfigurationPolicyType, Value*> that // properly cleans up after itself when going out of scope. // Exposes interesting methods of the underlying std::map. @@ -41,7 +42,7 @@ class PolicyMap { // corresponding policy type. The policies to load, and their types, are // listed in |list|. void LoadFrom(const DictionaryValue* policies, - const ConfigurationPolicyProvider::PolicyDefinitionList* list); + const PolicyDefinitionList* list); bool Equals(const PolicyMap& other) const; bool empty() const; diff --git a/chrome/browser/policy/user_policy_cache.cc b/chrome/browser/policy/user_policy_cache.cc index b0d92cf..3cf8da5 100644 --- a/chrome/browser/policy/user_policy_cache.cc +++ b/chrome/browser/policy/user_policy_cache.cc @@ -18,6 +18,7 @@ #include "chrome/browser/policy/proto/device_management_local.pb.h" #include "chrome/browser/policy/proto/old_generic_format.pb.h" #include "policy/configuration_policy_type.h" +#include "policy/policy_constants.h" namespace policy { @@ -139,9 +140,7 @@ void UserPolicyCache::MaybeDecodeOldstylePolicy( result.Set(named_value->name(), decoded_value); } } - mandatory->LoadFrom( - &result, - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()); + mandatory->LoadFrom(&result, GetChromePolicyDefinitionList()); } Value* UserPolicyCache::DecodeIntegerValue( diff --git a/chrome/tools/build/generate_policy_source.py b/chrome/tools/build/generate_policy_source.py index f4eef86..9523439 100644 --- a/chrome/tools/build/generate_policy_source.py +++ b/chrome/tools/build/generate_policy_source.py @@ -17,6 +17,15 @@ import sys; CHROME_SUBKEY = 'SOFTWARE\\\\Policies\\\\Google\\\\Chrome'; CHROMIUM_SUBKEY = 'SOFTWARE\\\\Policies\\\\Chromium'; +TYPE_MAP = { + 'int': 'TYPE_INTEGER', + 'int-enum': 'TYPE_INTEGER', + 'list': 'TYPE_LIST', + 'main': 'TYPE_BOOLEAN', + 'string': 'TYPE_STRING', + 'string-enum': 'TYPE_STRING', +} + def main(): parser = OptionParser(usage=__doc__); @@ -64,16 +73,48 @@ def _OutputGeneratedWarningForC(f, template_file_path): '//\n\n') -def _GetPolicyNameList(template_file_contents): - policy_names = []; +# Returns a tuple with details about the given policy: +# (name, type, list_of_platforms, is_device_policy) +def _GetPolicyDetails(policy): + if not TYPE_MAP.has_key(policy['type']): + print "Unknown policy type for %s: %s" % (policy['name'], policy['type']) + sys.exit(3) + # platforms is a list of "chrome", "chrome_os" and/or "chrome_frame". + platforms = [ x.split('.')[0].split(':')[0] for x in policy['supported_on'] ] + is_device_policy = policy.get('device_only', False) + return (policy['name'], TYPE_MAP[policy['type']], platforms, is_device_policy) + + +def _GetPolicyList(template_file_contents): + policies = []; for policy in template_file_contents['policy_definitions']: if policy['type'] == 'group': for sub_policy in policy['policies']: - policy_names.append(sub_policy['name']) + policies.append(_GetPolicyDetails(sub_policy)) else: - policy_names.append(policy['name']) - policy_names.sort() - return policy_names + policies.append(_GetPolicyDetails(policy)) + # Tuples are sorted in lexicographical order, which will sort by policy name + # in this case. + policies.sort() + return policies + + +def _GetPolicyNameList(template_file_contents): + return [name for (name, _, _, _) in _GetPolicyList(template_file_contents)] + + +def _GetChromePolicyList(template_file_contents): + return [(name, vtype) for (name, vtype, platforms, is_device_only) + in _GetPolicyList(template_file_contents) + if 'chrome' in platforms and not is_device_only] + + +def _GetChromeOSPolicyList(template_file_contents): + return [(name, vtype) for (name, vtype, platforms, is_device_only) + in _GetPolicyList(template_file_contents) + if 'chrome_os' in platforms + and not 'chrome' in platforms + and not is_device_only] def _LoadJSONFile(json_file): @@ -87,20 +128,43 @@ def _WritePolicyConstantHeader(template_file_contents, args, opts): platform = args[0]; with open(opts.header_path, "w") as f: _OutputGeneratedWarningForC(f, args[1]) + f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' '#pragma once\n' '\n' + '#include "base/values.h"\n' + '#include "policy/configuration_policy_type.h"\n' + '\n' 'namespace policy {\n\n') + if platform == "win": f.write('// The windows registry path where policy configuration ' - 'resides.\nextern const wchar_t kRegistrySubKey[];\n\n') + 'resides.\n' + 'extern const wchar_t kRegistrySubKey[];\n\n') + + f.write('// Lists policy types mapped to their names and expected types.\n' + '// Used to initialize ConfigurationPolicyProviders.\n' + 'struct PolicyDefinitionList {\n' + ' struct Entry {\n' + ' ConfigurationPolicyType policy_type;\n' + ' base::Value::Type value_type;\n' + ' const char* name;\n' + ' };\n' + '\n' + ' const Entry* begin;\n' + ' const Entry* end;\n' + '};\n' + '\n' + '// Gets the policy name for the given policy type.\n' + 'const char* GetPolicyName(ConfigurationPolicyType type);\n' + '\n' + '// Returns the default policy definition list for Chrome.\n' + 'const PolicyDefinitionList* GetChromePolicyDefinitionList();\n\n') f.write('// Key names for the policy settings.\n' 'namespace key {\n\n') for policy_name in _GetPolicyNameList(template_file_contents): f.write('extern const char k' + policy_name + '[];\n') - f.write('\n// Only used in testing.' - '\nextern const char* kMapPolicyString[];\n') f.write('\n} // namespace key\n\n' '} // namespace policy\n\n' '#endif // CHROME_COMMON_POLICY_CONSTANTS_H_\n') @@ -111,10 +175,37 @@ def _WritePolicyConstantSource(template_file_contents, args, opts): platform = args[0]; with open(opts.source_path, "w") as f: _OutputGeneratedWarningForC(f, args[1]) - f.write('#include "policy/policy_constants.h"\n' + + f.write('#include "base/basictypes.h"\n' + '#include "base/logging.h"\n' + '#include "policy/policy_constants.h"\n' '\n' - 'namespace policy {\n' - '\n') + 'namespace policy {\n\n') + + f.write('namespace {\n\n') + + f.write('PolicyDefinitionList::Entry entries[] = {\n') + for (name, vtype) in _GetChromePolicyList(template_file_contents): + f.write(' { kPolicy%s, Value::%s, key::k%s },\n' % (name, vtype, name)) + f.write('\n#if defined(OS_CHROMEOS)\n') + for (name, vtype) in _GetChromeOSPolicyList(template_file_contents): + f.write(' { kPolicy%s, Value::%s, key::k%s },\n' % (name, vtype, name)) + f.write('#endif\n' + '};\n\n') + + f.write('PolicyDefinitionList chrome_policy_list = {\n' + ' entries,\n' + ' entries + arraysize(entries),\n' + '};\n\n') + + f.write('// Maps a policy-type enum value to the policy name.\n' + 'const char* policy_name_map[] = {\n'); + for name in _GetPolicyNameList(template_file_contents): + f.write(' key::k%s,\n' % name) + f.write('};\n\n') + + f.write('} // namespace\n\n') + if platform == "win": f.write('#if defined(GOOGLE_CHROME_BUILD)\n' 'const wchar_t kRegistrySubKey[] = ' @@ -123,14 +214,20 @@ def _WritePolicyConstantSource(template_file_contents, args, opts): 'const wchar_t kRegistrySubKey[] = ' 'L"' + CHROMIUM_SUBKEY + '";\n' '#endif\n\n') + + f.write('const char* GetPolicyName(ConfigurationPolicyType type) {\n' + ' CHECK(type >= 0 && ' + 'static_cast<size_t>(type) < arraysize(policy_name_map));\n' + ' return policy_name_map[type];\n' + '}\n' + '\n' + 'const PolicyDefinitionList* GetChromePolicyDefinitionList() {\n' + ' return &chrome_policy_list;\n' + '}\n\n') + f.write('namespace key {\n\n') for policy_name in _GetPolicyNameList(template_file_contents): f.write('const char k%s[] = "%s";\n' % (policy_name, policy_name)) - f.write('\n// Only used in testing.' - '\nconst char* kMapPolicyString[] = {\n ') - for policy_name in _GetPolicyNameList(template_file_contents): - f.write('\n "%s",' % policy_name) - f.write('\n};\n') f.write('\n} // namespace key\n\n' '} // namespace policy\n') |