OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
15 | 16 |
16 namespace user_manager { | 17 namespace user_manager { |
17 class User; | 18 class User; |
18 } | 19 } |
19 | 20 |
20 namespace policy { | 21 namespace policy { |
21 | 22 |
22 class CloudPolicyManager; | 23 class CloudPolicyStore; |
23 class ConfigurationPolicyProvider; | 24 class ConfigurationPolicyProvider; |
24 class PolicyService; | 25 class PolicyService; |
25 class SchemaRegistry; | 26 class SchemaRegistry; |
26 | 27 |
27 // A KeyedService that creates and manages the per-Profile policy | 28 // A KeyedService that creates and manages the per-Profile policy components. |
28 // components. | |
29 class ProfilePolicyConnector : public KeyedService { | 29 class ProfilePolicyConnector : public KeyedService { |
30 public: | 30 public: |
31 ProfilePolicyConnector(); | 31 ProfilePolicyConnector(); |
32 ~ProfilePolicyConnector() override; | 32 ~ProfilePolicyConnector() override; |
33 | 33 |
34 void Init( | 34 // |user| is only used in Chrome OS builds and should be set to nullptr |
35 #if defined(OS_CHROMEOS) | 35 // otherwise. |configuration_policy_provider| and |policy_store| are nullptr |
36 const user_manager::User* user, | 36 // for non-regular users. |
37 #endif | 37 void Init(const user_manager::User* user, |
38 SchemaRegistry* schema_registry, | 38 SchemaRegistry* schema_registry, |
39 CloudPolicyManager* user_cloud_policy_manager); | 39 ConfigurationPolicyProvider* configuration_policy_provider, |
| 40 const CloudPolicyStore* policy_store); |
40 | 41 |
41 void InitForTesting(std::unique_ptr<PolicyService> service); | 42 void InitForTesting(std::unique_ptr<PolicyService> service); |
42 void OverrideIsManagedForTesting(bool is_managed); | 43 void OverrideIsManagedForTesting(bool is_managed); |
43 | 44 |
44 // KeyedService: | 45 // KeyedService: |
45 void Shutdown() override; | 46 void Shutdown() override; |
46 | 47 |
47 // This is never NULL. | 48 // This is never NULL. |
48 PolicyService* policy_service() const { return policy_service_.get(); } | 49 PolicyService* policy_service() const { return policy_service_.get(); } |
49 | 50 |
50 // Returns true if this Profile is under cloud policy management. You must | 51 // Returns true if this Profile is under any kind of policy management. You |
51 // call this method only when the policies system is fully initialized. | 52 // must call this method only when the policies system is fully initialized. |
52 bool IsManaged() const; | 53 bool IsManaged() const; |
53 | 54 |
54 // Returns the cloud policy management domain, if this Profile is under | 55 // Returns the cloud policy management domain or the Active Directory realm |
55 // cloud policy management. Otherwise returns an empty string. You must call | 56 // for managed Profiles or an empty string for unmanaged Profiles. You must |
56 // this method only when the policies system is fully initialized. | 57 // call this method only when the policies system is fully initialized. |
57 std::string GetManagementDomain() const; | 58 std::string GetManagementDomain() const; |
58 | 59 |
59 // Returns true if the |name| Chrome user policy is currently set via the | 60 // Returns true if this Profile is under policy management. Otherwise returns |
60 // CloudPolicyManager and isn't being overridden by a higher-level provider. | 61 // an empty string. You must call this method only when the policies system is |
61 bool IsPolicyFromCloudPolicy(const char* name) const; | 62 // fully initialized. |
| 63 bool IsProfilePolicy(const char* name) const; |
62 | 64 |
63 private: | 65 private: |
| 66 FRIEND_TEST_ALL_PREFIXES(ProfilePolicyConnectorTest, |
| 67 IsManagedForManagedUsers); |
| 68 FRIEND_TEST_ALL_PREFIXES(ProfilePolicyConnectorTest, IsProfilePolicy); |
| 69 |
64 // Find the policy provider that provides the |name| Chrome policy, if any. In | 70 // Find the policy provider that provides the |name| Chrome policy, if any. In |
65 // case of multiple providers sharing the same policy, the one with the | 71 // case of multiple providers sharing the same policy, the one with the |
66 // highest priority will be returned. | 72 // highest priority will be returned. |
67 const ConfigurationPolicyProvider* DeterminePolicyProviderForPolicy( | 73 const ConfigurationPolicyProvider* DeterminePolicyProviderForPolicy( |
68 const char* name) const; | 74 const char* name) const; |
69 | 75 |
70 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
71 // Some of the user policy configuration affects browser global state, and | 77 // Some of the user policy configuration affects browser global state, and |
72 // can only come from one Profile. |is_primary_user_| is true if this | 78 // can only come from one Profile. |is_primary_user_| is true if this |
73 // connector belongs to the first signed-in Profile, and in that case that | 79 // connector belongs to the first signed-in Profile, and in that case that |
74 // Profile's policy is the one that affects global policy settings in | 80 // Profile's policy is the one that affects global policy settings in |
75 // local state. | 81 // local state. |
76 bool is_primary_user_; | 82 bool is_primary_user_ = false; |
77 | 83 |
78 std::unique_ptr<ConfigurationPolicyProvider> special_user_policy_provider_; | 84 std::unique_ptr<ConfigurationPolicyProvider> special_user_policy_provider_; |
79 #endif // defined(OS_CHROMEOS) | 85 #endif // defined(OS_CHROMEOS) |
80 | 86 |
81 std::unique_ptr<ConfigurationPolicyProvider> | 87 std::unique_ptr<ConfigurationPolicyProvider> |
82 wrapped_platform_policy_provider_; | 88 wrapped_platform_policy_provider_; |
83 CloudPolicyManager* user_cloud_policy_manager_; | 89 const ConfigurationPolicyProvider* configuration_policy_provider_ = nullptr; |
| 90 const CloudPolicyStore* policy_store_ = nullptr; |
84 | 91 |
85 // |policy_providers_| contains a list of the policy providers available for | 92 // |policy_providers_| contains a list of the policy providers available for |
86 // the PolicyService of this connector, in decreasing order of priority. | 93 // the PolicyService of this connector, in decreasing order of priority. |
87 // | 94 // |
88 // Note: All the providers appended to this vector must eventually become | 95 // Note: All the providers appended to this vector must eventually become |
89 // initialized for every policy domain, otherwise some subsystems will never | 96 // initialized for every policy domain, otherwise some subsystems will never |
90 // use the policies exposed by the PolicyService! | 97 // use the policies exposed by the PolicyService! |
91 // The default ConfigurationPolicyProvider::IsInitializationComplete() | 98 // The default ConfigurationPolicyProvider::IsInitializationComplete() |
92 // result is true, so take care if a provider overrides that. | 99 // result is true, so take care if a provider overrides that. |
93 std::vector<ConfigurationPolicyProvider*> policy_providers_; | 100 std::vector<ConfigurationPolicyProvider*> policy_providers_; |
94 | 101 |
95 std::unique_ptr<PolicyService> policy_service_; | 102 std::unique_ptr<PolicyService> policy_service_; |
96 std::unique_ptr<bool> is_managed_override_; | 103 std::unique_ptr<bool> is_managed_override_; |
97 | 104 |
98 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector); | 105 DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector); |
99 }; | 106 }; |
100 | 107 |
101 } // namespace policy | 108 } // namespace policy |
102 | 109 |
103 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ | 110 #endif // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_ |
OLD | NEW |