1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/login/users/affiliation.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
17 #include "chrome/browser/policy/chrome_browser_policy_connector.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
20 class PrefRegistrySimple
;
24 class URLRequestContextGetter
;
29 class AffiliatedCloudPolicyInvalidator
;
30 class AffiliatedInvalidationServiceProvider
;
31 class AffiliatedRemoteCommandsInvalidator
;
32 class ConsumerManagementService
;
33 class DeviceCloudPolicyInitializer
;
34 class DeviceLocalAccountPolicyService
;
35 class DeviceManagementService
;
36 struct EnrollmentConfig
;
37 class EnterpriseInstallAttributes
;
38 class NetworkConfigurationUpdater
;
39 class ProxyPolicyProvider
;
40 class ServerBackedStateKeysBroker
;
42 // Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS.
43 class BrowserPolicyConnectorChromeOS
44 : public ChromeBrowserPolicyConnector
,
45 public DeviceCloudPolicyManagerChromeOS::Observer
{
47 BrowserPolicyConnectorChromeOS();
49 ~BrowserPolicyConnectorChromeOS() override
;
52 PrefService
* local_state
,
53 scoped_refptr
<net::URLRequestContextGetter
> request_context
) override
;
55 // Shutdown() is called from BrowserProcessImpl::StartTearDown() but |this|
56 // observes some objects that get destroyed earlier. PreShutdown() is called
57 // from ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun(), allowing the
58 // connection to these dependencies to be severed earlier.
61 void Shutdown() override
;
63 // Returns true if this device is managed by an enterprise (as opposed to
65 bool IsEnterpriseManaged();
67 // Returns the enterprise domain if device is managed.
68 std::string
GetEnterpriseDomain() const;
70 // Returns the device asset ID if it is set.
71 std::string
GetDeviceAssetID();
73 // Returns the cloud directory API ID or an empty string if it is not set.
74 std::string
GetDirectoryApiID();
76 // Returns the device mode. For ChromeOS this function will return the mode
77 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
78 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
79 // For other OSes the function will always return DEVICE_MODE_CONSUMER.
80 DeviceMode
GetDeviceMode();
82 // Get the enrollment configuration for the device as decided by various
83 // factors. See DeviceCloudPolicyInitializer::GetPrescribedEnrollmentConfig()
85 EnrollmentConfig
GetPrescribedEnrollmentConfig() const;
87 // Works out the user affiliation by checking the given |user_name| against
88 // the installation attributes.
89 UserAffiliation
GetUserAffiliation(const std::string
& user_name
);
91 DeviceCloudPolicyManagerChromeOS
* GetDeviceCloudPolicyManager() {
92 return device_cloud_policy_manager_
;
95 DeviceCloudPolicyInitializer
* GetDeviceCloudPolicyInitializer() {
96 return device_cloud_policy_initializer_
.get();
99 DeviceLocalAccountPolicyService
* GetDeviceLocalAccountPolicyService() {
100 return device_local_account_policy_service_
.get();
103 EnterpriseInstallAttributes
* GetInstallAttributes() {
104 return install_attributes_
.get();
107 ServerBackedStateKeysBroker
* GetStateKeysBroker() {
108 return state_keys_broker_
.get();
111 // The browser-global PolicyService is created before Profiles are ready, to
112 // provide managed values for the local state PrefService. It includes a
113 // policy provider that forwards policies from a delegate policy provider.
114 // This call can be used to set the user policy provider as that delegate
115 // once the Profile is ready, so that user policies can also affect local
116 // state preferences.
117 // Only one user policy provider can be set as a delegate at a time, and any
118 // previously set delegate is removed. Passing NULL removes the current
119 // delegate, if there is one.
120 void SetUserPolicyDelegate(ConfigurationPolicyProvider
* user_policy_provider
);
122 ConsumerManagementService
* GetConsumerManagementService() const {
123 return consumer_management_service_
.get();
126 DeviceManagementService
* GetDeviceManagementServiceForConsumer() const {
127 return consumer_device_management_service_
.get();
130 // Sets the consumer management service for testing.
131 void SetConsumerManagementServiceForTesting(
132 scoped_ptr
<ConsumerManagementService
> service
);
134 // Sets the device cloud policy initializer for testing.
135 void SetDeviceCloudPolicyInitializerForTesting(
136 scoped_ptr
<DeviceCloudPolicyInitializer
> initializer
);
138 // Sets the install attributes for testing. Must be called before the browser
139 // is created. RemoveInstallAttributesForTesting must be called after the test
140 // to free the attributes.
141 static void SetInstallAttributesForTesting(
142 EnterpriseInstallAttributes
* attributes
);
143 static void RemoveInstallAttributesForTesting();
145 // Registers device refresh rate pref.
146 static void RegisterPrefs(PrefRegistrySimple
* registry
);
148 // DeviceCloudPolicyManagerChromeOS::Observer:
149 void OnDeviceCloudPolicyManagerConnected() override
;
150 void OnDeviceCloudPolicyManagerDisconnected() override
;
152 chromeos::AffiliationIDSet
GetDeviceAffiliationIDs() const;
155 // Set the timezone as soon as the policies are available.
156 void SetTimezoneIfPolicyAvailable();
158 // Restarts the device cloud policy initializer, because the device's
159 // registration status changed from registered to unregistered.
160 void RestartDeviceCloudPolicyInitializer();
162 // Components of the device cloud policy implementation.
163 scoped_ptr
<ServerBackedStateKeysBroker
> state_keys_broker_
;
164 scoped_ptr
<EnterpriseInstallAttributes
> install_attributes_
;
165 scoped_ptr
<AffiliatedInvalidationServiceProvider
>
166 affiliated_invalidation_service_provider_
;
167 scoped_ptr
<ConsumerManagementService
> consumer_management_service_
;
168 DeviceCloudPolicyManagerChromeOS
* device_cloud_policy_manager_
;
169 PrefService
* local_state_
;
170 scoped_ptr
<DeviceManagementService
> consumer_device_management_service_
;
171 scoped_ptr
<DeviceCloudPolicyInitializer
> device_cloud_policy_initializer_
;
172 scoped_ptr
<DeviceLocalAccountPolicyService
>
173 device_local_account_policy_service_
;
174 scoped_ptr
<AffiliatedCloudPolicyInvalidator
> device_cloud_policy_invalidator_
;
175 scoped_ptr
<AffiliatedRemoteCommandsInvalidator
>
176 device_remote_commands_invalidator_
;
178 // This policy provider is used on Chrome OS to feed user policy into the
179 // global PolicyService instance. This works by installing the cloud policy
180 // provider of the primary profile as the delegate of the ProxyPolicyProvider,
182 // The provider is owned by the base class; this field is just a typed weak
183 // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate().
184 ProxyPolicyProvider
* global_user_cloud_policy_provider_
;
186 scoped_ptr
<NetworkConfigurationUpdater
> network_configuration_updater_
;
188 base::WeakPtrFactory
<BrowserPolicyConnectorChromeOS
> weak_ptr_factory_
;
190 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS
);
193 } // namespace policy
195 #endif // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_