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 #include "chrome/browser/policy/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/policy/async_policy_provider.h" | 16 #include "chrome/browser/policy/async_policy_provider.h" |
17 #include "chrome/browser/policy/cloud_policy_client.h" | 17 #include "chrome/browser/policy/cloud_policy_client.h" |
18 #include "chrome/browser/policy/cloud_policy_provider.h" | |
19 #include "chrome/browser/policy/cloud_policy_service.h" | 18 #include "chrome/browser/policy/cloud_policy_service.h" |
20 #include "chrome/browser/policy/cloud_policy_subsystem.h" | |
21 #include "chrome/browser/policy/configuration_policy_provider.h" | 19 #include "chrome/browser/policy/configuration_policy_provider.h" |
22 #include "chrome/browser/policy/device_management_service.h" | 20 #include "chrome/browser/policy/device_management_service.h" |
23 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 21 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
24 #include "chrome/browser/policy/policy_service_impl.h" | 22 #include "chrome/browser/policy/policy_service_impl.h" |
25 #include "chrome/browser/policy/policy_statistics_collector.h" | 23 #include "chrome/browser/policy/policy_statistics_collector.h" |
26 #include "chrome/browser/policy/user_policy_cache.h" | |
27 #include "chrome/browser/policy/user_policy_token_cache.h" | |
28 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/signin/token_service.h" | |
31 #include "chrome/common/chrome_notification_types.h" | |
32 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
Joao da Silva
2013/01/17 09:38:05
Not used
Mattias Nissler (ping if slow)
2013/01/22 10:31:39
Done.
| |
35 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
36 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
Joao da Silva
2013/01/17 09:38:05
These 2 not used
Mattias Nissler (ping if slow)
2013/01/22 10:31:39
Done.
| |
37 #include "google_apis/gaia/gaia_auth_util.h" | 31 #include "google_apis/gaia/gaia_auth_util.h" |
38 #include "google_apis/gaia/gaia_constants.h" | 32 #include "google_apis/gaia/gaia_constants.h" |
39 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
40 #include "policy/policy_constants.h" | 34 #include "policy/policy_constants.h" |
41 #include "third_party/icu/public/i18n/unicode/regex.h" | 35 #include "third_party/icu/public/i18n/unicode/regex.h" |
42 | 36 |
43 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
44 #include "chrome/browser/policy/policy_loader_win.h" | 38 #include "chrome/browser/policy/policy_loader_win.h" |
45 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
46 #include "chrome/browser/policy/policy_loader_mac.h" | 40 #include "chrome/browser/policy/policy_loader_mac.h" |
47 #include "chrome/browser/preferences_mac.h" | 41 #include "chrome/browser/preferences_mac.h" |
48 #elif defined(OS_POSIX) | 42 #elif defined(OS_POSIX) |
49 #include "chrome/browser/policy/config_dir_policy_loader.h" | 43 #include "chrome/browser/policy/config_dir_policy_loader.h" |
50 #endif | 44 #endif |
51 | 45 |
52 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
53 #include "base/utf_string_conversions.h" | 47 #include "base/utf_string_conversions.h" |
54 #include "chrome/browser/chromeos/cros/cros_library.h" | 48 #include "chrome/browser/chromeos/cros/cros_library.h" |
55 #include "chrome/browser/chromeos/login/user_manager.h" | 49 #include "chrome/browser/chromeos/login/user_manager.h" |
56 #include "chrome/browser/chromeos/settings/cros_settings.h" | 50 #include "chrome/browser/chromeos/settings/cros_settings.h" |
57 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" | 51 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
58 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 52 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
59 #include "chrome/browser/chromeos/system/statistics_provider.h" | 53 #include "chrome/browser/chromeos/system/statistics_provider.h" |
60 #include "chrome/browser/chromeos/system/timezone_settings.h" | 54 #include "chrome/browser/chromeos/system/timezone_settings.h" |
61 #include "chrome/browser/policy/app_pack_updater.h" | 55 #include "chrome/browser/policy/app_pack_updater.h" |
62 #include "chrome/browser/policy/cros_user_policy_cache.h" | |
63 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h" | 56 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h" |
64 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h" | 57 #include "chrome/browser/policy/device_cloud_policy_store_chromeos.h" |
65 #include "chrome/browser/policy/device_local_account_policy_provider.h" | 58 #include "chrome/browser/policy/device_local_account_policy_provider.h" |
66 #include "chrome/browser/policy/device_local_account_policy_service.h" | 59 #include "chrome/browser/policy/device_local_account_policy_service.h" |
67 #include "chrome/browser/policy/device_policy_cache.h" | 60 #include "chrome/browser/policy/device_status_collector.h" |
68 #include "chrome/browser/policy/network_configuration_updater.h" | 61 #include "chrome/browser/policy/network_configuration_updater.h" |
69 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" | 62 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" |
70 #include "chrome/browser/policy/user_cloud_policy_store_chromeos.h" | 63 #include "chrome/browser/policy/user_cloud_policy_store_chromeos.h" |
71 #include "chromeos/dbus/dbus_thread_manager.h" | 64 #include "chromeos/dbus/dbus_thread_manager.h" |
72 #else | 65 #else |
73 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 66 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
74 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" | 67 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" |
75 #endif | 68 #endif |
76 | 69 |
77 using content::BrowserThread; | |
78 | |
79 namespace policy { | 70 namespace policy { |
80 | 71 |
81 namespace { | 72 namespace { |
82 | 73 |
83 // Subdirectory in the user's profile for storing user policies. | 74 // Subdirectory in the user's profile for storing user policies. |
84 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 75 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
85 // File in the above directory for stroing user policy dmtokens. | 76 // File in the above directory for stroing user policy dmtokens. |
86 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); | 77 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
87 // File in the above directory for storing user policy data. | 78 // File in the above directory for storing user policy data. |
88 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); | 79 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 if (!device_management_service_.get()) { | 113 if (!device_management_service_.get()) { |
123 device_management_service_.reset( | 114 device_management_service_.reset( |
124 new DeviceManagementService(GetDeviceManagementUrl())); | 115 new DeviceManagementService(GetDeviceManagementUrl())); |
125 } | 116 } |
126 | 117 |
127 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
128 chromeos::CryptohomeLibrary* cryptohome = | 119 chromeos::CryptohomeLibrary* cryptohome = |
129 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); | 120 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
130 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); | 121 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
131 | 122 |
123 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store( | |
124 new DeviceCloudPolicyStoreChromeOS( | |
125 chromeos::DeviceSettingsService::Get(), | |
126 install_attributes_.get())); | |
127 device_cloud_policy_manager_.reset( | |
128 new DeviceCloudPolicyManagerChromeOS( | |
129 device_cloud_policy_store.Pass(), | |
130 install_attributes_.get())); | |
131 | |
132 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 132 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
133 if (!command_line->HasSwitch(switches::kDisableCloudPolicyService)) { | 133 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { |
134 scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store( | 134 device_local_account_policy_service_.reset( |
135 new DeviceCloudPolicyStoreChromeOS( | 135 new DeviceLocalAccountPolicyService( |
136 chromeos::DeviceSettingsService::Get(), | 136 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
137 install_attributes_.get())); | 137 chromeos::DeviceSettingsService::Get())); |
138 device_cloud_policy_manager_.reset( | |
139 new DeviceCloudPolicyManagerChromeOS( | |
140 device_cloud_policy_store.Pass(), | |
141 install_attributes_.get())); | |
142 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { | |
143 device_local_account_policy_service_.reset( | |
144 new DeviceLocalAccountPolicyService( | |
145 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | |
146 chromeos::DeviceSettingsService::Get())); | |
147 } | |
148 } else { | |
149 cloud_provider_.reset(new CloudPolicyProvider(this)); | |
150 } | 138 } |
151 | |
152 InitializeDevicePolicy(); | |
153 #endif | 139 #endif |
154 | 140 |
155 // Complete the initialization once the message loops are spinning. | 141 // Complete the initialization once the message loops are spinning. |
156 MessageLoop::current()->PostTask( | 142 MessageLoop::current()->PostTask( |
157 FROM_HERE, | 143 FROM_HERE, |
158 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 144 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
159 weak_ptr_factory_.GetWeakPtr())); | 145 weak_ptr_factory_.GetWeakPtr())); |
160 | 146 |
161 is_initialized_ = true; | 147 is_initialized_ = true; |
162 } | 148 } |
163 | 149 |
164 void BrowserPolicyConnector::Shutdown() { | 150 void BrowserPolicyConnector::Shutdown() { |
165 is_initialized_ = false; | 151 is_initialized_ = false; |
166 | 152 |
167 if (g_testing_provider) | 153 if (g_testing_provider) |
168 g_testing_provider->Shutdown(); | 154 g_testing_provider->Shutdown(); |
169 // Drop g_testing_provider so that tests executed with --single_process can | 155 // Drop g_testing_provider so that tests executed with --single_process can |
170 // call SetPolicyProviderForTesting() again. It is still owned by the test. | 156 // call SetPolicyProviderForTesting() again. It is still owned by the test. |
171 g_testing_provider = NULL; | 157 g_testing_provider = NULL; |
172 if (platform_provider_) | 158 if (platform_provider_) |
173 platform_provider_->Shutdown(); | 159 platform_provider_->Shutdown(); |
174 // The |cloud_provider_| must be shut down before destroying the cloud | |
175 // policy subsystems, which own the caches that |cloud_provider_| uses. | |
176 if (cloud_provider_) | |
177 cloud_provider_->Shutdown(); | |
178 | 160 |
179 #if defined(OS_CHROMEOS) | 161 #if defined(OS_CHROMEOS) |
180 // Shutdown device cloud policy. | |
181 if (device_cloud_policy_subsystem_) | |
182 device_cloud_policy_subsystem_->Shutdown(); | |
183 // The AppPackUpdater may be observing the |device_cloud_policy_subsystem_|. | 162 // The AppPackUpdater may be observing the |device_cloud_policy_subsystem_|. |
184 // Delete it first. | 163 // Delete it first. |
185 app_pack_updater_.reset(); | 164 app_pack_updater_.reset(); |
186 device_cloud_policy_subsystem_.reset(); | |
187 device_data_store_.reset(); | |
188 | 165 |
189 if (device_cloud_policy_manager_) | 166 if (device_cloud_policy_manager_) |
190 device_cloud_policy_manager_->Shutdown(); | 167 device_cloud_policy_manager_->Shutdown(); |
191 if (device_local_account_policy_provider_) | 168 if (device_local_account_policy_provider_) |
192 device_local_account_policy_provider_->Shutdown(); | 169 device_local_account_policy_provider_->Shutdown(); |
193 if (device_local_account_policy_service_) | 170 if (device_local_account_policy_service_) |
194 device_local_account_policy_service_->Disconnect(); | 171 device_local_account_policy_service_->Disconnect(); |
195 if (user_cloud_policy_manager_) | 172 if (user_cloud_policy_manager_) |
196 user_cloud_policy_manager_->Shutdown(); | 173 user_cloud_policy_manager_->Shutdown(); |
197 global_user_cloud_policy_provider_.Shutdown(); | 174 global_user_cloud_policy_provider_.Shutdown(); |
198 #endif | 175 #endif |
199 | 176 |
200 // Shutdown user cloud policy. | |
201 if (user_cloud_policy_subsystem_) | |
202 user_cloud_policy_subsystem_->Shutdown(); | |
203 user_cloud_policy_subsystem_.reset(); | |
204 user_policy_token_cache_.reset(); | |
205 user_data_store_.reset(); | |
206 | |
207 device_management_service_.reset(); | 177 device_management_service_.reset(); |
208 } | 178 } |
209 | 179 |
210 scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( | 180 scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( |
211 Profile* profile) { | 181 Profile* profile) { |
212 DCHECK(profile); | 182 DCHECK(profile); |
213 ConfigurationPolicyProvider* user_cloud_policy_provider = NULL; | 183 ConfigurationPolicyProvider* user_cloud_policy_provider = NULL; |
214 #if defined(OS_CHROMEOS) | 184 #if defined(OS_CHROMEOS) |
215 user_cloud_policy_provider = user_cloud_policy_manager_.get(); | 185 user_cloud_policy_provider = user_cloud_policy_manager_.get(); |
216 #else | 186 #else |
217 user_cloud_policy_provider = | 187 user_cloud_policy_provider = |
218 UserCloudPolicyManagerFactory::GetForProfile(profile); | 188 UserCloudPolicyManagerFactory::GetForProfile(profile); |
219 #endif | 189 #endif |
220 return CreatePolicyServiceWithProviders( | 190 return CreatePolicyServiceWithProviders( |
221 user_cloud_policy_provider, | 191 user_cloud_policy_provider, |
222 profile->GetManagedModePolicyProvider()); | 192 profile->GetManagedModePolicyProvider()); |
223 } | 193 } |
224 | 194 |
225 PolicyService* BrowserPolicyConnector::GetPolicyService() { | 195 PolicyService* BrowserPolicyConnector::GetPolicyService() { |
226 if (!policy_service_) | 196 if (!policy_service_) |
227 policy_service_ = CreatePolicyServiceWithProviders(NULL, NULL); | 197 policy_service_ = CreatePolicyServiceWithProviders(NULL, NULL); |
228 return policy_service_.get(); | 198 return policy_service_.get(); |
229 } | 199 } |
230 | 200 |
231 void BrowserPolicyConnector::RegisterForDevicePolicy( | |
232 const std::string& owner_email, | |
233 const std::string& token, | |
234 bool known_machine_id, | |
235 bool reregister) { | |
236 #if defined(OS_CHROMEOS) | 201 #if defined(OS_CHROMEOS) |
237 if (device_data_store_.get()) { | |
238 if (!device_data_store_->device_token().empty()) { | |
239 LOG(ERROR) << "Device policy data store already has a DMToken; " | |
240 << "RegisterForDevicePolicy won't trigger a new registration."; | |
241 } | |
242 | |
243 device_data_store_->set_user_name(owner_email); | |
244 device_data_store_->set_known_machine_id(known_machine_id); | |
245 if (reregister) { | |
246 device_data_store_->set_device_id(install_attributes_->GetDeviceId()); | |
247 device_data_store_->set_reregister(true); | |
248 } | |
249 device_data_store_->set_policy_fetching_enabled(false); | |
250 device_data_store_->SetOAuthToken(token); | |
251 } | |
252 #endif | |
253 } | |
254 | |
255 bool BrowserPolicyConnector::IsEnterpriseManaged() { | 202 bool BrowserPolicyConnector::IsEnterpriseManaged() { |
256 #if defined(OS_CHROMEOS) | 203 return install_attributes_->IsEnterpriseDevice(); |
257 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); | |
258 #else | |
259 return false; | |
260 #endif | |
261 } | |
262 | |
263 EnterpriseInstallAttributes::LockResult | |
264 BrowserPolicyConnector::LockDevice(const std::string& user) { | |
265 #if defined(OS_CHROMEOS) | |
266 if (install_attributes_.get()) { | |
267 return install_attributes_->LockDevice(user, | |
268 device_data_store_->device_mode(), | |
269 device_data_store_->device_id()); | |
270 } | |
271 #endif | |
272 | |
273 return EnterpriseInstallAttributes::LOCK_BACKEND_ERROR; | |
274 } | 204 } |
275 | 205 |
276 std::string BrowserPolicyConnector::GetEnterpriseDomain() { | 206 std::string BrowserPolicyConnector::GetEnterpriseDomain() { |
277 #if defined(OS_CHROMEOS) | 207 return install_attributes_->GetDomain(); |
278 if (install_attributes_.get()) | |
279 return install_attributes_->GetDomain(); | |
280 #endif | |
281 | |
282 return std::string(); | |
283 } | 208 } |
284 | 209 |
285 DeviceMode BrowserPolicyConnector::GetDeviceMode() { | 210 DeviceMode BrowserPolicyConnector::GetDeviceMode() { |
286 #if defined(OS_CHROMEOS) | 211 return install_attributes_->GetMode(); |
287 if (install_attributes_.get()) | 212 } |
288 return install_attributes_->GetMode(); | |
289 else | |
290 return DEVICE_MODE_NOT_SET; | |
291 #endif | 213 #endif |
292 | 214 |
293 // We only have the notion of "enterprise" device on ChromeOS for now. | |
294 return DEVICE_MODE_CONSUMER; | |
295 } | |
296 | |
297 void BrowserPolicyConnector::ResetDevicePolicy() { | |
298 #if defined(OS_CHROMEOS) | |
299 if (device_cloud_policy_subsystem_.get()) | |
300 device_cloud_policy_subsystem_->Reset(); | |
301 #endif | |
302 } | |
303 | |
304 void BrowserPolicyConnector::FetchCloudPolicy() { | |
305 #if defined(OS_CHROMEOS) | |
306 if (device_cloud_policy_subsystem_.get()) | |
307 device_cloud_policy_subsystem_->RefreshPolicies(false); | |
308 if (user_cloud_policy_subsystem_.get()) | |
309 user_cloud_policy_subsystem_->RefreshPolicies(true); // wait_for_auth_token | |
310 #endif | |
311 } | |
312 | |
313 void BrowserPolicyConnector::ScheduleServiceInitialization( | 215 void BrowserPolicyConnector::ScheduleServiceInitialization( |
314 int64 delay_milliseconds) { | 216 int64 delay_milliseconds) { |
315 if (device_management_service_.get()) | 217 device_management_service_->ScheduleInitialization(delay_milliseconds); |
316 device_management_service_->ScheduleInitialization(delay_milliseconds); | |
317 if (user_cloud_policy_subsystem_.get()) { | |
318 user_cloud_policy_subsystem_-> | |
319 ScheduleServiceInitialization(delay_milliseconds); | |
320 } | |
321 #if defined(OS_CHROMEOS) | |
322 if (device_cloud_policy_subsystem_.get()) { | |
323 device_cloud_policy_subsystem_-> | |
324 ScheduleServiceInitialization(delay_milliseconds); | |
325 } | |
326 #endif | |
327 } | 218 } |
328 | 219 |
220 #if defined(OS_CHROMEOS) | |
329 void BrowserPolicyConnector::InitializeUserPolicy( | 221 void BrowserPolicyConnector::InitializeUserPolicy( |
330 const std::string& user_name, | 222 const std::string& user_name, |
331 bool is_public_account, | 223 bool is_public_account, |
332 bool wait_for_policy_fetch) { | 224 bool wait_for_policy_fetch) { |
333 #if defined(OS_CHROMEOS) | |
334 // If the user is managed then importing certificates from ONC policy is | 225 // If the user is managed then importing certificates from ONC policy is |
335 // allowed, otherwise it's not. Update this flag once the user has signed in, | 226 // allowed, otherwise it's not. Update this flag once the user has signed in, |
336 // and before user policy is loaded. | 227 // and before user policy is loaded. |
337 GetNetworkConfigurationUpdater()->set_allow_web_trust( | 228 GetNetworkConfigurationUpdater()->set_allow_web_trust( |
338 GetUserAffiliation(user_name) == USER_AFFILIATION_MANAGED); | 229 GetUserAffiliation(user_name) == USER_AFFILIATION_MANAGED); |
339 | 230 |
340 // Re-initializing user policy is disallowed for two reasons: | 231 // Re-initializing user policy is disallowed for two reasons: |
341 // (a) Existing profiles may hold pointers to |user_cloud_policy_manager_|. | 232 // (a) Existing profiles may hold pointers to |user_cloud_policy_manager_|. |
342 // (b) Implementing UserCloudPolicyManager::IsInitializationComplete() | 233 // (b) Implementing UserCloudPolicyManager::IsInitializationComplete() |
343 // correctly is impossible for re-initialization. | 234 // correctly is impossible for re-initialization. |
344 CHECK(!user_cloud_policy_manager_.get()); | 235 CHECK(!user_cloud_policy_manager_.get()); |
345 #endif | |
346 | |
347 // Throw away the old backend. | |
348 user_cloud_policy_subsystem_.reset(); | |
349 user_policy_token_cache_.reset(); | |
350 user_data_store_.reset(); | |
351 token_service_ = NULL; | |
352 registrar_.RemoveAll(); | |
353 | 236 |
354 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 237 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
355 | 238 |
356 int64 startup_delay = | 239 int64 startup_delay = |
357 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; | 240 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
358 | 241 |
359 FilePath profile_dir; | 242 FilePath profile_dir; |
360 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | 243 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
361 #if defined(OS_CHROMEOS) | |
362 profile_dir = profile_dir.Append( | 244 profile_dir = profile_dir.Append( |
363 command_line->GetSwitchValuePath(switches::kLoginProfile)); | 245 command_line->GetSwitchValuePath(switches::kLoginProfile)); |
364 #endif | |
365 const FilePath policy_dir = profile_dir.Append(kPolicyDir); | 246 const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
366 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); | 247 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
367 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); | 248 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
368 | 249 |
369 if (!command_line->HasSwitch(switches::kDisableCloudPolicyService)) { | 250 device_management_service_->ScheduleInitialization(startup_delay); |
370 #if defined(OS_CHROMEOS) | 251 if (is_public_account && device_local_account_policy_service_.get()) { |
371 device_management_service_->ScheduleInitialization(startup_delay); | 252 device_local_account_policy_provider_.reset( |
372 if (is_public_account && device_local_account_policy_service_.get()) { | 253 new DeviceLocalAccountPolicyProvider( |
373 device_local_account_policy_provider_.reset( | 254 user_name, device_local_account_policy_service_.get())); |
374 new DeviceLocalAccountPolicyProvider( | |
375 user_name, device_local_account_policy_service_.get())); | |
376 | 255 |
377 device_local_account_policy_provider_->Init(); | 256 device_local_account_policy_provider_->Init(); |
378 global_user_cloud_policy_provider_.SetDelegate( | 257 global_user_cloud_policy_provider_.SetDelegate( |
379 device_local_account_policy_provider_.get()); | 258 device_local_account_policy_provider_.get()); |
380 } else if (!IsNonEnterpriseUser(user_name)) { | 259 } else if (!IsNonEnterpriseUser(user_name)) { |
381 scoped_ptr<CloudPolicyStore> store( | 260 scoped_ptr<CloudPolicyStore> store( |
382 new UserCloudPolicyStoreChromeOS( | 261 new UserCloudPolicyStoreChromeOS( |
383 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | 262 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
384 user_name, policy_cache_file, token_cache_file)); | 263 user_name, policy_cache_file, token_cache_file)); |
385 user_cloud_policy_manager_.reset( | 264 user_cloud_policy_manager_.reset( |
386 new UserCloudPolicyManagerChromeOS(store.Pass(), | 265 new UserCloudPolicyManagerChromeOS(store.Pass(), |
387 wait_for_policy_fetch)); | 266 wait_for_policy_fetch)); |
388 | 267 |
389 user_cloud_policy_manager_->Init(); | 268 user_cloud_policy_manager_->Init(); |
390 user_cloud_policy_manager_->Connect(g_browser_process->local_state(), | 269 user_cloud_policy_manager_->Connect(g_browser_process->local_state(), |
391 device_management_service_.get(), | 270 device_management_service_.get(), |
392 GetUserAffiliation(user_name)); | 271 GetUserAffiliation(user_name)); |
393 global_user_cloud_policy_provider_.SetDelegate( | 272 global_user_cloud_policy_provider_.SetDelegate( |
394 user_cloud_policy_manager_.get()); | 273 user_cloud_policy_manager_.get()); |
395 } | |
396 #endif | |
397 } else { | |
398 CloudPolicyCacheBase* user_policy_cache = NULL; | |
399 | |
400 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | |
401 #if defined(OS_CHROMEOS) | |
402 user_policy_cache = | |
403 new CrosUserPolicyCache( | |
404 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | |
405 user_data_store_.get(), | |
406 wait_for_policy_fetch, | |
407 token_cache_file, | |
408 policy_cache_file); | |
409 #else | |
410 user_policy_cache = new UserPolicyCache(policy_cache_file, | |
411 wait_for_policy_fetch); | |
412 user_policy_token_cache_.reset( | |
413 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); | |
414 | |
415 // Initiate the DM-Token load. | |
416 user_policy_token_cache_->Load(); | |
417 #endif | |
418 | |
419 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | |
420 user_data_store_.get(), | |
421 user_policy_cache, | |
422 GetDeviceManagementUrl())); | |
423 | |
424 user_data_store_->set_user_name(user_name); | |
425 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | |
426 | |
427 user_cloud_policy_subsystem_->CompleteInitialization( | |
428 prefs::kUserPolicyRefreshRate, | |
429 startup_delay); | |
430 | |
431 cloud_provider_->SetUserPolicyCache(user_policy_cache); | |
432 } | 274 } |
433 } | 275 } |
434 | |
435 void BrowserPolicyConnector::SetUserPolicyTokenService( | |
436 TokenService* token_service) { | |
437 token_service_ = token_service; | |
438 registrar_.Add(this, | |
439 chrome::NOTIFICATION_TOKEN_AVAILABLE, | |
440 content::Source<TokenService>(token_service_)); | |
441 | |
442 if (token_service_->HasTokenForService( | |
443 GaiaConstants::kDeviceManagementService)) { | |
444 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( | |
445 GaiaConstants::kDeviceManagementService)); | |
446 } | |
447 } | |
448 | |
449 void BrowserPolicyConnector::RegisterForUserPolicy( | |
450 const std::string& oauth_token) { | |
451 if (oauth_token.empty()) { | |
452 // An attempt to fetch the dm service oauth token has failed. Notify | |
453 // the user policy cache of this, so that a potential blocked login | |
454 // proceeds without waiting for user policy. | |
455 if (user_cloud_policy_subsystem_.get()) { | |
456 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> | |
457 SetFetchingDone(); | |
458 } | |
459 } else { | |
460 if (user_data_store_.get()) | |
461 user_data_store_->SetOAuthToken(oauth_token); | |
462 } | |
463 } | |
464 | |
465 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { | |
466 #if defined(OS_CHROMEOS) | |
467 return device_data_store_.get(); | |
468 #else | |
469 return NULL; | |
470 #endif | 276 #endif |
471 } | |
472 | |
473 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { | |
474 return user_data_store_.get(); | |
475 } | |
476 | 277 |
477 const ConfigurationPolicyHandlerList* | 278 const ConfigurationPolicyHandlerList* |
478 BrowserPolicyConnector::GetHandlerList() const { | 279 BrowserPolicyConnector::GetHandlerList() const { |
479 return &handler_list_; | 280 return &handler_list_; |
480 } | 281 } |
481 | 282 |
482 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( | 283 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( |
483 const std::string& user_name) { | 284 const std::string& user_name) { |
484 #if defined(OS_CHROMEOS) | 285 #if defined(OS_CHROMEOS) |
485 if (install_attributes_.get() && | 286 if (install_attributes_.get() && |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 const string16 domain = | 389 const string16 domain = |
589 UTF8ToUTF16(gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); | 390 UTF8ToUTF16(gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); |
590 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { | 391 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { |
591 string16 pattern = WideToUTF16(kNonManagedDomainPatterns[i]); | 392 string16 pattern = WideToUTF16(kNonManagedDomainPatterns[i]); |
592 if (MatchDomain(domain, pattern)) | 393 if (MatchDomain(domain, pattern)) |
593 return true; | 394 return true; |
594 } | 395 } |
595 return false; | 396 return false; |
596 } | 397 } |
597 | 398 |
598 void BrowserPolicyConnector::Observe( | |
599 int type, | |
600 const content::NotificationSource& source, | |
601 const content::NotificationDetails& details) { | |
602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
603 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | |
604 const TokenService* token_source = | |
605 content::Source<const TokenService>(source).ptr(); | |
606 DCHECK_EQ(token_service_, token_source); | |
607 const TokenService::TokenAvailableDetails* token_details = | |
608 content::Details<const TokenService::TokenAvailableDetails>(details). | |
609 ptr(); | |
610 if (token_details->service() == GaiaConstants::kDeviceManagementService) { | |
611 if (user_data_store_.get()) { | |
612 user_data_store_->SetGaiaToken(token_details->token()); | |
613 } | |
614 } | |
615 } else { | |
616 NOTREACHED(); | |
617 } | |
618 } | |
619 | |
620 void BrowserPolicyConnector::InitializeDevicePolicy() { | |
621 #if defined(OS_CHROMEOS) | |
622 // Throw away the old backend. | |
623 device_cloud_policy_subsystem_.reset(); | |
624 device_data_store_.reset(); | |
625 | |
626 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
627 if (command_line->HasSwitch(switches::kDisableCloudPolicyService)) { | |
628 device_data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies()); | |
629 DevicePolicyCache* device_policy_cache = | |
630 new DevicePolicyCache(device_data_store_.get(), | |
631 install_attributes_.get()); | |
632 | |
633 cloud_provider_->SetDevicePolicyCache(device_policy_cache); | |
634 | |
635 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | |
636 device_data_store_.get(), | |
637 device_policy_cache, | |
638 GetDeviceManagementUrl())); | |
639 } | |
640 #endif | |
641 } | |
642 | |
643 void BrowserPolicyConnector::CompleteInitialization() { | 399 void BrowserPolicyConnector::CompleteInitialization() { |
644 if (g_testing_provider) | 400 if (g_testing_provider) |
645 g_testing_provider->Init(); | 401 g_testing_provider->Init(); |
646 if (platform_provider_) | 402 if (platform_provider_) |
647 platform_provider_->Init(); | 403 platform_provider_->Init(); |
648 if (cloud_provider_) | |
649 cloud_provider_->Init(); | |
650 | 404 |
651 #if defined(OS_CHROMEOS) | 405 #if defined(OS_CHROMEOS) |
652 global_user_cloud_policy_provider_.Init(); | 406 global_user_cloud_policy_provider_.Init(); |
653 | 407 |
654 // Create the AppPackUpdater to start updating the cache. It requires the | 408 // Create the AppPackUpdater to start updating the cache. It requires the |
655 // system request context, which isn't available in Init(); therefore it is | 409 // system request context, which isn't available in Init(); therefore it is |
656 // created only once the loops are running. | 410 // created only once the loops are running. |
657 GetAppPackUpdater(); | 411 GetAppPackUpdater(); |
658 | 412 |
659 if (device_cloud_policy_subsystem_.get()) { | |
660 // Read serial number and machine model. This must be done before we call | |
661 // CompleteInitialization() below such that the serial number is available | |
662 // for re-submission in case we're doing serial number recovery. | |
663 if (device_data_store_->machine_id().empty() || | |
664 device_data_store_->machine_model().empty()) { | |
665 device_data_store_->set_machine_id( | |
666 DeviceCloudPolicyManagerChromeOS::GetMachineID()); | |
667 device_data_store_->set_machine_model( | |
668 DeviceCloudPolicyManagerChromeOS::GetMachineModel()); | |
669 } | |
670 | |
671 device_cloud_policy_subsystem_->CompleteInitialization( | |
672 prefs::kDevicePolicyRefreshRate, | |
673 kServiceInitializationStartupDelay); | |
674 } | |
675 | |
676 if (device_data_store_.get()) { | |
677 device_data_store_->set_device_status_collector( | |
678 new DeviceStatusCollector( | |
679 g_browser_process->local_state(), | |
680 chromeos::system::StatisticsProvider::GetInstance(), | |
681 NULL)); | |
682 } | |
683 | |
684 if (device_cloud_policy_manager_.get()) { | 413 if (device_cloud_policy_manager_.get()) { |
685 device_cloud_policy_manager_->Init(); | 414 device_cloud_policy_manager_->Init(); |
686 scoped_ptr<CloudPolicyClient::StatusProvider> status_provider( | 415 scoped_ptr<CloudPolicyClient::StatusProvider> status_provider( |
687 new DeviceStatusCollector(g_browser_process->local_state(), | 416 new DeviceStatusCollector(g_browser_process->local_state(), |
688 chromeos::system::StatisticsProvider::GetInstance(), | 417 chromeos::system::StatisticsProvider::GetInstance(), |
689 NULL)); | 418 NULL)); |
690 device_cloud_policy_manager_->Connect( | 419 device_cloud_policy_manager_->Connect( |
691 g_browser_process->local_state(), | 420 g_browser_process->local_state(), |
692 device_management_service_.get(), | 421 device_management_service_.get(), |
693 status_provider.Pass()); | 422 status_provider.Pass()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 BrowserPolicyConnector::CreatePolicyServiceWithProviders( | 464 BrowserPolicyConnector::CreatePolicyServiceWithProviders( |
736 ConfigurationPolicyProvider* user_cloud_policy_provider, | 465 ConfigurationPolicyProvider* user_cloud_policy_provider, |
737 ConfigurationPolicyProvider* managed_mode_policy_provider) { | 466 ConfigurationPolicyProvider* managed_mode_policy_provider) { |
738 PolicyServiceImpl::Providers providers; | 467 PolicyServiceImpl::Providers providers; |
739 if (g_testing_provider) { | 468 if (g_testing_provider) { |
740 providers.push_back(g_testing_provider); | 469 providers.push_back(g_testing_provider); |
741 } else { | 470 } else { |
742 // |providers| in decreasing order of priority. | 471 // |providers| in decreasing order of priority. |
743 if (platform_provider_) | 472 if (platform_provider_) |
744 providers.push_back(platform_provider_.get()); | 473 providers.push_back(platform_provider_.get()); |
745 if (cloud_provider_) | |
746 providers.push_back(cloud_provider_.get()); | |
747 | 474 |
748 #if defined(OS_CHROMEOS) | 475 #if defined(OS_CHROMEOS) |
749 if (device_cloud_policy_manager_.get()) | 476 if (device_cloud_policy_manager_.get()) |
750 providers.push_back(device_cloud_policy_manager_.get()); | 477 providers.push_back(device_cloud_policy_manager_.get()); |
751 if (!user_cloud_policy_provider) | 478 if (!user_cloud_policy_provider) |
752 user_cloud_policy_provider = &global_user_cloud_policy_provider_; | 479 user_cloud_policy_provider = &global_user_cloud_policy_provider_; |
753 #endif | 480 #endif |
754 | 481 |
755 if (user_cloud_policy_provider) | 482 if (user_cloud_policy_provider) |
756 providers.push_back(user_cloud_policy_provider); | 483 providers.push_back(user_cloud_policy_provider); |
(...skipping 23 matching lines...) Expand all Loading... | |
780 return new AsyncPolicyProvider(loader.Pass()); | 507 return new AsyncPolicyProvider(loader.Pass()); |
781 } else { | 508 } else { |
782 return NULL; | 509 return NULL; |
783 } | 510 } |
784 #else | 511 #else |
785 return NULL; | 512 return NULL; |
786 #endif | 513 #endif |
787 } | 514 } |
788 | 515 |
789 } // namespace policy | 516 } // namespace policy |
OLD | NEW |