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