Chromium Code Reviews| 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. | |
|
Mattias Nissler (ping if slow)
2012/08/03 12:19:08
In policy, we usually just spin up a fake FILE thr
Andrew T Wilson (Slow)
2012/08/04 00:54:41
Basically, any test that results in a call to g_br
| |
| 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<PolicyService> BrowserPolicyConnector::CreatePolicyService( |
| 162 Profile* profile) { | 167 Profile* profile) { |
| 163 // |providers| in decreasing order of priority. | 168 // |providers| in decreasing order of priority. |
| 164 PolicyServiceImpl::Providers providers; | 169 PolicyServiceImpl::Providers providers; |
| 165 if (g_testing_provider) | 170 if (g_testing_provider) |
| 166 providers.push_back(g_testing_provider); | 171 providers.push_back(g_testing_provider); |
| 167 if (platform_provider_.get()) | 172 if (platform_provider_.get()) |
| 168 providers.push_back(platform_provider_.get()); | 173 providers.push_back(platform_provider_.get()); |
| 169 if (managed_cloud_provider_.get()) | 174 if (managed_cloud_provider_.get()) |
| 170 providers.push_back(managed_cloud_provider_.get()); | 175 providers.push_back(managed_cloud_provider_.get()); |
| 171 if (recommended_cloud_provider_.get()) | 176 if (recommended_cloud_provider_.get()) |
| 172 providers.push_back(recommended_cloud_provider_.get()); | 177 providers.push_back(recommended_cloud_provider_.get()); |
| 173 | 178 |
| 174 // The global policy service uses the proxy provider to allow for swapping in | 179 // 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_| | 180 // user policy after startup, while profiles use |user_cloud_policy_manager_| |
| 176 // directly as their provider, which may also block initialization on a policy | 181 // directly as their provider, which may also block initialization on a policy |
| 177 // fetch at login time. | 182 // fetch at login time. |
| 178 if (profile) { | 183 if (profile) { |
| 179 if (user_cloud_policy_manager_.get()) | 184 UserCloudPolicyManager* manager = profile->GetUserCloudPolicyManager(); |
| 180 providers.push_back(user_cloud_policy_manager_.get()); | 185 if (manager) |
| 186 providers.push_back(manager); | |
| 181 | 187 |
| 182 providers.push_back( | 188 providers.push_back( |
| 183 ManagedModePolicyProviderFactory::GetForProfile(profile)); | 189 ManagedModePolicyProviderFactory::GetForProfile(profile)); |
| 184 } else { | 190 } else { |
| 185 providers.push_back(&user_cloud_policy_provider_); | 191 providers.push_back(&user_cloud_policy_provider_); |
| 186 } | 192 } |
| 187 | 193 |
| 188 return new PolicyServiceImpl(providers); | 194 return scoped_ptr<PolicyService>(new PolicyServiceImpl(providers)).Pass(); |
| 189 } | 195 } |
| 190 | 196 |
| 191 void BrowserPolicyConnector::RegisterForDevicePolicy( | 197 void BrowserPolicyConnector::RegisterForDevicePolicy( |
| 192 const std::string& owner_email, | 198 const std::string& owner_email, |
| 193 const std::string& token, | 199 const std::string& token, |
| 194 bool known_machine_id, | 200 bool known_machine_id, |
| 195 bool reregister) { | 201 bool reregister) { |
| 196 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 197 if (device_data_store_.get()) { | 203 if (device_data_store_.get()) { |
| 198 if (!device_data_store_->device_token().empty()) { | 204 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_-> | 301 user_cloud_policy_subsystem_-> |
| 296 ScheduleServiceInitialization(delay_milliseconds); | 302 ScheduleServiceInitialization(delay_milliseconds); |
| 297 } | 303 } |
| 298 #if defined(OS_CHROMEOS) | 304 #if defined(OS_CHROMEOS) |
| 299 if (device_cloud_policy_subsystem_.get()) { | 305 if (device_cloud_policy_subsystem_.get()) { |
| 300 device_cloud_policy_subsystem_-> | 306 device_cloud_policy_subsystem_-> |
| 301 ScheduleServiceInitialization(delay_milliseconds); | 307 ScheduleServiceInitialization(delay_milliseconds); |
| 302 } | 308 } |
| 303 #endif | 309 #endif |
| 304 } | 310 } |
| 311 | |
| 305 void BrowserPolicyConnector::InitializeUserPolicy( | 312 void BrowserPolicyConnector::InitializeUserPolicy( |
| 306 const std::string& user_name, | 313 const std::string& user_name, |
| 307 bool wait_for_policy_fetch) { | 314 bool wait_for_policy_fetch) { |
| 308 // Throw away the old backend. | 315 // Throw away the old backend. |
| 309 user_cloud_policy_manager_.reset(); | |
| 310 | |
| 311 user_cloud_policy_subsystem_.reset(); | 316 user_cloud_policy_subsystem_.reset(); |
| 312 user_policy_token_cache_.reset(); | 317 user_policy_token_cache_.reset(); |
| 313 user_data_store_.reset(); | 318 user_data_store_.reset(); |
| 314 token_service_ = NULL; | 319 token_service_ = NULL; |
| 315 registrar_.RemoveAll(); | 320 registrar_.RemoveAll(); |
| 316 | 321 |
| 317 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 322 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 318 | 323 |
| 319 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { | 324 int64 startup_delay = |
| 320 int64 startup_delay = | 325 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
| 321 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; | |
| 322 | 326 |
| 323 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 327 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
| 328 FilePath profile_dir; | |
| 329 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | |
| 324 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 325 user_cloud_policy_manager_ = | 331 profile_dir = profile_dir.Append( |
| 326 UserCloudPolicyManager::Create(wait_for_policy_fetch); | 332 command_line->GetSwitchValuePath(switches::kLoginProfile)); |
| 327 user_cloud_policy_manager_->Initialize(g_browser_process->local_state(), | 333 #endif |
| 328 device_management_service_.get(), | 334 const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| 329 GetUserAffiliation(user_name)); | 335 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| 330 user_cloud_policy_provider_.SetDelegate(user_cloud_policy_manager_.get()); | 336 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| 337 CloudPolicyCacheBase* user_policy_cache = NULL; | |
| 331 | 338 |
| 332 device_management_service_->ScheduleInitialization(startup_delay); | 339 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) | 340 #if defined(OS_CHROMEOS) |
| 338 profile_dir = profile_dir.Append( | 341 user_policy_cache = |
| 339 command_line->GetSwitchValuePath(switches::kLoginProfile)); | 342 new CrosUserPolicyCache( |
| 340 #endif | 343 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
| 341 const FilePath policy_dir = profile_dir.Append(kPolicyDir); | 344 user_data_store_.get(), |
| 342 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); | 345 wait_for_policy_fetch, |
| 343 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); | 346 token_cache_file, |
| 344 CloudPolicyCacheBase* user_policy_cache = NULL; | 347 policy_cache_file); |
| 348 #else | |
| 349 user_policy_cache = new UserPolicyCache(policy_cache_file, | |
| 350 wait_for_policy_fetch); | |
| 351 user_policy_token_cache_.reset( | |
| 352 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); | |
| 345 | 353 |
| 346 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 354 // Initiate the DM-Token load. |
| 347 #if defined(OS_CHROMEOS) | 355 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 | 356 #endif |
| 364 | 357 |
| 365 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 358 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 366 user_data_store_.get(), | 359 user_data_store_.get(), |
| 367 user_policy_cache)); | 360 user_policy_cache, |
| 361 GetDeviceManagementUrl())); | |
| 368 | 362 |
| 369 user_data_store_->set_user_name(user_name); | 363 user_data_store_->set_user_name(user_name); |
| 370 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | 364 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
| 371 | 365 |
| 372 user_cloud_policy_subsystem_->CompleteInitialization( | 366 user_cloud_policy_subsystem_->CompleteInitialization( |
| 373 prefs::kUserPolicyRefreshRate, | 367 prefs::kUserPolicyRefreshRate, |
| 374 startup_delay); | 368 startup_delay); |
| 375 | 369 |
| 376 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 370 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 377 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 371 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 378 } | |
| 379 } | 372 } |
| 380 } | 373 } |
| 381 | 374 |
| 382 void BrowserPolicyConnector::SetUserPolicyTokenService( | 375 void BrowserPolicyConnector::SetUserPolicyTokenService( |
| 383 TokenService* token_service) { | 376 TokenService* token_service) { |
| 384 token_service_ = token_service; | 377 token_service_ = token_service; |
| 385 registrar_.Add(this, | 378 registrar_.Add(this, |
| 386 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 379 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 387 content::Source<TokenService>(token_service_)); | 380 content::Source<TokenService>(token_service_)); |
| 388 | 381 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 400 // the user policy cache of this, so that a potential blocked login | 393 // the user policy cache of this, so that a potential blocked login |
| 401 // proceeds without waiting for user policy. | 394 // proceeds without waiting for user policy. |
| 402 if (user_cloud_policy_subsystem_.get()) { | 395 if (user_cloud_policy_subsystem_.get()) { |
| 403 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> | 396 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> |
| 404 SetFetchingDone(); | 397 SetFetchingDone(); |
| 405 } | 398 } |
| 406 } else { | 399 } else { |
| 407 if (user_data_store_.get()) | 400 if (user_data_store_.get()) |
| 408 user_data_store_->SetOAuthToken(oauth_token); | 401 user_data_store_->SetOAuthToken(oauth_token); |
| 409 } | 402 } |
| 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 } | 403 } |
| 422 | 404 |
| 423 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { | 405 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { |
| 424 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
| 425 return device_data_store_.get(); | 407 return device_data_store_.get(); |
| 426 #else | 408 #else |
| 427 return NULL; | 409 return NULL; |
| 428 #endif | 410 #endif |
| 429 } | 411 } |
| 430 | 412 |
| 431 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { | 413 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { |
| 432 return user_data_store_.get(); | 414 return user_data_store_.get(); |
| 433 } | 415 } |
| 434 | 416 |
| 435 const ConfigurationPolicyHandlerList* | 417 const ConfigurationPolicyHandlerList* |
| 436 BrowserPolicyConnector::GetHandlerList() const { | 418 BrowserPolicyConnector::GetHandlerList() const { |
| 437 return &handler_list_; | 419 return &handler_list_; |
| 438 } | 420 } |
| 439 | 421 |
| 440 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( | 422 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( |
| 441 const std::string& user_name) { | 423 const std::string& user_name) { |
| 442 #if defined(OS_CHROMEOS) | 424 #if defined(OS_CHROMEOS) |
| 443 if (install_attributes_.get()) { | 425 if (install_attributes_.get()) { |
| 444 size_t pos = user_name.find('@'); | 426 std::string canonicalized_user_name(gaia::CanonicalizeEmail(user_name)); |
| 427 size_t pos = canonicalized_user_name.find('@'); | |
| 445 if (pos != std::string::npos && | 428 if (pos != std::string::npos && |
| 446 user_name.substr(pos + 1) == install_attributes_->GetDomain()) { | 429 canonicalized_user_name.substr(pos + 1) == |
| 430 install_attributes_->GetDomain()) { | |
| 447 return USER_AFFILIATION_MANAGED; | 431 return USER_AFFILIATION_MANAGED; |
| 448 } | 432 } |
| 449 } | 433 } |
| 450 #endif | 434 #endif |
| 451 | 435 |
| 452 return USER_AFFILIATION_NONE; | 436 return USER_AFFILIATION_NONE; |
| 453 } | 437 } |
| 454 | 438 |
| 455 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { | 439 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { |
| 456 #if defined(OS_CHROMEOS) | 440 #if defined(OS_CHROMEOS) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 467 #endif | 451 #endif |
| 468 } | 452 } |
| 469 | 453 |
| 470 // static | 454 // static |
| 471 void BrowserPolicyConnector::SetPolicyProviderForTesting( | 455 void BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 472 ConfigurationPolicyProvider* provider) { | 456 ConfigurationPolicyProvider* provider) { |
| 473 DCHECK(!g_testing_provider); | 457 DCHECK(!g_testing_provider); |
| 474 g_testing_provider = provider; | 458 g_testing_provider = provider; |
| 475 } | 459 } |
| 476 | 460 |
| 461 // static | |
| 462 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { | |
| 463 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 464 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) | |
| 465 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); | |
| 466 else | |
| 467 return kDefaultDeviceManagementServerUrl; | |
| 468 } | |
| 469 | |
| 477 void BrowserPolicyConnector::Observe( | 470 void BrowserPolicyConnector::Observe( |
| 478 int type, | 471 int type, |
| 479 const content::NotificationSource& source, | 472 const content::NotificationSource& source, |
| 480 const content::NotificationDetails& details) { | 473 const content::NotificationDetails& details) { |
| 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 482 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 475 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| 483 const TokenService* token_source = | 476 const TokenService* token_source = |
| 484 content::Source<const TokenService>(source).ptr(); | 477 content::Source<const TokenService>(source).ptr(); |
| 485 DCHECK_EQ(token_service_, token_source); | 478 DCHECK_EQ(token_service_, token_source); |
| 486 const TokenService::TokenAvailableDetails* token_details = | 479 const TokenService::TokenAvailableDetails* token_details = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 514 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); | 507 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
| 515 DevicePolicyCache* device_policy_cache = | 508 DevicePolicyCache* device_policy_cache = |
| 516 new DevicePolicyCache(device_data_store_.get(), | 509 new DevicePolicyCache(device_data_store_.get(), |
| 517 install_attributes_.get()); | 510 install_attributes_.get()); |
| 518 | 511 |
| 519 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 512 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 520 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 513 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
| 521 | 514 |
| 522 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 515 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 523 device_data_store_.get(), | 516 device_data_store_.get(), |
| 524 device_policy_cache)); | 517 device_policy_cache, |
| 518 GetDeviceManagementUrl())); | |
| 519 | |
| 520 // Skip the final initialization if this is a unit test. | |
| 521 if (!MessageLoop::current()) | |
| 522 return; | |
| 525 | 523 |
| 526 // Initialize the subsystem once the message loops are spinning. | 524 // Initialize the subsystem once the message loops are spinning. |
| 527 MessageLoop::current()->PostTask( | 525 MessageLoop::current()->PostTask( |
| 528 FROM_HERE, | 526 FROM_HERE, |
| 529 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 527 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
| 530 weak_ptr_factory_.GetWeakPtr())); | 528 weak_ptr_factory_.GetWeakPtr())); |
| 531 } | 529 } |
| 532 } | 530 } |
| 533 #endif | 531 #endif |
| 534 } | 532 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 return new AsyncPolicyProvider(loader.Pass()); | 587 return new AsyncPolicyProvider(loader.Pass()); |
| 590 } else { | 588 } else { |
| 591 return NULL; | 589 return NULL; |
| 592 } | 590 } |
| 593 #else | 591 #else |
| 594 return NULL; | 592 return NULL; |
| 595 #endif | 593 #endif |
| 596 } | 594 } |
| 597 | 595 |
| 598 } // namespace policy | 596 } // namespace policy |
| OLD | NEW |