Commit 5078a919 authored by merkulova's avatar merkulova Committed by Commit bot

Default values for enterprise users are supported.

BUG=402800

Review URL: https://codereview.chromium.org/519643002

Cr-Commit-Position: refs/heads/master@{#293480}
parent 22dfc401
...@@ -280,25 +280,12 @@ void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { ...@@ -280,25 +280,12 @@ void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() {
void UserCloudPolicyManagerChromeOS::GetChromePolicy(PolicyMap* policy_map) { void UserCloudPolicyManagerChromeOS::GetChromePolicy(PolicyMap* policy_map) {
CloudPolicyManager::GetChromePolicy(policy_map); CloudPolicyManager::GetChromePolicy(policy_map);
// Default multi-profile behavior for managed accounts to primary-only. // If the store has a verified policy blob received from the server then apply
if (store()->has_policy() && // the defaults for policies that haven't been configured by the administrator
!policy_map->Get(key::kChromeOsMultiProfileUserBehavior)) { // given that this is an enterprise user.
policy_map->Set(key::kChromeOsMultiProfileUserBehavior, if (!store()->has_policy())
POLICY_LEVEL_MANDATORY, return;
POLICY_SCOPE_USER, SetEnterpriseUsersDefaults(policy_map);
new base::StringValue("primary-only"),
NULL);
}
// Set EasyUnlockAllowed policy to false by default for managed accounts.
if (store()->has_policy() &&
!policy_map->Get(key::kEasyUnlockAllowed)) {
policy_map->Set(key::kEasyUnlockAllowed,
POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
new base::FundamentalValue(false),
NULL);
}
} }
void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() {
......
...@@ -150,7 +150,7 @@ class UserCloudPolicyManagerChromeOS : public CloudPolicyManager, ...@@ -150,7 +150,7 @@ class UserCloudPolicyManagerChromeOS : public CloudPolicyManager,
// IsInitializationComplete(). // IsInitializationComplete().
bool wait_for_policy_fetch_; bool wait_for_policy_fetch_;
// A timer that puts a hard limit on the maximum time to wait for the intial // A timer that puts a hard limit on the maximum time to wait for the initial
// policy fetch. // policy fetch.
base::Timer policy_fetch_timeout_; base::Timer policy_fetch_timeout_;
......
...@@ -173,4 +173,30 @@ TEST(GeneratePolicySource, PolicyDetails) { ...@@ -173,4 +173,30 @@ TEST(GeneratePolicySource, PolicyDetails) {
// than 0, once a type 'external' policy is added. // than 0, once a type 'external' policy is added.
} }
#if defined(OS_CHROMEOS)
TEST(GeneratePolicySource, SetEnterpriseDefaults) {
PolicyMap policy_map;
// If policy not configured yet, set the enterprise default.
SetEnterpriseUsersDefaults(&policy_map);
const base::Value* multiprof_behavior =
policy_map.GetValue(key::kChromeOsMultiProfileUserBehavior);
base::StringValue expected("primary-only");
EXPECT_TRUE(expected.Equals(multiprof_behavior));
// If policy already configured, it's not changed to enterprise defaults.
policy_map.Set(key::kChromeOsMultiProfileUserBehavior,
POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
new base::StringValue("test_value"),
NULL);
SetEnterpriseUsersDefaults(&policy_map);
multiprof_behavior =
policy_map.GetValue(key::kChromeOsMultiProfileUserBehavior);
expected = base::StringValue("test_value");
EXPECT_TRUE(expected.Equals(multiprof_behavior));
}
#endif
} // namespace policy } // namespace policy
...@@ -134,6 +134,10 @@ ...@@ -134,6 +134,10 @@
# that this policy is only supported as a device-level Cloud Policy. # that this policy is only supported as a device-level Cloud Policy.
# In that case no entry in the UserPolicy Protobuf is generated and # In that case no entry in the UserPolicy Protobuf is generated and
# it is assumed that it will be added to the DevicePolicy Protobuf manually. # it is assumed that it will be added to the DevicePolicy Protobuf manually.
#
# Enterprise defaults:
# An optional key 'default_for_enterprise_users' contains value that's set for
# enterprise users as a default.
# #
'policy_definitions': [ 'policy_definitions': [
{ {
...@@ -3143,6 +3147,7 @@ ...@@ -3143,6 +3147,7 @@
'per_profile': True, 'per_profile': True,
}, },
'example_value': 'unrestricted', 'example_value': 'unrestricted',
'default_for_enterprise_users': 'primary-only',
'id': 244, 'id': 244,
'caption': '''Control the user behavior in a multiprofile session''', 'caption': '''Control the user behavior in a multiprofile session''',
'desc': '''Control the user behavior in a multiprofile session on <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> devices. 'desc': '''Control the user behavior in a multiprofile session on <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> devices.
...@@ -6604,6 +6609,7 @@ ...@@ -6604,6 +6609,7 @@
'per_profile': True, 'per_profile': True,
}, },
'example_value': True, 'example_value': True,
'default_for_enterprise_users': False,
'id': 272, 'id': 272,
'caption': '''Allows EasyUnlock to be used''', 'caption': '''Allows EasyUnlock to be used''',
'desc': '''Allows EasyUnlock to be used on <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> devices. 'desc': '''Allows EasyUnlock to be used on <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> devices.
......
...@@ -57,6 +57,9 @@ class PolicyDetails: ...@@ -57,6 +57,9 @@ class PolicyDetails:
self.is_deprecated = policy.get('deprecated', False) self.is_deprecated = policy.get('deprecated', False)
self.is_device_only = policy.get('device_only', False) self.is_device_only = policy.get('device_only', False)
self.schema = policy.get('schema', {}) self.schema = policy.get('schema', {})
self.has_enterprise_default = 'default_for_enterprise_users' in policy
if self.has_enterprise_default:
self.enterprise_default = policy['default_for_enterprise_users']
expected_platform = 'chrome_os' if is_chromium_os else os.lower() expected_platform = 'chrome_os' if is_chromium_os else os.lower()
self.platforms = [] self.platforms = []
...@@ -216,6 +219,7 @@ def _WritePolicyConstantHeader(policies, os, f): ...@@ -216,6 +219,7 @@ def _WritePolicyConstantHeader(policies, os, f):
'#include "base/basictypes.h"\n' '#include "base/basictypes.h"\n'
'#include "base/values.h"\n' '#include "base/values.h"\n'
'#include "components/policy/core/common/policy_details.h"\n' '#include "components/policy/core/common/policy_details.h"\n'
'#include "components/policy/core/common/policy_map.h"\n'
'\n' '\n'
'namespace policy {\n' 'namespace policy {\n'
'\n' '\n'
...@@ -228,7 +232,12 @@ def _WritePolicyConstantHeader(policies, os, f): ...@@ -228,7 +232,12 @@ def _WritePolicyConstantHeader(policies, os, f):
'configuration resides.\n' 'configuration resides.\n'
'extern const wchar_t kRegistryChromePolicyKey[];\n') 'extern const wchar_t kRegistryChromePolicyKey[];\n')
f.write('// Returns the PolicyDetails for |policy| if |policy| is a known\n' f.write('#if defined (OS_CHROMEOS)\n'
'// Sets default values for enterprise users.\n'
'void SetEnterpriseUsersDefaults(PolicyMap* policy_map);\n'
'#endif\n'
'\n'
'// Returns the PolicyDetails for |policy| if |policy| is a known\n'
'// Chrome policy, otherwise returns NULL.\n' '// Chrome policy, otherwise returns NULL.\n'
'const PolicyDetails* GetChromePolicyDetails(' 'const PolicyDetails* GetChromePolicyDetails('
'const std::string& policy);\n' 'const std::string& policy);\n'
...@@ -630,6 +639,35 @@ def _WritePolicyConstantSource(policies, os, f): ...@@ -630,6 +639,35 @@ def _WritePolicyConstantSource(policies, os, f):
' return &kChromeSchemaData;\n' ' return &kChromeSchemaData;\n'
'}\n\n') '}\n\n')
f.write('#if defined (OS_CHROMEOS)\n'
'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n')
for policy in policies:
if policy.has_enterprise_default:
if policy.policy_type == 'TYPE_BOOLEAN':
creation_expression = 'new base::FundamentalValue(%s)' %\
('true' if policy.enterprise_default else 'false')
elif policy.policy_type == 'TYPE_INTEGER':
creation_expression = 'new base::FundamentalValue(%s)' %\
policy.enterprise_default
elif policy.policy_type == 'TYPE_STRING':
creation_expression = 'new base::StringValue("%s")' %\
policy.enterprise_default
else:
raise RuntimeError('Type %s of policy %s is not supported at '
'enterprise defaults' % (policy.policy_type,
policy.name))
f.write(' if (!policy_map->Get(key::k%s)) {\n'
' policy_map->Set(key::k%s,\n'
' POLICY_LEVEL_MANDATORY,\n'
' POLICY_SCOPE_USER,\n'
' %s,\n'
' NULL);\n'
' }\n' % (policy.name, policy.name, creation_expression))
f.write('}\n'
'#endif\n\n')
f.write('const PolicyDetails* GetChromePolicyDetails(' f.write('const PolicyDetails* GetChromePolicyDetails('
'const std::string& policy) {\n' 'const std::string& policy) {\n'
' // First index in kPropertyNodes of the Chrome policies.\n' ' // First index in kPropertyNodes of the Chrome policies.\n'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment