| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/location.h" | 9 #include "base/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/browser_process_platform_part.h" | 15 #include "chrome/browser/browser_process_platform_part.h" |
| 15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" | 16 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" |
| 16 #include "chrome/browser/chromeos/login/startup_utils.h" | 17 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 19 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 20 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 21 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 23 #include "chromeos/chromeos_switches.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 24 #include "google_apis/gaia/gaia_auth_consumer.h" | 26 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 25 #include "google_apis/gaia/gaia_auth_fetcher.h" | 27 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 26 #include "google_apis/gaia/gaia_constants.h" | 28 #include "google_apis/gaia/gaia_constants.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 // A helper class that takes care of asynchronously revoking a given token. | 32 // A helper class that takes care of asynchronously revoking a given token. |
| 31 class TokenRevoker : public GaiaAuthConsumer { | 33 class TokenRevoker : public GaiaAuthConsumer { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 connector->GetEnterpriseEnrollmentDomain() != enrolling_user_domain_) { | 155 connector->GetEnterpriseEnrollmentDomain() != enrolling_user_domain_) { |
| 154 LOG(ERROR) << "Trying to re-enroll to a different domain than " | 156 LOG(ERROR) << "Trying to re-enroll to a different domain than " |
| 155 << connector->GetEnterpriseEnrollmentDomain(); | 157 << connector->GetEnterpriseEnrollmentDomain(); |
| 156 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); | 158 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); |
| 157 if (oauth_status_ != OAUTH_NOT_STARTED) | 159 if (oauth_status_ != OAUTH_NOT_STARTED) |
| 158 oauth_status_ = OAUTH_FINISHED; | 160 oauth_status_ = OAUTH_FINISHED; |
| 159 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); | 161 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); |
| 160 return; | 162 return; |
| 161 } | 163 } |
| 162 | 164 |
| 165 bool check_license_type = false; |
| 166 // The license selection dialog is not used when doing Zero Touch. |
| 167 if (!enrollment_config_.is_mode_attestation()) { |
| 168 check_license_type = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 169 chromeos::switches::kEnterpriseEnableLicenseTypeSelection); |
| 170 } |
| 171 |
| 163 connector->ScheduleServiceInitialization(0); | 172 connector->ScheduleServiceInitialization(0); |
| 164 policy::DeviceCloudPolicyInitializer* dcp_initializer = | 173 policy::DeviceCloudPolicyInitializer* dcp_initializer = |
| 165 connector->GetDeviceCloudPolicyInitializer(); | 174 connector->GetDeviceCloudPolicyInitializer(); |
| 166 CHECK(dcp_initializer); | 175 CHECK(dcp_initializer); |
| 167 dcp_initializer->StartEnrollment( | 176 dcp_initializer->PrepareEnrollment( |
| 168 connector->device_management_service(), ad_join_delegate_, | 177 connector->device_management_service(), ad_join_delegate_, |
| 169 enrollment_config_, token, | 178 enrollment_config_, token, |
| 170 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished, | 179 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished, |
| 171 weak_ptr_factory_.GetWeakPtr())); | 180 weak_ptr_factory_.GetWeakPtr())); |
| 181 if (check_license_type) { |
| 182 dcp_initializer->CheckAvailableLicenses( |
| 183 base::Bind(&EnterpriseEnrollmentHelperImpl::OnLicenseMapObtained, |
| 184 weak_ptr_factory_.GetWeakPtr())); |
| 185 } else { |
| 186 dcp_initializer->StartEnrollment(); |
| 187 } |
| 188 } |
| 189 |
| 190 void EnterpriseEnrollmentHelperImpl::UseLicenseType(policy::LicenseType type) { |
| 191 DCHECK(type != policy::LicenseType::UNKNOWN); |
| 192 policy::DeviceCloudPolicyInitializer* dcp_initializer = |
| 193 g_browser_process->platform_part() |
| 194 ->browser_policy_connector_chromeos() |
| 195 ->GetDeviceCloudPolicyInitializer(); |
| 196 |
| 197 CHECK(dcp_initializer); |
| 198 dcp_initializer->StartEnrollmentWithLicense(type); |
| 172 } | 199 } |
| 173 | 200 |
| 174 void EnterpriseEnrollmentHelperImpl::GetDeviceAttributeUpdatePermission() { | 201 void EnterpriseEnrollmentHelperImpl::GetDeviceAttributeUpdatePermission() { |
| 175 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 202 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
| 176 LOG(WARNING) << "Get device attribute update permission"; | 203 LOG(WARNING) << "Get device attribute update permission"; |
| 177 policy::BrowserPolicyConnectorChromeOS* connector = | 204 policy::BrowserPolicyConnectorChromeOS* connector = |
| 178 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 205 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 179 // Don't update device attributes for Active Directory management. | 206 // Don't update device attributes for Active Directory management. |
| 180 if (connector->IsActiveDirectoryManaged()) { | 207 if (connector->IsActiveDirectoryManaged()) { |
| 181 OnDeviceAttributeUpdatePermission(false); | 208 OnDeviceAttributeUpdatePermission(false); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 oauth_status_ = OAUTH_FINISHED; | 270 oauth_status_ = OAUTH_FINISHED; |
| 244 if (status.status() == policy::EnrollmentStatus::SUCCESS) { | 271 if (status.status() == policy::EnrollmentStatus::SUCCESS) { |
| 245 success_ = true; | 272 success_ = true; |
| 246 StartupUtils::MarkOobeCompleted(); | 273 StartupUtils::MarkOobeCompleted(); |
| 247 status_consumer()->OnDeviceEnrolled(additional_token_); | 274 status_consumer()->OnDeviceEnrolled(additional_token_); |
| 248 } else { | 275 } else { |
| 249 status_consumer()->OnEnrollmentError(status); | 276 status_consumer()->OnEnrollmentError(status); |
| 250 } | 277 } |
| 251 } | 278 } |
| 252 | 279 |
| 280 void EnterpriseEnrollmentHelperImpl::OnLicenseMapObtained( |
| 281 const EnrollmentLicenseMap& licenses) { |
| 282 int count = 0; |
| 283 policy::LicenseType license_type = policy::LicenseType::UNKNOWN; |
| 284 for (const auto& it : licenses) { |
| 285 if (it.second > 0) { |
| 286 count++; |
| 287 license_type = it.first; |
| 288 } |
| 289 } |
| 290 if (count == 0) { |
| 291 // No user license type selection allowed, start usual enrollment. |
| 292 policy::BrowserPolicyConnectorChromeOS* connector = |
| 293 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 294 policy::DeviceCloudPolicyInitializer* dcp_initializer = |
| 295 connector->GetDeviceCloudPolicyInitializer(); |
| 296 CHECK(dcp_initializer); |
| 297 dcp_initializer->StartEnrollment(); |
| 298 } else if (count == 1) { |
| 299 UseLicenseType(license_type); |
| 300 } else { |
| 301 status_consumer()->OnMultipleLicensesAvailable(licenses); |
| 302 } |
| 303 } |
| 304 |
| 253 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( | 305 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( |
| 254 bool granted) { | 306 bool granted) { |
| 255 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 307 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
| 256 LOG(WARNING) << "Device attribute update permission granted=" << granted; | 308 LOG(WARNING) << "Device attribute update permission granted=" << granted; |
| 257 status_consumer()->OnDeviceAttributeUpdatePermission(granted); | 309 status_consumer()->OnDeviceAttributeUpdatePermission(granted); |
| 258 } | 310 } |
| 259 | 311 |
| 260 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted( | 312 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted( |
| 261 bool success) { | 313 bool success) { |
| 262 status_consumer()->OnDeviceAttributeUploadCompleted(success); | 314 status_consumer()->OnDeviceAttributeUploadCompleted(success); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 EnrollmentUMA(sample, enrollment_config_.mode); | 495 EnrollmentUMA(sample, enrollment_config_.mode); |
| 444 } | 496 } |
| 445 | 497 |
| 446 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( | 498 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( |
| 447 const base::Closure& callback) { | 499 const base::Closure& callback) { |
| 448 oauth_data_cleared_ = true; | 500 oauth_data_cleared_ = true; |
| 449 callback.Run(); | 501 callback.Run(); |
| 450 } | 502 } |
| 451 | 503 |
| 452 } // namespace chromeos | 504 } // namespace chromeos |
| OLD | NEW |