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/policy/chrome_browser_policy_connector.h"
15 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
17 class PrefRegistrySimple;
21 class URLRequestContextGetter;
27 class DeviceCloudPolicyManagerChromeOS;
28 class DeviceLocalAccountPolicyService;
29 class DeviceManagementService;
30 class EnterpriseInstallAttributes;
31 class NetworkConfigurationUpdater;
32 class ProxyPolicyProvider;
33 class ServerBackedStateKeysBroker;
35 // Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS.
36 class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector {
38 BrowserPolicyConnectorChromeOS();
40 virtual ~BrowserPolicyConnectorChromeOS();
43 PrefService* local_state,
44 scoped_refptr<net::URLRequestContextGetter> request_context) OVERRIDE;
46 virtual void Shutdown() OVERRIDE;
48 // Returns true if this device is managed by an enterprise (as opposed to
50 bool IsEnterpriseManaged();
52 // Returns the enterprise domain if device is managed.
53 std::string GetEnterpriseDomain();
55 // Returns the device mode. For ChromeOS this function will return the mode
56 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
57 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
58 // For other OSes the function will always return DEVICE_MODE_CONSUMER.
59 DeviceMode GetDeviceMode();
61 // Works out the user affiliation by checking the given |user_name| against
62 // the installation attributes.
63 UserAffiliation GetUserAffiliation(const std::string& user_name);
65 AppPackUpdater* GetAppPackUpdater();
67 DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() {
68 return device_cloud_policy_manager_;
71 DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() {
72 return device_local_account_policy_service_.get();
75 EnterpriseInstallAttributes* GetInstallAttributes() {
76 return install_attributes_.get();
79 ServerBackedStateKeysBroker* GetStateKeysBroker() {
80 return state_keys_broker_.get();
83 // The browser-global PolicyService is created before Profiles are ready, to
84 // provide managed values for the local state PrefService. It includes a
85 // policy provider that forwards policies from a delegate policy provider.
86 // This call can be used to set the user policy provider as that delegate
87 // once the Profile is ready, so that user policies can also affect local
89 // Only one user policy provider can be set as a delegate at a time, and any
90 // previously set delegate is removed. Passing NULL removes the current
91 // delegate, if there is one.
92 void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider);
94 // Returns the device management service for consumer management.
95 DeviceManagementService* consumer_device_management_service() const {
96 return consumer_device_management_service_.get();
99 // Sets the install attributes for testing. Must be called before the browser
100 // is created. RemoveInstallAttributesForTesting must be called after the test
101 // to free the attributes.
102 static void SetInstallAttributesForTesting(
103 EnterpriseInstallAttributes* attributes);
104 static void RemoveInstallAttributesForTesting();
106 // Registers device refresh rate pref.
107 static void RegisterPrefs(PrefRegistrySimple* registry);
110 // Set the timezone as soon as the policies are available.
111 void SetTimezoneIfPolicyAvailable();
113 // Components of the device cloud policy implementation.
114 scoped_ptr<ServerBackedStateKeysBroker> state_keys_broker_;
115 scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
116 DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager_;
117 scoped_ptr<DeviceLocalAccountPolicyService>
118 device_local_account_policy_service_;
120 // This policy provider is used on Chrome OS to feed user policy into the
121 // global PolicyService instance. This works by installing the cloud policy
122 // provider of the primary profile as the delegate of the ProxyPolicyProvider,
124 // The provider is owned by the base class; this field is just a typed weak
125 // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate().
126 ProxyPolicyProvider* global_user_cloud_policy_provider_;
128 scoped_ptr<AppPackUpdater> app_pack_updater_;
129 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
131 scoped_ptr<DeviceManagementService> consumer_device_management_service_;
133 base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_;
135 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS);
138 } // namespace policy
140 #endif // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_