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_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
15 #include "chrome/browser/policy/chrome_browser_policy_connector.h"
16 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
18 class PrefRegistrySimple
;
22 class URLRequestContextGetter
;
27 class AffiliatedInvalidationServiceProvider
;
28 class ConsumerManagementService
;
29 class DeviceCloudPolicyInitializer
;
30 class AffiliatedCloudPolicyInvalidator
;
31 class DeviceLocalAccountPolicyService
;
32 class DeviceManagementService
;
33 struct EnrollmentConfig
;
34 class EnterpriseInstallAttributes
;
35 class NetworkConfigurationUpdater
;
36 class ProxyPolicyProvider
;
37 class ServerBackedStateKeysBroker
;
39 // Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS.
40 class BrowserPolicyConnectorChromeOS
41 : public ChromeBrowserPolicyConnector
,
42 public DeviceCloudPolicyManagerChromeOS::Observer
{
44 BrowserPolicyConnectorChromeOS();
46 ~BrowserPolicyConnectorChromeOS() override
;
49 PrefService
* local_state
,
50 scoped_refptr
<net::URLRequestContextGetter
> request_context
) override
;
52 // Shutdown() is called from BrowserProcessImpl::StartTearDown() but |this|
53 // observes some objects that get destroyed earlier. PreShutdown() is called
54 // from ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun(), allowing the
55 // connection to these dependencies to be severed earlier.
58 void Shutdown() override
;
60 // Returns true if this device is managed by an enterprise (as opposed to
62 bool IsEnterpriseManaged();
64 // Returns the enterprise domain if device is managed.
65 std::string
GetEnterpriseDomain();
67 // Returns the device mode. For ChromeOS this function will return the mode
68 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
69 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
70 // For other OSes the function will always return DEVICE_MODE_CONSUMER.
71 DeviceMode
GetDeviceMode();
73 // Get the enrollment configuration for the device as decided by various
74 // factors. See DeviceCloudPolicyInitializer::GetPrescribedEnrollmentConfig()
76 EnrollmentConfig
GetPrescribedEnrollmentConfig() const;
78 // Works out the user affiliation by checking the given |user_name| against
79 // the installation attributes.
80 UserAffiliation
GetUserAffiliation(const std::string
& user_name
);
82 DeviceCloudPolicyManagerChromeOS
* GetDeviceCloudPolicyManager() {
83 return device_cloud_policy_manager_
;
86 DeviceCloudPolicyInitializer
* GetDeviceCloudPolicyInitializer() {
87 return device_cloud_policy_initializer_
.get();
90 DeviceLocalAccountPolicyService
* GetDeviceLocalAccountPolicyService() {
91 return device_local_account_policy_service_
.get();
94 EnterpriseInstallAttributes
* GetInstallAttributes() {
95 return install_attributes_
.get();
98 ServerBackedStateKeysBroker
* GetStateKeysBroker() {
99 return state_keys_broker_
.get();
102 // The browser-global PolicyService is created before Profiles are ready, to
103 // provide managed values for the local state PrefService. It includes a
104 // policy provider that forwards policies from a delegate policy provider.
105 // This call can be used to set the user policy provider as that delegate
106 // once the Profile is ready, so that user policies can also affect local
107 // state preferences.
108 // Only one user policy provider can be set as a delegate at a time, and any
109 // previously set delegate is removed. Passing NULL removes the current
110 // delegate, if there is one.
111 void SetUserPolicyDelegate(ConfigurationPolicyProvider
* user_policy_provider
);
113 ConsumerManagementService
* GetConsumerManagementService() const {
114 return consumer_management_service_
.get();
117 DeviceManagementService
* GetDeviceManagementServiceForConsumer() const {
118 return consumer_device_management_service_
.get();
121 // Sets the consumer management service for testing.
122 void SetConsumerManagementServiceForTesting(
123 scoped_ptr
<ConsumerManagementService
> service
);
125 // Sets the device cloud policy initializer for testing.
126 void SetDeviceCloudPolicyInitializerForTesting(
127 scoped_ptr
<DeviceCloudPolicyInitializer
> initializer
);
129 // Sets the install attributes for testing. Must be called before the browser
130 // is created. RemoveInstallAttributesForTesting must be called after the test
131 // to free the attributes.
132 static void SetInstallAttributesForTesting(
133 EnterpriseInstallAttributes
* attributes
);
134 static void RemoveInstallAttributesForTesting();
136 // Registers device refresh rate pref.
137 static void RegisterPrefs(PrefRegistrySimple
* registry
);
139 // DeviceCloudPolicyManagerChromeOS::Observer:
140 void OnDeviceCloudPolicyManagerConnected() override
;
141 void OnDeviceCloudPolicyManagerDisconnected() override
;
144 // Set the timezone as soon as the policies are available.
145 void SetTimezoneIfPolicyAvailable();
147 // Restarts the device cloud policy initializer, because the device's
148 // registration status changed from registered to unregistered.
149 void RestartDeviceCloudPolicyInitializer();
151 // Components of the device cloud policy implementation.
152 scoped_ptr
<ServerBackedStateKeysBroker
> state_keys_broker_
;
153 scoped_ptr
<EnterpriseInstallAttributes
> install_attributes_
;
154 scoped_ptr
<AffiliatedInvalidationServiceProvider
>
155 affiliated_invalidation_service_provider_
;
156 scoped_ptr
<ConsumerManagementService
> consumer_management_service_
;
157 DeviceCloudPolicyManagerChromeOS
* device_cloud_policy_manager_
;
158 PrefService
* local_state_
;
159 scoped_ptr
<DeviceManagementService
> consumer_device_management_service_
;
160 scoped_ptr
<DeviceCloudPolicyInitializer
> device_cloud_policy_initializer_
;
161 scoped_ptr
<DeviceLocalAccountPolicyService
>
162 device_local_account_policy_service_
;
163 scoped_ptr
<AffiliatedCloudPolicyInvalidator
> device_cloud_policy_invalidator_
;
165 // This policy provider is used on Chrome OS to feed user policy into the
166 // global PolicyService instance. This works by installing the cloud policy
167 // provider of the primary profile as the delegate of the ProxyPolicyProvider,
169 // The provider is owned by the base class; this field is just a typed weak
170 // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate().
171 ProxyPolicyProvider
* global_user_cloud_policy_provider_
;
173 scoped_ptr
<NetworkConfigurationUpdater
> network_configuration_updater_
;
175 base::WeakPtrFactory
<BrowserPolicyConnectorChromeOS
> weak_ptr_factory_
;
177 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS
);
180 } // namespace policy
182 #endif // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_