blob: 6f79136cf9752874292753724a583bbe506a3d2c [file] [log] [blame]
[email protected]43dbf8c2012-01-03 14:28:081// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]985655a2011-02-23 09:54:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_
6#define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_
[email protected]985655a2011-02-23 09:54:257
[email protected]6ced4e792011-04-11 10:59:088#include <string>
[email protected]6ced4e792011-04-11 10:59:089
[email protected]985655a2011-02-23 09:54:2510#include "base/basictypes.h"
[email protected]362d694f2013-02-28 09:07:2411#include "base/memory/ref_counted.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/scoped_ptr.h"
[email protected]d203dec2011-10-04 13:18:1613#include "base/memory/weak_ptr.h"
[email protected]b39d25712013-03-14 09:53:4014#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
[email protected]8720d882011-11-05 18:07:4215#include "chrome/browser/policy/configuration_policy_handler_list.h"
[email protected]eb83c392013-11-07 12:53:2416#include "chrome/browser/policy/schema_registry.h"
17#include "components/policy/core/common/schema.h"
[email protected]b39d25712013-03-14 09:53:4018
19#if defined(OS_CHROMEOS)
20#include "chrome/browser/chromeos/policy/proxy_policy_provider.h"
21#endif
[email protected]985655a2011-02-23 09:54:2522
[email protected]b1de2c72013-02-06 02:45:4723class PrefRegistrySimple;
[email protected]362d694f2013-02-28 09:07:2424class PrefService;
[email protected]abe2c032011-03-31 18:49:3425
[email protected]362d694f2013-02-28 09:07:2426namespace net {
[email protected]362d694f2013-02-28 09:07:2427class URLRequestContextGetter;
28}
29
[email protected]985655a2011-02-23 09:54:2530namespace policy {
31
[email protected]985655a2011-02-23 09:54:2532class ConfigurationPolicyProvider;
[email protected]d14c96a2013-01-23 12:15:2733class DeviceManagementService;
34class PolicyService;
35class PolicyStatisticsCollector;
36
37#if defined(OS_CHROMEOS)
38class AppPackUpdater;
[email protected]bd48fee62012-10-23 19:18:2239class DeviceCloudPolicyManagerChromeOS;
[email protected]0f456542012-11-23 16:26:3540class DeviceLocalAccountPolicyService;
[email protected]d14c96a2013-01-23 12:15:2741class EnterpriseInstallAttributes;
[email protected]bfeb6ce2012-09-07 15:02:4142class NetworkConfigurationUpdater;
[email protected]d14c96a2013-01-23 12:15:2743#endif
[email protected]985655a2011-02-23 09:54:2544
45// Manages the lifecycle of browser-global policy infrastructure, such as the
[email protected]fcf53572011-06-29 15:44:3746// platform policy providers, device- and the user-cloud policy infrastructure.
[email protected]d14c96a2013-01-23 12:15:2747class BrowserPolicyConnector {
[email protected]985655a2011-02-23 09:54:2548 public:
[email protected]5fe04582011-11-21 19:25:5749 // Builds an uninitialized BrowserPolicyConnector, suitable for testing.
50 // Init() should be called to create and start the policy machinery.
51 BrowserPolicyConnector();
[email protected]3b19e8e2012-10-17 19:15:4952
53 // Invoke Shutdown() before deleting, see below.
[email protected]fcf53572011-06-29 15:44:3754 virtual ~BrowserPolicyConnector();
[email protected]985655a2011-02-23 09:54:2555
[email protected]362d694f2013-02-28 09:07:2456 // Finalizes the initialization of the connector. This call can be skipped on
57 // tests that don't require the full policy system running.
58 void Init(PrefService* local_state,
[email protected]3ea5bd52013-09-25 13:00:1959 scoped_refptr<net::URLRequestContextGetter> request_context);
[email protected]5fe04582011-11-21 19:25:5760
[email protected]3b19e8e2012-10-17 19:15:4961 // Stops the policy providers and cleans up the connector before it can be
62 // safely deleted. This must be invoked before the destructor and while the
63 // threads are still running. The policy providers are still valid but won't
64 // update anymore after this call.
65 void Shutdown();
66
67 // Returns true if Init() has been called but Shutdown() hasn't been yet.
68 bool is_initialized() const { return is_initialized_; }
69
[email protected]eb83c392013-11-07 12:53:2470 // Returns a handle to the Chrome schema.
71 const Schema& GetChromeSchema() const;
72
73 // Returns the global CombinedSchemaRegistry. SchemaRegistries from Profiles
74 // should be tracked by the global registry, so that the global policy
75 // providers also load policies for the components of each Profile.
76 CombinedSchemaRegistry* GetSchemaRegistry();
77
[email protected]d25da252013-11-14 01:23:4378 // Returns the platform policy provider.
79 ConfigurationPolicyProvider* GetPlatformProvider();
80
[email protected]3b19e8e2012-10-17 19:15:4981 // Returns the browser-global PolicyService, that contains policies for the
82 // whole browser.
83 PolicyService* GetPolicyService();
84
[email protected]fcf53572011-06-29 15:44:3785#if defined(OS_CHROMEOS)
[email protected]6ced4e792011-04-11 10:59:0886 // Returns true if this device is managed by an enterprise (as opposed to
87 // a local owner).
88 bool IsEnterpriseManaged();
89
[email protected]30358282011-04-12 17:27:2790 // Returns the enterprise domain if device is managed.
91 std::string GetEnterpriseDomain();
92
[email protected]d59799992012-02-24 13:04:0493 // Returns the device mode. For ChromeOS this function will return the mode
94 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
95 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
96 // For other OSes the function will always return DEVICE_MODE_CONSUMER.
97 DeviceMode GetDeviceMode();
[email protected]d14c96a2013-01-23 12:15:2798#endif
[email protected]ffac3102011-04-26 15:17:2699
[email protected]fcf53572011-06-29 15:44:37100 // Schedules initialization of the cloud policy backend services, if the
101 // services are already constructed.
[email protected]5efacc02011-05-24 21:49:49102 void ScheduleServiceInitialization(int64 delay_milliseconds);
[email protected]d9ef4952011-05-20 14:07:30103
[email protected]8720d882011-11-05 18:07:42104 const ConfigurationPolicyHandlerList* GetHandlerList() const;
[email protected]f04d73f2011-10-25 15:07:12105
[email protected]28d9fc62011-11-15 17:29:29106 // Works out the user affiliation by checking the given |user_name| against
107 // the installation attributes.
[email protected]43dbf8c2012-01-03 14:28:08108 UserAffiliation GetUserAffiliation(const std::string& user_name);
[email protected]28d9fc62011-11-15 17:29:29109
[email protected]5c4c89f2012-08-07 21:09:59110 DeviceManagementService* device_management_service() {
111 return device_management_service_.get();
112 }
113
[email protected]cec72662012-10-24 14:02:07114#if defined(OS_CHROMEOS)
[email protected]d14c96a2013-01-23 12:15:27115 AppPackUpdater* GetAppPackUpdater();
116
[email protected]cec72662012-10-24 14:02:07117 DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() {
118 return device_cloud_policy_manager_.get();
119 }
[email protected]8a2166d92012-12-06 23:58:45120 DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() {
121 return device_local_account_policy_service_.get();
122 }
[email protected]5d80c0362012-12-10 23:18:22123 EnterpriseInstallAttributes* GetInstallAttributes() {
124 return install_attributes_.get();
125 }
[email protected]42c0d5ed2013-04-30 17:04:45126
127 // The browser-global PolicyService is created before Profiles are ready, to
128 // provide managed values for the local state PrefService. It includes a
129 // policy provider that forwards policies from a delegate policy provider.
130 // This call can be used to set the user policy provider as that delegate
131 // once the Profile is ready, so that user policies can also affect local
132 // state preferences.
133 // Only one user policy provider can be set as a delegate at a time, and any
134 // previously set delegate is removed. Passing NULL removes the current
135 // delegate, if there is one.
136 void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider);
[email protected]654bd7e2013-10-30 03:04:59137
138 // Sets the install attributes for testing. Must be called before the browser
139 // is created. Takes ownership of |attributes|.
140 static void SetInstallAttributesForTesting(
141 EnterpriseInstallAttributes* attributes);
[email protected]cec72662012-10-24 14:02:07142#endif
143
[email protected]3757c7d2012-07-23 11:24:36144 // Sets a |provider| that will be included in PolicyServices returned by
145 // CreatePolicyService. This is a static method because local state is
146 // created immediately after the connector, and tests don't have a chance to
147 // inject the provider otherwise. |provider| must outlive the connector, and
[email protected]3b19e8e2012-10-17 19:15:49148 // its ownership is not taken though the connector will initialize and shut it
149 // down.
[email protected]3757c7d2012-07-23 11:24:36150 static void SetPolicyProviderForTesting(
151 ConfigurationPolicyProvider* provider);
152
[email protected]f7e68e42012-12-07 20:01:27153 // Check whether a user is known to be non-enterprise. Domains such as
154 // gmail.com and googlemail.com are known to not be managed. Also returns
155 // false if the username is empty.
156 static bool IsNonEnterpriseUser(const std::string& username);
157
[email protected]d14c96a2013-01-23 12:15:27158 // Registers refresh rate prefs.
[email protected]b1de2c72013-02-06 02:45:47159 static void RegisterPrefs(PrefRegistrySimple* registry);
[email protected]d14c96a2013-01-23 12:15:27160
[email protected]985655a2011-02-23 09:54:25161 private:
[email protected]f588e2dd2012-08-16 13:42:37162 // Set the timezone as soon as the policies are available.
163 void SetTimezoneIfPolicyAvailable();
164
[email protected]8d01f642013-11-12 14:50:15165 ConfigurationPolicyProvider* CreatePlatformProvider();
[email protected]90a47542011-07-22 14:19:04166
[email protected]3b19e8e2012-10-17 19:15:49167 // Whether Init() but not Shutdown() has been invoked.
168 bool is_initialized_;
169
[email protected]362d694f2013-02-28 09:07:24170 PrefService* local_state_;
[email protected]3ea5bd52013-09-25 13:00:19171 scoped_refptr<net::URLRequestContextGetter> request_context_;
[email protected]362d694f2013-02-28 09:07:24172
[email protected]15a194d12012-06-05 12:52:20173 // Used to convert policies to preferences. The providers declared below
[email protected]3b19e8e2012-10-17 19:15:49174 // may trigger policy updates during shutdown, which will result in
175 // |handler_list_| being consulted for policy translation.
[email protected]15a194d12012-06-05 12:52:20176 // Therefore, it's important to destroy |handler_list_| after the providers.
[email protected]d9534e072013-10-25 12:02:05177 scoped_ptr<ConfigurationPolicyHandlerList> handler_list_;
[email protected]15a194d12012-06-05 12:52:20178
[email protected]eb83c392013-11-07 12:53:24179 // The Chrome schema. This wraps the structure generated by
180 // generate_policy_source.py at compile time.
181 Schema chrome_schema_;
182
183 // The global SchemaRegistry, which will track all the other registries.
184 CombinedSchemaRegistry schema_registry_;
185
[email protected]f2e46d42012-06-05 17:35:45186 scoped_ptr<ConfigurationPolicyProvider> platform_provider_;
[email protected]fcf53572011-06-29 15:44:37187
[email protected]42c0d5ed2013-04-30 17:04:45188 // Components of the device cloud policy implementation.
[email protected]bd48fee62012-10-23 19:18:22189#if defined(OS_CHROMEOS)
190 scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
191 scoped_ptr<DeviceCloudPolicyManagerChromeOS> device_cloud_policy_manager_;
[email protected]0f456542012-11-23 16:26:35192 scoped_ptr<DeviceLocalAccountPolicyService>
193 device_local_account_policy_service_;
[email protected]3c843b42012-12-03 16:00:16194
195 // This policy provider is used on Chrome OS to feed user policy into the
[email protected]42c0d5ed2013-04-30 17:04:45196 // global PolicyService instance. This works by installing the cloud policy
197 // provider of the primary profile as the delegate of the ProxyPolicyProvider,
198 // after login.
[email protected]3c843b42012-12-03 16:00:16199 ProxyPolicyProvider global_user_cloud_policy_provider_;
[email protected]bd48fee62012-10-23 19:18:22200#endif
[email protected]3b19e8e2012-10-17 19:15:49201
202 // Must be deleted before all the policy providers.
203 scoped_ptr<PolicyService> policy_service_;
204
[email protected]e908adf32012-09-20 16:44:32205 scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_;
206
[email protected]15a194d12012-06-05 12:52:20207 scoped_ptr<DeviceManagementService> device_management_service_;
208
[email protected]d203dec2011-10-04 13:18:16209 // Used to initialize the device policy subsystem once the message loops
210 // are spinning.
211 base::WeakPtrFactory<BrowserPolicyConnector> weak_ptr_factory_;
[email protected]985655a2011-02-23 09:54:25212
[email protected]944dfa82012-03-20 02:07:51213#if defined(OS_CHROMEOS)
214 scoped_ptr<AppPackUpdater> app_pack_updater_;
[email protected]bfeb6ce2012-09-07 15:02:41215 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
[email protected]944dfa82012-03-20 02:07:51216#endif
217
[email protected]985655a2011-02-23 09:54:25218 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector);
219};
220
221} // namespace policy
222
223#endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_