OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
10 #include "chrome/browser/policy/cloud_policy_data_store.h" | 10 #include "chrome/browser/policy/cloud_policy_data_store.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 29 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
30 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
31 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 31 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
32 #elif defined(OS_POSIX) | 32 #elif defined(OS_POSIX) |
33 #include "chrome/browser/policy/config_dir_policy_provider.h" | 33 #include "chrome/browser/policy/config_dir_policy_provider.h" |
34 #endif | 34 #endif |
35 | 35 |
36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
37 #include "chrome/browser/chromeos/cros/cros_library.h" | 37 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 38 #include "chrome/browser/policy/cros_user_policy_cache.h" |
38 #include "chrome/browser/policy/device_policy_cache.h" | 39 #include "chrome/browser/policy/device_policy_cache.h" |
39 #endif | 40 #endif |
40 | 41 |
41 namespace policy { | 42 namespace policy { |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 // Subdirectory in the user's profile for storing user policies. | 46 // Subdirectory in the user's profile for storing user policies. |
46 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 47 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
47 // File in the above directory for stroing user policy dmtokens. | 48 // File in the above directory for stroing user policy dmtokens. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void BrowserPolicyConnector::FetchDevicePolicy() { | 227 void BrowserPolicyConnector::FetchDevicePolicy() { |
227 #if defined(OS_CHROMEOS) | 228 #if defined(OS_CHROMEOS) |
228 if (device_data_store_.get()) { | 229 if (device_data_store_.get()) { |
229 DCHECK(!device_data_store_->device_token().empty()); | 230 DCHECK(!device_data_store_->device_token().empty()); |
230 device_data_store_->NotifyDeviceTokenChanged(); | 231 device_data_store_->NotifyDeviceTokenChanged(); |
231 } | 232 } |
232 #endif | 233 #endif |
233 } | 234 } |
234 | 235 |
235 void BrowserPolicyConnector::InitializeUserPolicy(const std::string& user_name, | 236 void BrowserPolicyConnector::InitializeUserPolicy(const std::string& user_name, |
236 const FilePath& policy_dir, | 237 const FilePath& profile_dir, |
237 TokenService* token_service) { | 238 TokenService* token_service) { |
238 DCHECK(token_service); | 239 DCHECK(token_service); |
239 | 240 |
240 // Throw away the old backend. | 241 // Throw away the old backend. |
241 user_cloud_policy_subsystem_.reset(); | 242 user_cloud_policy_subsystem_.reset(); |
242 user_policy_token_cache_.reset(); | 243 user_policy_token_cache_.reset(); |
243 user_data_store_.reset(); | 244 user_data_store_.reset(); |
244 registrar_.RemoveAll(); | 245 registrar_.RemoveAll(); |
245 | 246 |
246 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 247 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
247 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 248 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
248 token_service_ = token_service; | 249 token_service_ = token_service; |
249 registrar_.Add(this, | 250 registrar_.Add(this, |
250 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 251 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
251 Source<TokenService>(token_service_)); | 252 Source<TokenService>(token_service_)); |
252 | 253 |
253 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); | |
254 UserPolicyCache* user_policy_cache = | |
255 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); | |
256 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 254 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| 255 |
| 256 const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| 257 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| 258 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| 259 CloudPolicyCacheBase* user_policy_cache = NULL; |
| 260 |
| 261 #if defined(OS_CHROMEOS) |
| 262 user_policy_cache = |
| 263 new CrosUserPolicyCache(chromeos::CrosLibrary::Get()->GetLoginLibrary(), |
| 264 user_data_store_.get(), |
| 265 token_cache_file, |
| 266 policy_cache_file); |
| 267 #else |
| 268 user_policy_cache = new UserPolicyCache(policy_cache_file); |
257 user_policy_token_cache_.reset( | 269 user_policy_token_cache_.reset( |
258 new UserPolicyTokenCache(user_data_store_.get(), | 270 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); |
259 policy_cache_dir.Append(kTokenCacheFile))); | 271 |
| 272 // Initiate the DM-Token load. |
| 273 user_policy_token_cache_->Load(); |
| 274 #endif |
260 | 275 |
261 // Prepending user caches meaning they will take precedence of device policy | 276 // Prepending user caches meaning they will take precedence of device policy |
262 // caches. | 277 // caches. |
263 managed_cloud_provider_->PrependCache(user_policy_cache); | 278 managed_cloud_provider_->PrependCache(user_policy_cache); |
264 recommended_cloud_provider_->PrependCache(user_policy_cache); | 279 recommended_cloud_provider_->PrependCache(user_policy_cache); |
265 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 280 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
266 user_data_store_.get(), | 281 user_data_store_.get(), |
267 user_policy_cache)); | 282 user_policy_cache)); |
268 | 283 |
269 // Initiate the DM-Token load. | |
270 user_policy_token_cache_->Load(); | |
271 | |
272 user_data_store_->set_user_name(user_name); | 284 user_data_store_->set_user_name(user_name); |
273 if (token_service_->HasTokenForService( | 285 if (token_service_->HasTokenForService( |
274 GaiaConstants::kDeviceManagementService)) { | 286 GaiaConstants::kDeviceManagementService)) { |
275 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( | 287 user_data_store_->SetGaiaToken(token_service_->GetTokenForService( |
276 GaiaConstants::kDeviceManagementService)); | 288 GaiaConstants::kDeviceManagementService)); |
277 } | 289 } |
278 | 290 |
279 user_cloud_policy_subsystem_->CompleteInitialization( | 291 user_cloud_policy_subsystem_->CompleteInitialization( |
280 prefs::kUserPolicyRefreshRate, | 292 prefs::kUserPolicyRefreshRate, |
281 kServiceInitializationStartupDelay); | 293 kServiceInitializationStartupDelay); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 if (user_data_store_.get()) { | 363 if (user_data_store_.get()) { |
352 user_data_store_->SetGaiaToken(token_details->token()); | 364 user_data_store_->SetGaiaToken(token_details->token()); |
353 } | 365 } |
354 } | 366 } |
355 } else { | 367 } else { |
356 NOTREACHED(); | 368 NOTREACHED(); |
357 } | 369 } |
358 } | 370 } |
359 | 371 |
360 } // namespace | 372 } // namespace |
OLD | NEW |