OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
6 #define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/policy/cloud_policy_constants.h" | 13 #include "chrome/browser/policy/cloud_policy_constants.h" |
14 #include "chrome/browser/policy/configuration_policy_handler_list.h" | 14 #include "chrome/browser/policy/configuration_policy_handler_list.h" |
15 #include "chrome/browser/policy/enterprise_install_attributes.h" | 15 #include "chrome/browser/policy/enterprise_install_attributes.h" |
Joao da Silva
2013/01/17 09:38:05
This can be forward-declared now
Mattias Nissler (ping if slow)
2013/01/22 10:31:39
Done.
| |
16 #include "chrome/browser/policy/proxy_policy_provider.h" | 16 #include "chrome/browser/policy/proxy_policy_provider.h" |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 | 17 |
20 class Profile; | 18 class Profile; |
21 class TokenService; | |
22 | 19 |
23 namespace policy { | 20 namespace policy { |
24 | 21 |
25 class AppPackUpdater; | 22 class AppPackUpdater; |
26 class CloudPolicyDataStore; | |
27 class CloudPolicyProvider; | |
28 class CloudPolicySubsystem; | |
29 class ConfigurationPolicyProvider; | 23 class ConfigurationPolicyProvider; |
30 class DeviceCloudPolicyManagerChromeOS; | 24 class DeviceCloudPolicyManagerChromeOS; |
31 class DeviceLocalAccountPolicyProvider; | 25 class DeviceLocalAccountPolicyProvider; |
32 class DeviceLocalAccountPolicyService; | 26 class DeviceLocalAccountPolicyService; |
33 class DeviceManagementService; | 27 class DeviceManagementService; |
34 class NetworkConfigurationUpdater; | 28 class NetworkConfigurationUpdater; |
35 class PolicyService; | 29 class PolicyService; |
36 class PolicyStatisticsCollector; | 30 class PolicyStatisticsCollector; |
37 class UserCloudPolicyManagerChromeOS; | 31 class UserCloudPolicyManagerChromeOS; |
38 class UserPolicyTokenCache; | |
39 | 32 |
40 // Manages the lifecycle of browser-global policy infrastructure, such as the | 33 // Manages the lifecycle of browser-global policy infrastructure, such as the |
41 // platform policy providers, device- and the user-cloud policy infrastructure. | 34 // platform policy providers, device- and the user-cloud policy infrastructure. |
42 // TODO(gfeher,mnissler): Factor out device and user specific methods into their | 35 class BrowserPolicyConnector { |
43 // respective classes. | |
44 class BrowserPolicyConnector : public content::NotificationObserver { | |
45 public: | 36 public: |
46 // Builds an uninitialized BrowserPolicyConnector, suitable for testing. | 37 // Builds an uninitialized BrowserPolicyConnector, suitable for testing. |
47 // Init() should be called to create and start the policy machinery. | 38 // Init() should be called to create and start the policy machinery. |
48 BrowserPolicyConnector(); | 39 BrowserPolicyConnector(); |
49 | 40 |
50 // Invoke Shutdown() before deleting, see below. | 41 // Invoke Shutdown() before deleting, see below. |
51 virtual ~BrowserPolicyConnector(); | 42 virtual ~BrowserPolicyConnector(); |
52 | 43 |
53 // Creates the policy providers and finalizes the initialization of the | 44 // Creates the policy providers and finalizes the initialization of the |
54 // connector. This call can be skipped on tests that don't require the full | 45 // connector. This call can be skipped on tests that don't require the full |
55 // policy system running. | 46 // policy system running. |
56 void Init(); | 47 void Init(); |
57 | 48 |
58 // Stops the policy providers and cleans up the connector before it can be | 49 // Stops the policy providers and cleans up the connector before it can be |
59 // safely deleted. This must be invoked before the destructor and while the | 50 // safely deleted. This must be invoked before the destructor and while the |
60 // threads are still running. The policy providers are still valid but won't | 51 // threads are still running. The policy providers are still valid but won't |
61 // update anymore after this call. | 52 // update anymore after this call. |
62 void Shutdown(); | 53 void Shutdown(); |
63 | 54 |
64 // Returns true if Init() has been called but Shutdown() hasn't been yet. | 55 // Returns true if Init() has been called but Shutdown() hasn't been yet. |
65 bool is_initialized() const { return is_initialized_; } | 56 bool is_initialized() const { return is_initialized_; } |
66 | 57 |
67 // Creates a new policy service for the given profile. | 58 // Creates a new policy service for the given profile. |
68 scoped_ptr<PolicyService> CreatePolicyService(Profile* profile); | 59 scoped_ptr<PolicyService> CreatePolicyService(Profile* profile); |
69 | 60 |
70 // Returns the browser-global PolicyService, that contains policies for the | 61 // Returns the browser-global PolicyService, that contains policies for the |
71 // whole browser. | 62 // whole browser. |
72 PolicyService* GetPolicyService(); | 63 PolicyService* GetPolicyService(); |
73 | 64 |
74 // Returns a weak pointer to the CloudPolicySubsystem corresponding to the | |
75 // device policy managed by this policy connector, or NULL if no such | |
76 // subsystem exists (i.e. when running outside ChromeOS). | |
77 CloudPolicySubsystem* device_cloud_policy_subsystem() { | |
78 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
79 return device_cloud_policy_subsystem_.get(); | |
80 #else | |
81 return NULL; | |
82 #endif | |
83 } | |
84 | |
85 // Returns a weak pointer to the CloudPolicySubsystem corresponding to the | |
86 // user policy managed by this policy connector, or NULL if no such | |
87 // subsystem exists (i.e. when user cloud policy is not active due to | |
88 // unmanaged or not logged in). | |
89 CloudPolicySubsystem* user_cloud_policy_subsystem() { | |
90 return user_cloud_policy_subsystem_.get(); | |
91 } | |
92 | |
93 // Triggers registration for device policy, using the |owner_email| account. | |
94 // |token| is an oauth token to authenticate the registration request, and | |
95 // |known_machine_id| is true if the server should do additional checks based | |
96 // on the machine_id used for the request. | |
97 void RegisterForDevicePolicy(const std::string& owner_email, | |
98 const std::string& token, | |
99 bool known_machine_id, | |
100 bool reregister); | |
101 | |
102 // Returns true if this device is managed by an enterprise (as opposed to | 66 // Returns true if this device is managed by an enterprise (as opposed to |
103 // a local owner). | 67 // a local owner). |
104 bool IsEnterpriseManaged(); | 68 bool IsEnterpriseManaged(); |
105 | 69 |
106 // Locks the device to an enterprise domain. | |
107 EnterpriseInstallAttributes::LockResult LockDevice(const std::string& user); | |
108 | |
109 // Returns the enterprise domain if device is managed. | 70 // Returns the enterprise domain if device is managed. |
110 std::string GetEnterpriseDomain(); | 71 std::string GetEnterpriseDomain(); |
111 | 72 |
112 // Returns the device mode. For ChromeOS this function will return the mode | 73 // Returns the device mode. For ChromeOS this function will return the mode |
113 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been | 74 // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been |
114 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet. | 75 // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet. |
115 // For other OSes the function will always return DEVICE_MODE_CONSUMER. | 76 // For other OSes the function will always return DEVICE_MODE_CONSUMER. |
116 DeviceMode GetDeviceMode(); | 77 DeviceMode GetDeviceMode(); |
117 | 78 #endif |
118 // Reset the device policy machinery. This stops any automatic retry behavior | |
119 // and clears the error flags, so potential retries have a chance to succeed. | |
120 void ResetDevicePolicy(); | |
121 | |
122 // Initiates device and user policy fetches, if possible. Pending fetches | |
123 // will be cancelled. | |
124 void FetchCloudPolicy(); | |
125 | 79 |
126 // Schedules initialization of the cloud policy backend services, if the | 80 // Schedules initialization of the cloud policy backend services, if the |
127 // services are already constructed. | 81 // services are already constructed. |
128 void ScheduleServiceInitialization(int64 delay_milliseconds); | 82 void ScheduleServiceInitialization(int64 delay_milliseconds); |
129 | 83 |
84 #if defined(OS_CHROMEOS) | |
130 // Initializes the user cloud policy infrastructure. | 85 // Initializes the user cloud policy infrastructure. |
131 // If |wait_for_policy_fetch| is true, the user policy will only become fully | 86 // If |wait_for_policy_fetch| is true, the user policy will only become fully |
132 // initialized after a policy fetch is attempted. Note that Profile creation | 87 // initialized after a policy fetch is attempted. Note that Profile creation |
133 // is blocked until this initialization is complete. | 88 // is blocked until this initialization is complete. |
134 void InitializeUserPolicy(const std::string& user_name, | 89 void InitializeUserPolicy(const std::string& user_name, |
135 bool is_public_account, | 90 bool is_public_account, |
136 bool wait_for_policy_fetch); | 91 bool wait_for_policy_fetch); |
137 | 92 #endif |
138 // Installs a token service for user policy. | |
139 void SetUserPolicyTokenService(TokenService* token_service); | |
140 | |
141 // Registers for user policy (if not already registered), using the passed | |
142 // OAuth V2 token for authentication. |oauth_token| can be empty to signal | |
143 // that an attempt to fetch the token was made but failed, or that oauth | |
144 // isn't being used. | |
145 void RegisterForUserPolicy(const std::string& oauth_token); | |
146 | |
147 // The data stores should be considered read-only for everyone except for | |
148 // tests. | |
149 CloudPolicyDataStore* GetDeviceCloudPolicyDataStore(); | |
150 CloudPolicyDataStore* GetUserCloudPolicyDataStore(); | |
151 | 93 |
152 const ConfigurationPolicyHandlerList* GetHandlerList() const; | 94 const ConfigurationPolicyHandlerList* GetHandlerList() const; |
153 | 95 |
154 // Works out the user affiliation by checking the given |user_name| against | 96 // Works out the user affiliation by checking the given |user_name| against |
155 // the installation attributes. | 97 // the installation attributes. |
156 UserAffiliation GetUserAffiliation(const std::string& user_name); | 98 UserAffiliation GetUserAffiliation(const std::string& user_name); |
157 | 99 |
158 AppPackUpdater* GetAppPackUpdater(); | 100 AppPackUpdater* GetAppPackUpdater(); |
159 | 101 |
160 NetworkConfigurationUpdater* GetNetworkConfigurationUpdater(); | 102 NetworkConfigurationUpdater* GetNetworkConfigurationUpdater(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 // Gets the URL of the DM server (either the default or a URL provided via the | 137 // Gets the URL of the DM server (either the default or a URL provided via the |
196 // command line). | 138 // command line). |
197 static std::string GetDeviceManagementUrl(); | 139 static std::string GetDeviceManagementUrl(); |
198 | 140 |
199 // Check whether a user is known to be non-enterprise. Domains such as | 141 // Check whether a user is known to be non-enterprise. Domains such as |
200 // gmail.com and googlemail.com are known to not be managed. Also returns | 142 // gmail.com and googlemail.com are known to not be managed. Also returns |
201 // false if the username is empty. | 143 // false if the username is empty. |
202 static bool IsNonEnterpriseUser(const std::string& username); | 144 static bool IsNonEnterpriseUser(const std::string& username); |
203 | 145 |
204 private: | 146 private: |
205 // content::NotificationObserver method overrides: | |
206 virtual void Observe(int type, | |
207 const content::NotificationSource& source, | |
208 const content::NotificationDetails& details) OVERRIDE; | |
209 | |
210 // Initializes the device cloud policy infrasturcture. | |
211 void InitializeDevicePolicy(); | |
212 | |
213 // Complete initialization once the message loops are running and the | 147 // Complete initialization once the message loops are running and the |
214 // local_state is initialized. | 148 // local_state is initialized. |
215 void CompleteInitialization(); | 149 void CompleteInitialization(); |
216 | 150 |
217 // Set the timezone as soon as the policies are available. | 151 // Set the timezone as soon as the policies are available. |
218 void SetTimezoneIfPolicyAvailable(); | 152 void SetTimezoneIfPolicyAvailable(); |
219 | 153 |
220 // Creates a new PolicyService with the shared policy providers and the given | 154 // Creates a new PolicyService with the shared policy providers and the given |
221 // |user_cloud_policy_provider| and |managed_mode_policy_provider|, which are | 155 // |user_cloud_policy_provider| and |managed_mode_policy_provider|, which are |
222 // optional. | 156 // optional. |
223 scoped_ptr<PolicyService> CreatePolicyServiceWithProviders( | 157 scoped_ptr<PolicyService> CreatePolicyServiceWithProviders( |
224 ConfigurationPolicyProvider* user_cloud_policy_provider, | 158 ConfigurationPolicyProvider* user_cloud_policy_provider, |
225 ConfigurationPolicyProvider* managed_mode_policy_provider); | 159 ConfigurationPolicyProvider* managed_mode_policy_provider); |
226 | 160 |
227 static ConfigurationPolicyProvider* CreatePlatformProvider(); | 161 static ConfigurationPolicyProvider* CreatePlatformProvider(); |
228 | 162 |
229 // Whether Init() but not Shutdown() has been invoked. | 163 // Whether Init() but not Shutdown() has been invoked. |
230 bool is_initialized_; | 164 bool is_initialized_; |
231 | 165 |
232 // Used to convert policies to preferences. The providers declared below | 166 // Used to convert policies to preferences. The providers declared below |
233 // may trigger policy updates during shutdown, which will result in | 167 // may trigger policy updates during shutdown, which will result in |
234 // |handler_list_| being consulted for policy translation. | 168 // |handler_list_| being consulted for policy translation. |
235 // Therefore, it's important to destroy |handler_list_| after the providers. | 169 // Therefore, it's important to destroy |handler_list_| after the providers. |
236 ConfigurationPolicyHandlerList handler_list_; | 170 ConfigurationPolicyHandlerList handler_list_; |
237 | 171 |
238 scoped_ptr<ConfigurationPolicyProvider> platform_provider_; | 172 scoped_ptr<ConfigurationPolicyProvider> platform_provider_; |
239 scoped_ptr<CloudPolicyProvider> cloud_provider_; | |
240 | 173 |
241 // Components of the new-style cloud policy implementation. | 174 // Components of the new-style cloud policy implementation. |
242 // TODO(mnissler): Remove the old-style components below once we have | 175 // TODO(mnissler): Remove the old-style components below once we have |
243 // completed the switch to the new cloud policy implementation. | 176 // completed the switch to the new cloud policy implementation. |
244 #if defined(OS_CHROMEOS) | 177 #if defined(OS_CHROMEOS) |
245 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; | 178 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; |
246 scoped_ptr<DeviceCloudPolicyManagerChromeOS> device_cloud_policy_manager_; | 179 scoped_ptr<DeviceCloudPolicyManagerChromeOS> device_cloud_policy_manager_; |
247 scoped_ptr<DeviceLocalAccountPolicyService> | 180 scoped_ptr<DeviceLocalAccountPolicyService> |
248 device_local_account_policy_service_; | 181 device_local_account_policy_service_; |
249 scoped_ptr<DeviceLocalAccountPolicyProvider> | 182 scoped_ptr<DeviceLocalAccountPolicyProvider> |
250 device_local_account_policy_provider_; | 183 device_local_account_policy_provider_; |
251 scoped_ptr<UserCloudPolicyManagerChromeOS> user_cloud_policy_manager_; | 184 scoped_ptr<UserCloudPolicyManagerChromeOS> user_cloud_policy_manager_; |
252 | 185 |
253 // This policy provider is used on Chrome OS to feed user policy into the | 186 // This policy provider is used on Chrome OS to feed user policy into the |
254 // global PolicyService instance. This works by installing | 187 // global PolicyService instance. This works by installing |
255 // |user_cloud_policy_manager_| or |device_local_account_policy_provider_|, | 188 // |user_cloud_policy_manager_| or |device_local_account_policy_provider_|, |
256 // respectively as the delegate after login. | 189 // respectively as the delegate after login. |
257 ProxyPolicyProvider global_user_cloud_policy_provider_; | 190 ProxyPolicyProvider global_user_cloud_policy_provider_; |
258 #endif | 191 #endif |
259 | 192 |
260 // Must be deleted before all the policy providers. | 193 // Must be deleted before all the policy providers. |
261 scoped_ptr<PolicyService> policy_service_; | 194 scoped_ptr<PolicyService> policy_service_; |
262 | 195 |
263 #if defined(OS_CHROMEOS) | |
264 scoped_ptr<CloudPolicyDataStore> device_data_store_; | |
265 scoped_ptr<CloudPolicySubsystem> device_cloud_policy_subsystem_; | |
266 #endif | |
267 | |
268 scoped_ptr<UserPolicyTokenCache> user_policy_token_cache_; | |
269 scoped_ptr<CloudPolicyDataStore> user_data_store_; | |
270 scoped_ptr<CloudPolicySubsystem> user_cloud_policy_subsystem_; | |
271 | |
272 scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_; | 196 scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_; |
273 | 197 |
274 scoped_ptr<DeviceManagementService> device_management_service_; | 198 scoped_ptr<DeviceManagementService> device_management_service_; |
275 | 199 |
276 // Used to initialize the device policy subsystem once the message loops | 200 // Used to initialize the device policy subsystem once the message loops |
277 // are spinning. | 201 // are spinning. |
278 base::WeakPtrFactory<BrowserPolicyConnector> weak_ptr_factory_; | 202 base::WeakPtrFactory<BrowserPolicyConnector> weak_ptr_factory_; |
279 | 203 |
280 // Registers the provider for notification of successful Gaia logins. | |
281 content::NotificationRegistrar registrar_; | |
282 | |
283 // Weak reference to the TokenService we are listening to for user cloud | |
284 // policy authentication tokens. | |
285 TokenService* token_service_; | |
286 | |
287 #if defined(OS_CHROMEOS) | 204 #if defined(OS_CHROMEOS) |
288 scoped_ptr<AppPackUpdater> app_pack_updater_; | 205 scoped_ptr<AppPackUpdater> app_pack_updater_; |
289 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; | 206 scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_; |
290 #endif | 207 #endif |
291 | 208 |
292 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); | 209 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); |
293 }; | 210 }; |
294 | 211 |
295 } // namespace policy | 212 } // namespace policy |
296 | 213 |
297 #endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 214 #endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
OLD | NEW |