[email protected] | 43dbf8c | 2012-01-03 14:28:08 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 2 | // 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] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 7 | |
[email protected] | 6ced4e79 | 2011-04-11 10:59:08 | [diff] [blame] | 8 | #include <string> |
[email protected] | 6ced4e79 | 2011-04-11 10:59:08 | [diff] [blame] | 9 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | d203dec | 2011-10-04 13:18:16 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
[email protected] | b39d2571 | 2013-03-14 09:53:40 | [diff] [blame] | 14 | #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
[email protected] | 8720d88 | 2011-11-05 18:07:42 | [diff] [blame] | 15 | #include "chrome/browser/policy/configuration_policy_handler_list.h" |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 16 | #include "chrome/browser/policy/schema_registry.h" |
| 17 | #include "components/policy/core/common/schema.h" |
[email protected] | b39d2571 | 2013-03-14 09:53:40 | [diff] [blame] | 18 | |
| 19 | #if defined(OS_CHROMEOS) |
| 20 | #include "chrome/browser/chromeos/policy/proxy_policy_provider.h" |
| 21 | #endif |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 22 | |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 23 | class PrefRegistrySimple; |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 24 | class PrefService; |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 25 | |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 26 | namespace net { |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 27 | class URLRequestContextGetter; |
| 28 | } |
| 29 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 30 | namespace policy { |
| 31 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 32 | class ConfigurationPolicyProvider; |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 33 | class DeviceManagementService; |
| 34 | class PolicyService; |
| 35 | class PolicyStatisticsCollector; |
| 36 | |
| 37 | #if defined(OS_CHROMEOS) |
| 38 | class AppPackUpdater; |
[email protected] | bd48fee6 | 2012-10-23 19:18:22 | [diff] [blame] | 39 | class DeviceCloudPolicyManagerChromeOS; |
[email protected] | 0f45654 | 2012-11-23 16:26:35 | [diff] [blame] | 40 | class DeviceLocalAccountPolicyService; |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 41 | class EnterpriseInstallAttributes; |
[email protected] | bfeb6ce | 2012-09-07 15:02:41 | [diff] [blame] | 42 | class NetworkConfigurationUpdater; |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 43 | #endif |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 44 | |
| 45 | // Manages the lifecycle of browser-global policy infrastructure, such as the |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 46 | // platform policy providers, device- and the user-cloud policy infrastructure. |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 47 | class BrowserPolicyConnector { |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 48 | public: |
[email protected] | 5fe0458 | 2011-11-21 19:25:57 | [diff] [blame] | 49 | // Builds an uninitialized BrowserPolicyConnector, suitable for testing. |
| 50 | // Init() should be called to create and start the policy machinery. |
| 51 | BrowserPolicyConnector(); |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 52 | |
| 53 | // Invoke Shutdown() before deleting, see below. |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 54 | virtual ~BrowserPolicyConnector(); |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 55 | |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 56 | // 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] | 3ea5bd5 | 2013-09-25 13:00:19 | [diff] [blame] | 59 | scoped_refptr<net::URLRequestContextGetter> request_context); |
[email protected] | 5fe0458 | 2011-11-21 19:25:57 | [diff] [blame] | 60 | |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 61 | // 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] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 70 | // 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] | d25da25 | 2013-11-14 01:23:43 | [diff] [blame^] | 78 | // Returns the platform policy provider. |
| 79 | ConfigurationPolicyProvider* GetPlatformProvider(); |
| 80 | |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 81 | // Returns the browser-global PolicyService, that contains policies for the |
| 82 | // whole browser. |
| 83 | PolicyService* GetPolicyService(); |
| 84 | |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 85 | #if defined(OS_CHROMEOS) |
[email protected] | 6ced4e79 | 2011-04-11 10:59:08 | [diff] [blame] | 86 | // Returns true if this device is managed by an enterprise (as opposed to |
| 87 | // a local owner). |
| 88 | bool IsEnterpriseManaged(); |
| 89 | |
[email protected] | 3035828 | 2011-04-12 17:27:27 | [diff] [blame] | 90 | // Returns the enterprise domain if device is managed. |
| 91 | std::string GetEnterpriseDomain(); |
| 92 | |
[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 93 | // 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] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 98 | #endif |
[email protected] | ffac310 | 2011-04-26 15:17:26 | [diff] [blame] | 99 | |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 100 | // Schedules initialization of the cloud policy backend services, if the |
| 101 | // services are already constructed. |
[email protected] | 5efacc0 | 2011-05-24 21:49:49 | [diff] [blame] | 102 | void ScheduleServiceInitialization(int64 delay_milliseconds); |
[email protected] | d9ef495 | 2011-05-20 14:07:30 | [diff] [blame] | 103 | |
[email protected] | 8720d88 | 2011-11-05 18:07:42 | [diff] [blame] | 104 | const ConfigurationPolicyHandlerList* GetHandlerList() const; |
[email protected] | f04d73f | 2011-10-25 15:07:12 | [diff] [blame] | 105 | |
[email protected] | 28d9fc6 | 2011-11-15 17:29:29 | [diff] [blame] | 106 | // Works out the user affiliation by checking the given |user_name| against |
| 107 | // the installation attributes. |
[email protected] | 43dbf8c | 2012-01-03 14:28:08 | [diff] [blame] | 108 | UserAffiliation GetUserAffiliation(const std::string& user_name); |
[email protected] | 28d9fc6 | 2011-11-15 17:29:29 | [diff] [blame] | 109 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 110 | DeviceManagementService* device_management_service() { |
| 111 | return device_management_service_.get(); |
| 112 | } |
| 113 | |
[email protected] | cec7266 | 2012-10-24 14:02:07 | [diff] [blame] | 114 | #if defined(OS_CHROMEOS) |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 115 | AppPackUpdater* GetAppPackUpdater(); |
| 116 | |
[email protected] | cec7266 | 2012-10-24 14:02:07 | [diff] [blame] | 117 | DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() { |
| 118 | return device_cloud_policy_manager_.get(); |
| 119 | } |
[email protected] | 8a2166d9 | 2012-12-06 23:58:45 | [diff] [blame] | 120 | DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() { |
| 121 | return device_local_account_policy_service_.get(); |
| 122 | } |
[email protected] | 5d80c036 | 2012-12-10 23:18:22 | [diff] [blame] | 123 | EnterpriseInstallAttributes* GetInstallAttributes() { |
| 124 | return install_attributes_.get(); |
| 125 | } |
[email protected] | 42c0d5ed | 2013-04-30 17:04:45 | [diff] [blame] | 126 | |
| 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] | 654bd7e | 2013-10-30 03:04:59 | [diff] [blame] | 137 | |
| 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] | cec7266 | 2012-10-24 14:02:07 | [diff] [blame] | 142 | #endif |
| 143 | |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 144 | // 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] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 148 | // its ownership is not taken though the connector will initialize and shut it |
| 149 | // down. |
[email protected] | 3757c7d | 2012-07-23 11:24:36 | [diff] [blame] | 150 | static void SetPolicyProviderForTesting( |
| 151 | ConfigurationPolicyProvider* provider); |
| 152 | |
[email protected] | f7e68e4 | 2012-12-07 20:01:27 | [diff] [blame] | 153 | // 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] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 158 | // Registers refresh rate prefs. |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 159 | static void RegisterPrefs(PrefRegistrySimple* registry); |
[email protected] | d14c96a | 2013-01-23 12:15:27 | [diff] [blame] | 160 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 161 | private: |
[email protected] | f588e2dd | 2012-08-16 13:42:37 | [diff] [blame] | 162 | // Set the timezone as soon as the policies are available. |
| 163 | void SetTimezoneIfPolicyAvailable(); |
| 164 | |
[email protected] | 8d01f64 | 2013-11-12 14:50:15 | [diff] [blame] | 165 | ConfigurationPolicyProvider* CreatePlatformProvider(); |
[email protected] | 90a4754 | 2011-07-22 14:19:04 | [diff] [blame] | 166 | |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 167 | // Whether Init() but not Shutdown() has been invoked. |
| 168 | bool is_initialized_; |
| 169 | |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 170 | PrefService* local_state_; |
[email protected] | 3ea5bd5 | 2013-09-25 13:00:19 | [diff] [blame] | 171 | scoped_refptr<net::URLRequestContextGetter> request_context_; |
[email protected] | 362d694f | 2013-02-28 09:07:24 | [diff] [blame] | 172 | |
[email protected] | 15a194d1 | 2012-06-05 12:52:20 | [diff] [blame] | 173 | // Used to convert policies to preferences. The providers declared below |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 174 | // may trigger policy updates during shutdown, which will result in |
| 175 | // |handler_list_| being consulted for policy translation. |
[email protected] | 15a194d1 | 2012-06-05 12:52:20 | [diff] [blame] | 176 | // Therefore, it's important to destroy |handler_list_| after the providers. |
[email protected] | d9534e07 | 2013-10-25 12:02:05 | [diff] [blame] | 177 | scoped_ptr<ConfigurationPolicyHandlerList> handler_list_; |
[email protected] | 15a194d1 | 2012-06-05 12:52:20 | [diff] [blame] | 178 | |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 179 | // 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] | f2e46d4 | 2012-06-05 17:35:45 | [diff] [blame] | 186 | scoped_ptr<ConfigurationPolicyProvider> platform_provider_; |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 187 | |
[email protected] | 42c0d5ed | 2013-04-30 17:04:45 | [diff] [blame] | 188 | // Components of the device cloud policy implementation. |
[email protected] | bd48fee6 | 2012-10-23 19:18:22 | [diff] [blame] | 189 | #if defined(OS_CHROMEOS) |
| 190 | scoped_ptr<EnterpriseInstallAttributes> install_attributes_; |
| 191 | scoped_ptr<DeviceCloudPolicyManagerChromeOS> device_cloud_policy_manager_; |
[email protected] | 0f45654 | 2012-11-23 16:26:35 | [diff] [blame] | 192 | scoped_ptr<DeviceLocalAccountPolicyService> |
| 193 | device_local_account_policy_service_; |
[email protected] | 3c843b4 | 2012-12-03 16:00:16 | [diff] [blame] | 194 | |
| 195 | // This policy provider is used on Chrome OS to feed user policy into the |
[email protected] | 42c0d5ed | 2013-04-30 17:04:45 | [diff] [blame] | 196 | // 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] | 3c843b4 | 2012-12-03 16:00:16 | [diff] [blame] | 199 | ProxyPolicyProvider global_user_cloud_policy_provider_; |
[email protected] | bd48fee6 | 2012-10-23 19:18:22 | [diff] [blame] | 200 | #endif |
[email protected] | 3b19e8e | 2012-10-17 19:15:49 | [diff] [blame] | 201 | |
| 202 | // Must be deleted before all the policy providers. |
| 203 | scoped_ptr<PolicyService> policy_service_; |
| 204 | |
[email protected] | e908adf3 | 2012-09-20 16:44:32 | [diff] [blame] | 205 | scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_; |
| 206 | |
[email protected] | 15a194d1 | 2012-06-05 12:52:20 | [diff] [blame] | 207 | scoped_ptr<DeviceManagementService> device_management_service_; |
| 208 | |
[email protected] | d203dec | 2011-10-04 13:18:16 | [diff] [blame] | 209 | // Used to initialize the device policy subsystem once the message loops |
| 210 | // are spinning. |
| 211 | base::WeakPtrFactory<BrowserPolicyConnector> weak_ptr_factory_; |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 212 | |
[email protected] | 944dfa8 | 2012-03-20 02:07:51 | [diff] [blame] | 213 | #if defined(OS_CHROMEOS) |
| 214 | scoped_ptr<AppPackUpdater> app_pack_updater_; |
[email protected] | bfeb6ce | 2012-09-07 15:02:41 | [diff] [blame] | 215 | scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
[email protected] | 944dfa8 | 2012-03-20 02:07:51 | [diff] [blame] | 216 | #endif |
| 217 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 218 | DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); |
| 219 | }; |
| 220 | |
| 221 | } // namespace policy |
| 222 | |
| 223 | #endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |