| 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/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/policy/async_policy_provider.h" | 13 #include "chrome/browser/policy/async_policy_provider.h" |
| 14 #include "chrome/browser/policy/cloud_policy_client.h" | 14 #include "chrome/browser/policy/cloud_policy_client.h" |
| 15 #include "chrome/browser/policy/cloud_policy_provider.h" | 15 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 16 #include "chrome/browser/policy/cloud_policy_service.h" | 16 #include "chrome/browser/policy/cloud_policy_service.h" |
| 17 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 17 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
| 18 #include "chrome/browser/policy/configuration_policy_provider.h" | 18 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 19 #include "chrome/browser/policy/device_management_service.h" | 19 #include "chrome/browser/policy/device_management_service.h" |
| 20 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 20 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| 21 #include "chrome/browser/policy/managed_mode_policy_provider_factory.h" | 21 #include "chrome/browser/policy/managed_mode_policy_provider_factory.h" |
| 22 #include "chrome/browser/policy/policy_service_impl.h" | 22 #include "chrome/browser/policy/policy_service_impl.h" |
| 23 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 23 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
| 24 #include "chrome/browser/policy/user_policy_cache.h" | 24 #include "chrome/browser/policy/user_policy_cache.h" |
| 25 #include "chrome/browser/policy/user_policy_token_cache.h" | 25 #include "chrome/browser/policy/user_policy_token_cache.h" |
| 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/signin/token_service.h" | 27 #include "chrome/browser/signin/token_service.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/net/gaia/gaia_auth_util.h" |
| 30 #include "chrome/common/net/gaia/gaia_constants.h" | 32 #include "chrome/common/net/gaia/gaia_constants.h" |
| 31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 32 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 34 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 35 #include "policy/policy_constants.h" | 37 #include "policy/policy_constants.h" |
| 36 | 38 |
| 37 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 38 #include "chrome/browser/policy/policy_loader_win.h" | 40 #include "chrome/browser/policy/policy_loader_win.h" |
| 39 #elif defined(OS_MACOSX) | 41 #elif defined(OS_MACOSX) |
| 40 #include "chrome/browser/policy/policy_loader_mac.h" | 42 #include "chrome/browser/policy/policy_loader_mac.h" |
| 41 #include "chrome/browser/preferences_mac.h" | 43 #include "chrome/browser/preferences_mac.h" |
| 42 #elif defined(OS_POSIX) | 44 #elif defined(OS_POSIX) |
| 43 #include "chrome/browser/policy/config_dir_policy_loader.h" | 45 #include "chrome/browser/policy/config_dir_policy_loader.h" |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 46 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 47 #include "chrome/browser/chromeos/cros/cros_library.h" | 49 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 50 #include "chrome/browser/chromeos/login/authenticator.h" |
| 51 #include "chrome/browser/chromeos/login/user_manager.h" |
| 48 #include "chrome/browser/chromeos/system/statistics_provider.h" | 52 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 49 #include "chrome/browser/policy/app_pack_updater.h" | 53 #include "chrome/browser/policy/app_pack_updater.h" |
| 50 #include "chrome/browser/policy/cros_user_policy_cache.h" | 54 #include "chrome/browser/policy/cros_user_policy_cache.h" |
| 51 #include "chrome/browser/policy/device_policy_cache.h" | 55 #include "chrome/browser/policy/device_policy_cache.h" |
| 52 #include "chromeos/dbus/dbus_thread_manager.h" | 56 #include "chromeos/dbus/dbus_thread_manager.h" |
| 53 #endif | 57 #endif |
| 54 | 58 |
| 55 using content::BrowserThread; | 59 using content::BrowserThread; |
| 56 | 60 |
| 57 namespace policy { | 61 namespace policy { |
| 58 | 62 |
| 59 namespace { | 63 namespace { |
| 60 | 64 |
| 61 // Subdirectory in the user's profile for storing user policies. | 65 // Subdirectory in the user's profile for storing user policies. |
| 62 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 66 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
| 63 // File in the above directory for stroing user policy dmtokens. | 67 // File in the above directory for stroing user policy dmtokens. |
| 64 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); | 68 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
| 65 // File in the above directory for storing user policy data. | 69 // File in the above directory for storing user policy data. |
| 66 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); | 70 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
| 67 | 71 |
| 68 // The following constants define delays applied before the initial policy fetch | 72 // The following constants define delays applied before the initial policy fetch |
| 69 // on startup. (So that displaying Chrome's GUI does not get delayed.) | 73 // on startup. (So that displaying Chrome's GUI does not get delayed.) |
| 70 // Delay in milliseconds from startup. | 74 // Delay in milliseconds from startup. |
| 71 const int64 kServiceInitializationStartupDelay = 5000; | 75 const int64 kServiceInitializationStartupDelay = 5000; |
| 72 | 76 |
| 77 // The URL for the device management server. |
| 78 const char kDefaultDeviceManagementServerUrl[] = |
| 79 "https://m.google.com/devicemanagement/data/api"; |
| 80 |
| 73 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
| 74 // MachineInfo key names. | 82 // MachineInfo key names. |
| 75 const char kMachineInfoSystemHwqual[] = "hardware_class"; | 83 const char kMachineInfoSystemHwqual[] = "hardware_class"; |
| 76 | 84 |
| 77 // These are the machine serial number keys that we check in order until we | 85 // These are the machine serial number keys that we check in order until we |
| 78 // find a non-empty serial number. The VPD spec says the serial number should be | 86 // find a non-empty serial number. The VPD spec says the serial number should be |
| 79 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a | 87 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a |
| 80 // different keys to report their serial number, which we fall back to if | 88 // different keys to report their serial number, which we fall back to if |
| 81 // "serial_number" is not present. | 89 // "serial_number" is not present. |
| 82 const char* kMachineInfoSerialNumberKeys[] = { | 90 const char* kMachineInfoSerialNumberKeys[] = { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 device_data_store_.reset(); | 115 device_data_store_.reset(); |
| 108 #endif | 116 #endif |
| 109 | 117 |
| 110 // Shutdown user cloud policy. | 118 // Shutdown user cloud policy. |
| 111 if (user_cloud_policy_subsystem_.get()) | 119 if (user_cloud_policy_subsystem_.get()) |
| 112 user_cloud_policy_subsystem_->Shutdown(); | 120 user_cloud_policy_subsystem_->Shutdown(); |
| 113 user_cloud_policy_subsystem_.reset(); | 121 user_cloud_policy_subsystem_.reset(); |
| 114 user_policy_token_cache_.reset(); | 122 user_policy_token_cache_.reset(); |
| 115 user_data_store_.reset(); | 123 user_data_store_.reset(); |
| 116 | 124 |
| 117 if (user_cloud_policy_manager_.get()) | |
| 118 user_cloud_policy_manager_->Shutdown(); | |
| 119 user_cloud_policy_manager_.reset(); | |
| 120 | |
| 121 device_management_service_.reset(); | 125 device_management_service_.reset(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void BrowserPolicyConnector::Init() { | 128 void BrowserPolicyConnector::Init() { |
| 125 platform_provider_.reset(CreatePlatformProvider()); | 129 DCHECK(!device_management_service_.get()) << |
| 130 "BrowserPolicyConnector::Init() called twice."; |
| 131 // Don't create platform providers if running in a unit test, since |
| 132 // AsyncPlatformLoader requires deletion on the FILE thread. |
| 133 if (MessageLoop::current()) |
| 134 platform_provider_.reset(CreatePlatformProvider()); |
| 135 |
| 136 device_management_service_.reset( |
| 137 new DeviceManagementService(GetDeviceManagementUrl())); |
| 126 | 138 |
| 127 #if defined(OS_CHROMEOS) | 139 #if defined(OS_CHROMEOS) |
| 128 // The CloudPolicyProvider blocks asynchronous Profile creation until a login | |
| 129 // is performed. This is used to ensure that the Profile's PrefService sees | |
| 130 // managed preferences on managed Chrome OS devices. However, this also | |
| 131 // prevents creation of new Profiles in Desktop Chrome. The implementation of | |
| 132 // cloud policy on the Desktop requires a refactoring of the cloud provider, | |
| 133 // but for now it just isn't created. | |
| 134 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 140 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 135 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 141 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| 136 device_management_service_.reset( | 142 managed_cloud_provider_.reset(new CloudPolicyProvider( |
| 137 new DeviceManagementService( | 143 this, |
| 138 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); | 144 POLICY_LEVEL_MANDATORY)); |
| 139 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 145 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| 140 managed_cloud_provider_.reset(new CloudPolicyProvider( | 146 this, |
| 141 this, | 147 POLICY_LEVEL_RECOMMENDED)); |
| 142 POLICY_LEVEL_MANDATORY)); | |
| 143 recommended_cloud_provider_.reset(new CloudPolicyProvider( | |
| 144 this, | |
| 145 POLICY_LEVEL_RECOMMENDED)); | |
| 146 } | |
| 147 } | 148 } |
| 148 | 149 |
| 149 InitializeDevicePolicy(); | 150 InitializeDevicePolicy(); |
| 150 | 151 |
| 152 // Don't bother updating the cache if this is a unit test. |
| 153 if (!MessageLoop::current()) |
| 154 return; |
| 155 |
| 151 // Create the AppPackUpdater to start updating the cache. It requires the | 156 // Create the AppPackUpdater to start updating the cache. It requires the |
| 152 // system request context, which isn't available yet; therefore it is | 157 // system request context, which isn't available yet; therefore it is |
| 153 // created only once the loops are running. | 158 // created only once the loops are running. |
| 154 MessageLoop::current()->PostTask( | 159 MessageLoop::current()->PostTask( |
| 155 FROM_HERE, | 160 FROM_HERE, |
| 156 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), | 161 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), |
| 157 weak_ptr_factory_.GetWeakPtr())); | 162 weak_ptr_factory_.GetWeakPtr())); |
| 158 #endif | 163 #endif |
| 159 } | 164 } |
| 160 | 165 |
| 161 PolicyService* BrowserPolicyConnector::CreatePolicyService( | 166 scoped_ptr<UserCloudPolicyManager> |
| 167 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { |
| 168 scoped_ptr<UserCloudPolicyManager> manager; |
| 169 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 170 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| 171 bool wait_for_policy_fetch = false; |
| 172 #if defined(OS_CHROMEOS) |
| 173 // TODO(mnissler): Revisit once Chrome OS gains multi-profiles support. |
| 174 // Don't wait for a policy fetch if there's no logged in user. |
| 175 if (chromeos::UserManager::Get()->IsUserLoggedIn()) { |
| 176 wait_for_policy_fetch = |
| 177 g_browser_process->browser_policy_connector()->GetUserAffiliation( |
| 178 chromeos::UserManager::Get()->GetLoggedInUser().email()) == |
| 179 policy::USER_AFFILIATION_MANAGED; |
| 180 } |
| 181 #else |
| 182 // On desktop, there's no way to figure out if a user is logged in yet |
| 183 // because prefs are not yet initialized. So we do not block waiting for |
| 184 // the policy fetch to happen (because that would inhibit startup for |
| 185 // non-signed-in users) and instead rely on the fact that a signed-in |
| 186 // profile will already have policy downloaded. If no policy is available |
| 187 // (due to a previous fetch failing), the normal policy refresh mechanism |
| 188 // will cause it to get downloaded eventually. |
| 189 #endif |
| 190 manager = UserCloudPolicyManager::Create(profile, wait_for_policy_fetch); |
| 191 } |
| 192 return manager.Pass(); |
| 193 } |
| 194 |
| 195 scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( |
| 162 Profile* profile) { | 196 Profile* profile) { |
| 163 // |providers| in decreasing order of priority. | 197 // |providers| in decreasing order of priority. |
| 164 PolicyServiceImpl::Providers providers; | 198 PolicyServiceImpl::Providers providers; |
| 165 if (g_testing_provider) | 199 if (g_testing_provider) |
| 166 providers.push_back(g_testing_provider); | 200 providers.push_back(g_testing_provider); |
| 167 if (platform_provider_.get()) | 201 if (platform_provider_.get()) |
| 168 providers.push_back(platform_provider_.get()); | 202 providers.push_back(platform_provider_.get()); |
| 169 if (managed_cloud_provider_.get()) | 203 if (managed_cloud_provider_.get()) |
| 170 providers.push_back(managed_cloud_provider_.get()); | 204 providers.push_back(managed_cloud_provider_.get()); |
| 171 if (recommended_cloud_provider_.get()) | 205 if (recommended_cloud_provider_.get()) |
| 172 providers.push_back(recommended_cloud_provider_.get()); | 206 providers.push_back(recommended_cloud_provider_.get()); |
| 173 | 207 |
| 174 // The global policy service uses the proxy provider to allow for swapping in | 208 // The global policy service uses the proxy provider to allow for swapping in |
| 175 // user policy after startup, while profiles use |user_cloud_policy_manager_| | 209 // user policy after startup, while profiles use |user_cloud_policy_manager_| |
| 176 // directly as their provider, which may also block initialization on a policy | 210 // directly as their provider, which may also block initialization on a policy |
| 177 // fetch at login time. | 211 // fetch at login time. |
| 178 if (profile) { | 212 if (profile) { |
| 179 if (user_cloud_policy_manager_.get()) | 213 UserCloudPolicyManager* manager = profile->GetUserCloudPolicyManager(); |
| 180 providers.push_back(user_cloud_policy_manager_.get()); | 214 if (manager) |
| 215 providers.push_back(manager); |
| 181 | 216 |
| 182 providers.push_back( | 217 providers.push_back( |
| 183 ManagedModePolicyProviderFactory::GetForProfile(profile)); | 218 ManagedModePolicyProviderFactory::GetForProfile(profile)); |
| 184 } else { | 219 } else { |
| 185 providers.push_back(&user_cloud_policy_provider_); | 220 providers.push_back(&user_cloud_policy_provider_); |
| 186 } | 221 } |
| 187 | 222 |
| 188 return new PolicyServiceImpl(providers); | 223 return scoped_ptr<PolicyService>(new PolicyServiceImpl(providers)).Pass(); |
| 189 } | 224 } |
| 190 | 225 |
| 191 void BrowserPolicyConnector::RegisterForDevicePolicy( | 226 void BrowserPolicyConnector::RegisterForDevicePolicy( |
| 192 const std::string& owner_email, | 227 const std::string& owner_email, |
| 193 const std::string& token, | 228 const std::string& token, |
| 194 bool known_machine_id, | 229 bool known_machine_id, |
| 195 bool reregister) { | 230 bool reregister) { |
| 196 #if defined(OS_CHROMEOS) | 231 #if defined(OS_CHROMEOS) |
| 197 if (device_data_store_.get()) { | 232 if (device_data_store_.get()) { |
| 198 if (!device_data_store_->device_token().empty()) { | 233 if (!device_data_store_->device_token().empty()) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 user_cloud_policy_subsystem_-> | 330 user_cloud_policy_subsystem_-> |
| 296 ScheduleServiceInitialization(delay_milliseconds); | 331 ScheduleServiceInitialization(delay_milliseconds); |
| 297 } | 332 } |
| 298 #if defined(OS_CHROMEOS) | 333 #if defined(OS_CHROMEOS) |
| 299 if (device_cloud_policy_subsystem_.get()) { | 334 if (device_cloud_policy_subsystem_.get()) { |
| 300 device_cloud_policy_subsystem_-> | 335 device_cloud_policy_subsystem_-> |
| 301 ScheduleServiceInitialization(delay_milliseconds); | 336 ScheduleServiceInitialization(delay_milliseconds); |
| 302 } | 337 } |
| 303 #endif | 338 #endif |
| 304 } | 339 } |
| 340 |
| 305 void BrowserPolicyConnector::InitializeUserPolicy( | 341 void BrowserPolicyConnector::InitializeUserPolicy( |
| 306 const std::string& user_name, | 342 const std::string& user_name, |
| 307 bool wait_for_policy_fetch) { | 343 bool wait_for_policy_fetch) { |
| 308 // Throw away the old backend. | 344 // Throw away the old backend. |
| 309 user_cloud_policy_manager_.reset(); | |
| 310 | |
| 311 user_cloud_policy_subsystem_.reset(); | 345 user_cloud_policy_subsystem_.reset(); |
| 312 user_policy_token_cache_.reset(); | 346 user_policy_token_cache_.reset(); |
| 313 user_data_store_.reset(); | 347 user_data_store_.reset(); |
| 314 token_service_ = NULL; | 348 token_service_ = NULL; |
| 315 registrar_.RemoveAll(); | 349 registrar_.RemoveAll(); |
| 316 | 350 |
| 317 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 351 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 318 | 352 |
| 319 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 353 int64 startup_delay = |
| 320 int64 startup_delay = | 354 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
| 321 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; | |
| 322 | 355 |
| 323 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 356 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| 357 FilePath profile_dir; |
| 358 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
| 324 #if defined(OS_CHROMEOS) | 359 #if defined(OS_CHROMEOS) |
| 325 user_cloud_policy_manager_ = | 360 profile_dir = profile_dir.Append( |
| 326 UserCloudPolicyManager::Create(wait_for_policy_fetch); | 361 command_line->GetSwitchValuePath(switches::kLoginProfile)); |
| 327 user_cloud_policy_manager_->Initialize(g_browser_process->local_state(), | 362 #endif |
| 328 device_management_service_.get(), | 363 const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| 329 GetUserAffiliation(user_name)); | 364 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| 330 user_cloud_policy_provider_.SetDelegate(user_cloud_policy_manager_.get()); | 365 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| 366 CloudPolicyCacheBase* user_policy_cache = NULL; |
| 331 | 367 |
| 332 device_management_service_->ScheduleInitialization(startup_delay); | 368 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
| 333 #endif | |
| 334 } else { | |
| 335 FilePath profile_dir; | |
| 336 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | |
| 337 #if defined(OS_CHROMEOS) | 369 #if defined(OS_CHROMEOS) |
| 338 profile_dir = profile_dir.Append( | 370 user_policy_cache = |
| 339 command_line->GetSwitchValuePath(switches::kLoginProfile)); | 371 new CrosUserPolicyCache( |
| 340 #endif | 372 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| 341 const FilePath policy_dir = profile_dir.Append(kPolicyDir); | 373 user_data_store_.get(), |
| 342 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); | 374 wait_for_policy_fetch, |
| 343 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); | 375 token_cache_file, |
| 344 CloudPolicyCacheBase* user_policy_cache = NULL; | 376 policy_cache_file); |
| 377 #else |
| 378 user_policy_cache = new UserPolicyCache(policy_cache_file, |
| 379 wait_for_policy_fetch); |
| 380 user_policy_token_cache_.reset( |
| 381 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); |
| 345 | 382 |
| 346 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 383 // Initiate the DM-Token load. |
| 347 #if defined(OS_CHROMEOS) | 384 user_policy_token_cache_->Load(); |
| 348 user_policy_cache = | |
| 349 new CrosUserPolicyCache( | |
| 350 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | |
| 351 user_data_store_.get(), | |
| 352 wait_for_policy_fetch, | |
| 353 token_cache_file, | |
| 354 policy_cache_file); | |
| 355 #else | |
| 356 user_policy_cache = new UserPolicyCache(policy_cache_file, | |
| 357 wait_for_policy_fetch); | |
| 358 user_policy_token_cache_.reset( | |
| 359 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); | |
| 360 | |
| 361 // Initiate the DM-Token load. | |
| 362 user_policy_token_cache_->Load(); | |
| 363 #endif | 385 #endif |
| 364 | 386 |
| 365 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 387 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 366 user_data_store_.get(), | 388 user_data_store_.get(), |
| 367 user_policy_cache)); | 389 user_policy_cache, |
| 390 GetDeviceManagementUrl())); |
| 368 | 391 |
| 369 user_data_store_->set_user_name(user_name); | 392 user_data_store_->set_user_name(user_name); |
| 370 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | 393 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
| 371 | 394 |
| 372 user_cloud_policy_subsystem_->CompleteInitialization( | 395 user_cloud_policy_subsystem_->CompleteInitialization( |
| 373 prefs::kUserPolicyRefreshRate, | 396 prefs::kUserPolicyRefreshRate, |
| 374 startup_delay); | 397 startup_delay); |
| 375 | 398 |
| 376 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 399 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 377 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 400 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 378 } | |
| 379 } | 401 } |
| 380 } | 402 } |
| 381 | 403 |
| 382 void BrowserPolicyConnector::SetUserPolicyTokenService( | 404 void BrowserPolicyConnector::SetUserPolicyTokenService( |
| 383 TokenService* token_service) { | 405 TokenService* token_service) { |
| 384 token_service_ = token_service; | 406 token_service_ = token_service; |
| 385 registrar_.Add(this, | 407 registrar_.Add(this, |
| 386 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 408 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 387 content::Source<TokenService>(token_service_)); | 409 content::Source<TokenService>(token_service_)); |
| 388 | 410 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 // the user policy cache of this, so that a potential blocked login | 422 // the user policy cache of this, so that a potential blocked login |
| 401 // proceeds without waiting for user policy. | 423 // proceeds without waiting for user policy. |
| 402 if (user_cloud_policy_subsystem_.get()) { | 424 if (user_cloud_policy_subsystem_.get()) { |
| 403 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> | 425 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> |
| 404 SetFetchingDone(); | 426 SetFetchingDone(); |
| 405 } | 427 } |
| 406 } else { | 428 } else { |
| 407 if (user_data_store_.get()) | 429 if (user_data_store_.get()) |
| 408 user_data_store_->SetOAuthToken(oauth_token); | 430 user_data_store_->SetOAuthToken(oauth_token); |
| 409 } | 431 } |
| 410 if (user_cloud_policy_manager_.get()) { | |
| 411 CloudPolicyService* service = | |
| 412 user_cloud_policy_manager_->cloud_policy_service(); | |
| 413 if (service->client() && | |
| 414 !service->client()->is_registered() && | |
| 415 !oauth_token.empty()) { | |
| 416 service->client()->Register(oauth_token); | |
| 417 } else { | |
| 418 user_cloud_policy_manager_->CancelWaitForPolicyFetch(); | |
| 419 } | |
| 420 } | |
| 421 } | 432 } |
| 422 | 433 |
| 423 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { | 434 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { |
| 424 #if defined(OS_CHROMEOS) | 435 #if defined(OS_CHROMEOS) |
| 425 return device_data_store_.get(); | 436 return device_data_store_.get(); |
| 426 #else | 437 #else |
| 427 return NULL; | 438 return NULL; |
| 428 #endif | 439 #endif |
| 429 } | 440 } |
| 430 | 441 |
| 431 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { | 442 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { |
| 432 return user_data_store_.get(); | 443 return user_data_store_.get(); |
| 433 } | 444 } |
| 434 | 445 |
| 435 const ConfigurationPolicyHandlerList* | 446 const ConfigurationPolicyHandlerList* |
| 436 BrowserPolicyConnector::GetHandlerList() const { | 447 BrowserPolicyConnector::GetHandlerList() const { |
| 437 return &handler_list_; | 448 return &handler_list_; |
| 438 } | 449 } |
| 439 | 450 |
| 440 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( | 451 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( |
| 441 const std::string& user_name) { | 452 const std::string& user_name) { |
| 442 #if defined(OS_CHROMEOS) | 453 #if defined(OS_CHROMEOS) |
| 443 if (install_attributes_.get()) { | 454 if (install_attributes_.get()) { |
| 444 size_t pos = user_name.find('@'); | 455 std::string canonicalized_user_name(gaia::CanonicalizeEmail(user_name)); |
| 456 size_t pos = canonicalized_user_name.find('@'); |
| 445 if (pos != std::string::npos && | 457 if (pos != std::string::npos && |
| 446 user_name.substr(pos + 1) == install_attributes_->GetDomain()) { | 458 canonicalized_user_name.substr(pos + 1) == |
| 459 install_attributes_->GetDomain()) { |
| 447 return USER_AFFILIATION_MANAGED; | 460 return USER_AFFILIATION_MANAGED; |
| 448 } | 461 } |
| 449 } | 462 } |
| 450 #endif | 463 #endif |
| 451 | 464 |
| 452 return USER_AFFILIATION_NONE; | 465 return USER_AFFILIATION_NONE; |
| 453 } | 466 } |
| 454 | 467 |
| 455 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { | 468 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { |
| 456 #if defined(OS_CHROMEOS) | 469 #if defined(OS_CHROMEOS) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 467 #endif | 480 #endif |
| 468 } | 481 } |
| 469 | 482 |
| 470 // static | 483 // static |
| 471 void BrowserPolicyConnector::SetPolicyProviderForTesting( | 484 void BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 472 ConfigurationPolicyProvider* provider) { | 485 ConfigurationPolicyProvider* provider) { |
| 473 DCHECK(!g_testing_provider); | 486 DCHECK(!g_testing_provider); |
| 474 g_testing_provider = provider; | 487 g_testing_provider = provider; |
| 475 } | 488 } |
| 476 | 489 |
| 490 // static |
| 491 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { |
| 492 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 493 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) |
| 494 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); |
| 495 else |
| 496 return kDefaultDeviceManagementServerUrl; |
| 497 } |
| 498 |
| 477 void BrowserPolicyConnector::Observe( | 499 void BrowserPolicyConnector::Observe( |
| 478 int type, | 500 int type, |
| 479 const content::NotificationSource& source, | 501 const content::NotificationSource& source, |
| 480 const content::NotificationDetails& details) { | 502 const content::NotificationDetails& details) { |
| 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 482 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 504 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| 483 const TokenService* token_source = | 505 const TokenService* token_source = |
| 484 content::Source<const TokenService>(source).ptr(); | 506 content::Source<const TokenService>(source).ptr(); |
| 485 DCHECK_EQ(token_service_, token_source); | 507 DCHECK_EQ(token_service_, token_source); |
| 486 const TokenService::TokenAvailableDetails* token_details = | 508 const TokenService::TokenAvailableDetails* token_details = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 514 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); | 536 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
| 515 DevicePolicyCache* device_policy_cache = | 537 DevicePolicyCache* device_policy_cache = |
| 516 new DevicePolicyCache(device_data_store_.get(), | 538 new DevicePolicyCache(device_data_store_.get(), |
| 517 install_attributes_.get()); | 539 install_attributes_.get()); |
| 518 | 540 |
| 519 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 541 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 520 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 542 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 521 | 543 |
| 522 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 544 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 523 device_data_store_.get(), | 545 device_data_store_.get(), |
| 524 device_policy_cache)); | 546 device_policy_cache, |
| 547 GetDeviceManagementUrl())); |
| 548 |
| 549 // Skip the final initialization if this is a unit test. |
| 550 if (!MessageLoop::current()) |
| 551 return; |
| 525 | 552 |
| 526 // Initialize the subsystem once the message loops are spinning. | 553 // Initialize the subsystem once the message loops are spinning. |
| 527 MessageLoop::current()->PostTask( | 554 MessageLoop::current()->PostTask( |
| 528 FROM_HERE, | 555 FROM_HERE, |
| 529 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 556 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| 530 weak_ptr_factory_.GetWeakPtr())); | 557 weak_ptr_factory_.GetWeakPtr())); |
| 531 } | 558 } |
| 532 } | 559 } |
| 533 #endif | 560 #endif |
| 534 } | 561 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 return new AsyncPolicyProvider(loader.Pass()); | 616 return new AsyncPolicyProvider(loader.Pass()); |
| 590 } else { | 617 } else { |
| 591 return NULL; | 618 return NULL; |
| 592 } | 619 } |
| 593 #else | 620 #else |
| 594 return NULL; | 621 return NULL; |
| 595 #endif | 622 #endif |
| 596 } | 623 } |
| 597 | 624 |
| 598 } // namespace policy | 625 } // namespace policy |
| OLD | NEW |