| 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/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/net/gaia/token_service.h" |
| 11 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 10 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 12 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
| 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 13 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | 15 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" |
| 16 #include "chrome/browser/policy/user_policy_cache.h" |
| 17 #include "chrome/browser/policy/user_policy_identity_strategy.h" |
| 14 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 16 | 20 #include "chrome/common/net/gaia/gaia_constants.h" |
| 21 #include "content/common/notification_details.h" |
| 22 #include "content/common/notification_source.h" |
| 17 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 18 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 24 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
| 19 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
| 20 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 26 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| 21 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) |
| 22 #include "chrome/browser/policy/config_dir_policy_provider.h" | 28 #include "chrome/browser/policy/config_dir_policy_provider.h" |
| 23 #endif | 29 #endif |
| 24 | 30 |
| 25 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 26 #include "chrome/browser/chromeos/cros/cros_library.h" | 32 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 33 #include "chrome/browser/chromeos/login/user_manager.h" |
| 27 #include "chrome/browser/policy/device_policy_cache.h" | 34 #include "chrome/browser/policy/device_policy_cache.h" |
| 28 #include "chrome/browser/policy/device_policy_identity_strategy.h" | 35 #include "chrome/browser/policy/device_policy_identity_strategy.h" |
| 29 #include "chrome/browser/policy/enterprise_install_attributes.h" | 36 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 37 #include "content/common/notification_service.h" |
| 30 #endif | 38 #endif |
| 31 | 39 |
| 32 namespace policy { | 40 namespace policy { |
| 33 | 41 |
| 34 namespace { | 42 namespace { |
| 35 | 43 |
| 44 // The directory suffixes for user cloud policy. |
| 45 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
| 46 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
| 47 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
| 48 |
| 36 // The following constants define delays applied before the initial policy fetch | 49 // The following constants define delays applied before the initial policy fetch |
| 37 // on startup. (So that displaying Chrome's GUI does not get delayed.) | 50 // on startup. (So that displaying Chrome's GUI does not get delayed.) |
| 38 // Delay in milliseconds from startup. | 51 // Delay in milliseconds from startup. |
| 39 const int64 kServiceInitializationStartupDelay = 5000; | 52 const int64 kServiceInitializationStartupDelay = 5000; |
| 40 | 53 |
| 41 } // namespace | 54 } // namespace |
| 42 | 55 |
| 43 // static | 56 // static |
| 44 BrowserPolicyConnector* BrowserPolicyConnector::Create() { | 57 BrowserPolicyConnector* BrowserPolicyConnector::Create() { |
| 45 return new BrowserPolicyConnector(); | 58 return new BrowserPolicyConnector(); |
| 46 } | 59 } |
| 47 | 60 |
| 48 BrowserPolicyConnector::BrowserPolicyConnector() | 61 BrowserPolicyConnector::BrowserPolicyConnector() |
| 49 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 62 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 50 managed_platform_provider_.reset(CreateManagedPlatformProvider()); | 63 managed_platform_provider_.reset(CreateManagedPlatformProvider()); |
| 51 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); | 64 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); |
| 52 | 65 |
| 66 managed_cloud_provider_.reset(new CloudPolicyProvider( |
| 67 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 68 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY)); |
| 69 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| 70 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 71 CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED)); |
| 72 |
| 53 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
| 54 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 74 InitializeDevicePolicy(); |
| 55 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { | |
| 56 identity_strategy_.reset(new DevicePolicyIdentityStrategy()); | |
| 57 install_attributes_.reset(new EnterpriseInstallAttributes( | |
| 58 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); | |
| 59 cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | |
| 60 identity_strategy_.get(), | |
| 61 new DevicePolicyCache(identity_strategy_.get(), | |
| 62 install_attributes_.get()))); | |
| 63 | |
| 64 // Initialize the subsystem once the message loops are spinning. | |
| 65 MessageLoop::current()->PostTask( | |
| 66 FROM_HERE, | |
| 67 method_factory_.NewRunnableMethod(&BrowserPolicyConnector::Initialize)); | |
| 68 } | |
| 69 #endif | 75 #endif |
| 70 } | 76 } |
| 71 | 77 |
| 72 BrowserPolicyConnector::BrowserPolicyConnector( | 78 BrowserPolicyConnector::BrowserPolicyConnector( |
| 73 ConfigurationPolicyProvider* managed_platform_provider, | 79 ConfigurationPolicyProvider* managed_platform_provider, |
| 74 ConfigurationPolicyProvider* recommended_platform_provider) | 80 ConfigurationPolicyProvider* recommended_platform_provider, |
| 81 CloudPolicyProvider* managed_cloud_provider, |
| 82 CloudPolicyProvider* recommended_cloud_provider) |
| 75 : managed_platform_provider_(managed_platform_provider), | 83 : managed_platform_provider_(managed_platform_provider), |
| 76 recommended_platform_provider_(recommended_platform_provider), | 84 recommended_platform_provider_(recommended_platform_provider), |
| 85 managed_cloud_provider_(managed_cloud_provider), |
| 86 recommended_cloud_provider_(recommended_cloud_provider), |
| 77 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} | 87 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
| 78 | 88 |
| 79 BrowserPolicyConnector::~BrowserPolicyConnector() { | 89 BrowserPolicyConnector::~BrowserPolicyConnector() { |
| 80 if (cloud_policy_subsystem_.get()) | 90 // Shutdown device cloud policy. |
| 81 cloud_policy_subsystem_->Shutdown(); | |
| 82 cloud_policy_subsystem_.reset(); | |
| 83 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 84 identity_strategy_.reset(); | 92 if (device_cloud_policy_subsystem_.get()) |
| 93 device_cloud_policy_subsystem_->Shutdown(); |
| 94 device_cloud_policy_subsystem_.reset(); |
| 95 device_identity_strategy_.reset(); |
| 85 #endif | 96 #endif |
| 97 |
| 98 // Shutdown user cloud policy. |
| 99 if (user_cloud_policy_subsystem_.get()) |
| 100 user_cloud_policy_subsystem_->Shutdown(); |
| 101 user_cloud_policy_subsystem_.reset(); |
| 102 user_identity_strategy_.reset(); |
| 86 } | 103 } |
| 87 | 104 |
| 88 ConfigurationPolicyProvider* | 105 ConfigurationPolicyProvider* |
| 89 BrowserPolicyConnector::GetManagedPlatformProvider() const { | 106 BrowserPolicyConnector::GetManagedPlatformProvider() const { |
| 90 return managed_platform_provider_.get(); | 107 return managed_platform_provider_.get(); |
| 91 } | 108 } |
| 92 | 109 |
| 93 ConfigurationPolicyProvider* | 110 ConfigurationPolicyProvider* |
| 94 BrowserPolicyConnector::GetManagedCloudProvider() const { | 111 BrowserPolicyConnector::GetManagedCloudProvider() const { |
| 95 if (cloud_policy_subsystem_.get()) | 112 return managed_cloud_provider_.get(); |
| 96 return cloud_policy_subsystem_->GetManagedPolicyProvider(); | |
| 97 | |
| 98 return NULL; | |
| 99 } | 113 } |
| 100 | 114 |
| 101 ConfigurationPolicyProvider* | 115 ConfigurationPolicyProvider* |
| 102 BrowserPolicyConnector::GetRecommendedPlatformProvider() const { | 116 BrowserPolicyConnector::GetRecommendedPlatformProvider() const { |
| 103 return recommended_platform_provider_.get(); | 117 return recommended_platform_provider_.get(); |
| 104 } | 118 } |
| 105 | 119 |
| 106 ConfigurationPolicyProvider* | 120 ConfigurationPolicyProvider* |
| 107 BrowserPolicyConnector::GetRecommendedCloudProvider() const { | 121 BrowserPolicyConnector::GetRecommendedCloudProvider() const { |
| 108 if (cloud_policy_subsystem_.get()) | 122 return recommended_cloud_provider_.get(); |
| 109 return cloud_policy_subsystem_->GetRecommendedPolicyProvider(); | |
| 110 | |
| 111 return NULL; | |
| 112 } | 123 } |
| 113 | 124 |
| 114 ConfigurationPolicyProvider* | 125 ConfigurationPolicyProvider* |
| 115 BrowserPolicyConnector::CreateManagedPlatformProvider() { | 126 BrowserPolicyConnector::CreateManagedPlatformProvider() { |
| 116 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | 127 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
| 117 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | 128 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 118 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
| 119 return new ConfigurationPolicyProviderWin(policy_list); | 130 return new ConfigurationPolicyProviderWin(policy_list); |
| 120 #elif defined(OS_MACOSX) | 131 #elif defined(OS_MACOSX) |
| 121 return new ConfigurationPolicyProviderMac(policy_list); | 132 return new ConfigurationPolicyProviderMac(policy_list); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 144 policy_list, | 155 policy_list, |
| 145 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 156 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
| 146 } else { | 157 } else { |
| 147 return new DummyConfigurationPolicyProvider(policy_list); | 158 return new DummyConfigurationPolicyProvider(policy_list); |
| 148 } | 159 } |
| 149 #else | 160 #else |
| 150 return new DummyConfigurationPolicyProvider(policy_list); | 161 return new DummyConfigurationPolicyProvider(policy_list); |
| 151 #endif | 162 #endif |
| 152 } | 163 } |
| 153 | 164 |
| 154 void BrowserPolicyConnector::SetCredentials(const std::string& owner_email, | 165 void BrowserPolicyConnector::SetDeviceCredentials( |
| 155 const std::string& gaia_token) { | 166 const std::string& owner_email, |
| 167 const std::string& gaia_token) { |
| 156 #if defined(OS_CHROMEOS) | 168 #if defined(OS_CHROMEOS) |
| 157 if (identity_strategy_.get()) | 169 if (device_identity_strategy_.get()) |
| 158 identity_strategy_->SetAuthCredentials(owner_email, gaia_token); | 170 device_identity_strategy_->SetAuthCredentials(owner_email, gaia_token); |
| 159 #endif | 171 #endif |
| 160 } | 172 } |
| 161 | 173 |
| 162 bool BrowserPolicyConnector::IsEnterpriseManaged() { | 174 bool BrowserPolicyConnector::IsEnterpriseManaged() { |
| 163 #if defined(OS_CHROMEOS) | 175 #if defined(OS_CHROMEOS) |
| 164 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); | 176 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); |
| 165 #else | 177 #else |
| 166 return false; | 178 return false; |
| 167 #endif | 179 #endif |
| 168 } | 180 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 179 | 191 |
| 180 std::string BrowserPolicyConnector::GetEnterpriseDomain() { | 192 std::string BrowserPolicyConnector::GetEnterpriseDomain() { |
| 181 #if defined(OS_CHROMEOS) | 193 #if defined(OS_CHROMEOS) |
| 182 if (install_attributes_.get()) | 194 if (install_attributes_.get()) |
| 183 return install_attributes_->GetDomain(); | 195 return install_attributes_->GetDomain(); |
| 184 #endif | 196 #endif |
| 185 | 197 |
| 186 return std::string(); | 198 return std::string(); |
| 187 } | 199 } |
| 188 | 200 |
| 189 void BrowserPolicyConnector::StopAutoRetry() { | 201 void BrowserPolicyConnector::DeviceStopAutoRetry() { |
| 190 if (cloud_policy_subsystem_.get()) | |
| 191 cloud_policy_subsystem_->StopAutoRetry(); | |
| 192 } | |
| 193 | |
| 194 void BrowserPolicyConnector::FetchPolicy() { | |
| 195 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 196 if (identity_strategy_.get()) | 203 if (device_cloud_policy_subsystem_.get()) |
| 197 return identity_strategy_->FetchPolicy(); | 204 device_cloud_policy_subsystem_->StopAutoRetry(); |
| 198 #endif | 205 #endif |
| 199 } | 206 } |
| 200 | 207 |
| 201 void BrowserPolicyConnector::Initialize() { | 208 void BrowserPolicyConnector::FetchDevicePolicy() { |
| 202 if (cloud_policy_subsystem_.get()) { | 209 #if defined(OS_CHROMEOS) |
| 203 cloud_policy_subsystem_->Initialize( | 210 if (device_identity_strategy_.get()) |
| 211 return device_identity_strategy_->FetchPolicy(); |
| 212 #endif |
| 213 } |
| 214 |
| 215 void BrowserPolicyConnector::InitializeUserPolicy(std::string& user_name, |
| 216 const FilePath& policy_dir, |
| 217 TokenService* token_service) { |
| 218 // Throw away the old backend. |
| 219 user_cloud_policy_subsystem_.reset(); |
| 220 user_identity_strategy_.reset(); |
| 221 registrar_.RemoveAll(); |
| 222 |
| 223 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 224 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| 225 token_service_ = token_service; |
| 226 registrar_.Add(this, |
| 227 NotificationType::TOKEN_AVAILABLE, |
| 228 Source<TokenService>(token_service_)); |
| 229 |
| 230 // Register for the event of user login on CrOS to make sure that the user |
| 231 // is not changing while the user policy backend is active. |
| 232 #if defined(OS_CHROMEOS) |
| 233 registrar_.Add(this, |
| 234 NotificationType::LOGIN_USER_CHANGED, |
| 235 NotificationService::AllSources()); |
| 236 #endif |
| 237 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); |
| 238 UserPolicyCache* user_policy_cache = |
| 239 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); |
| 240 |
| 241 // Prepending user caches meaning they will take precedence of device policy |
| 242 // caches. |
| 243 managed_cloud_provider_->PrependCache(user_policy_cache); |
| 244 recommended_cloud_provider_->PrependCache(user_policy_cache); |
| 245 user_identity_strategy_.reset( |
| 246 new UserPolicyIdentityStrategy( |
| 247 user_name, |
| 248 policy_cache_dir.Append(kTokenCacheFile))); |
| 249 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 250 user_identity_strategy_.get(), |
| 251 user_policy_cache)); |
| 252 |
| 253 // Initiate the DM-Token load. |
| 254 user_identity_strategy_->LoadTokenCache(); |
| 255 |
| 256 // In case the token of |token_service_| is already available we set it |
| 257 // directly, since there will be no notification for it. |
| 258 if (token_service_->HasTokenForService( |
| 259 GaiaConstants::kDeviceManagementService)) { |
| 260 user_identity_strategy_->SetAuthToken( |
| 261 token_service_->GetTokenForService( |
| 262 GaiaConstants::kDeviceManagementService)); |
| 263 } |
| 264 |
| 265 // TODO(sfeuz): This already assumes that user policy refresh rate |
| 266 // preference lives in local_state. |
| 267 user_cloud_policy_subsystem_->Initialize( |
| 204 g_browser_process->local_state(), | 268 g_browser_process->local_state(), |
| 205 kServiceInitializationStartupDelay); | 269 kServiceInitializationStartupDelay); |
| 206 } | 270 } |
| 207 } | 271 } |
| 208 | 272 |
| 209 void BrowserPolicyConnector::ScheduleServiceInitialization( | 273 void BrowserPolicyConnector::ScheduleUserServiceInitialization( |
| 210 int64 delay_milliseconds) { | 274 int64 delay_milliseconds) { |
| 211 if (cloud_policy_subsystem_.get()) | 275 if (user_cloud_policy_subsystem_.get()) |
| 212 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds); | 276 user_cloud_policy_subsystem_-> |
| 277 ScheduleServiceInitialization(delay_milliseconds); |
| 278 } |
| 279 |
| 280 void BrowserPolicyConnector::InitializeDevicePolicy() { |
| 281 #if defined(OS_CHROMEOS) |
| 282 // Throw away the old backend. |
| 283 device_cloud_policy_subsystem_.reset(); |
| 284 device_identity_strategy_.reset(); |
| 285 |
| 286 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 287 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| 288 device_cloud_policy_subsystem_.reset(); |
| 289 device_identity_strategy_.reset(); |
| 290 |
| 291 device_identity_strategy_.reset(new DevicePolicyIdentityStrategy()); |
| 292 install_attributes_.reset(new EnterpriseInstallAttributes( |
| 293 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); |
| 294 DevicePolicyCache* device_policy_cache = |
| 295 new DevicePolicyCache(device_identity_strategy_.get(), |
| 296 install_attributes_.get()); |
| 297 |
| 298 managed_cloud_provider_->AppendCache(device_policy_cache); |
| 299 recommended_cloud_provider_->AppendCache(device_policy_cache); |
| 300 |
| 301 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 302 device_identity_strategy_.get(), |
| 303 device_policy_cache)); |
| 304 |
| 305 // Initialize the subsystem once the message loops are spinning. |
| 306 MessageLoop::current()->PostTask( |
| 307 FROM_HERE, |
| 308 method_factory_.NewRunnableMethod( |
| 309 &BrowserPolicyConnector::InitializeDevicePolicySubsystem)); |
| 310 } |
| 311 #endif |
| 312 } |
| 313 |
| 314 void BrowserPolicyConnector::InitializeDevicePolicySubsystem() { |
| 315 #if defined(OS_CHROMEOS) |
| 316 if (device_cloud_policy_subsystem_.get()) { |
| 317 device_cloud_policy_subsystem_->Initialize( |
| 318 g_browser_process->local_state(), |
| 319 kServiceInitializationStartupDelay); |
| 320 } |
| 321 #endif |
| 322 } |
| 323 |
| 324 void BrowserPolicyConnector::ScheduleDeviceServiceInitialization( |
| 325 int64 delay_milliseconds) { |
| 326 #if defined(OS_CHROMEOS) |
| 327 if (device_cloud_policy_subsystem_.get()) { |
| 328 device_cloud_policy_subsystem_-> |
| 329 ScheduleServiceInitialization(delay_milliseconds); |
| 330 } |
| 331 #endif |
| 332 } |
| 333 |
| 334 void BrowserPolicyConnector::Observe(NotificationType type, |
| 335 const NotificationSource& source, |
| 336 const NotificationDetails& details) { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 338 if (type == NotificationType::TOKEN_AVAILABLE) { |
| 339 const TokenService::TokenService* token_source = |
| 340 Source<const TokenService>(source).ptr(); |
| 341 DCHECK_EQ(token_service_, token_source); |
| 342 const TokenService::TokenAvailableDetails* token_details = |
| 343 Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
| 344 if (token_details->service() == GaiaConstants::kDeviceManagementService) |
| 345 if (user_identity_strategy_.get()) |
| 346 user_identity_strategy_->SetAuthToken(token_details->token()); |
| 347 #if defined(OS_CHROMEOS) |
| 348 } else if (type == NotificationType::LOGIN_USER_CHANGED) { |
| 349 const chromeos::UserManager::User* user_details = |
| 350 Details<const chromeos::UserManager::User>(details).ptr(); |
| 351 std::string current_username, current_auth_token; |
| 352 user_identity_strategy_->GetCredentials(¤t_username, |
| 353 ¤t_auth_token); |
| 354 DCHECK_EQ(current_username, user_details->email()); |
| 355 #endif |
| 356 } else { |
| 357 NOTREACHED(); |
| 358 } |
| 213 } | 359 } |
| 214 | 360 |
| 215 } // namespace | 361 } // namespace |
| OLD | NEW |