| 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/chromeos/login/enrollment/enrollment_screen.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 UMA_HISTOGRAM_CUSTOM_TIMES( \ | 37 UMA_HISTOGRAM_CUSTOM_TIMES( \ |
| 38 (histogram_name), \ | 38 (histogram_name), \ |
| 39 (elapsed_timer)->Elapsed(), \ | 39 (elapsed_timer)->Elapsed(), \ |
| 40 base::TimeDelta::FromMilliseconds(100) /* min */, \ | 40 base::TimeDelta::FromMilliseconds(100) /* min */, \ |
| 41 base::TimeDelta::FromMinutes(15) /* max */, \ | 41 base::TimeDelta::FromMinutes(15) /* max */, \ |
| 42 100 /* bucket_count */); \ | 42 100 /* bucket_count */); \ |
| 43 } while (0) | 43 } while (0) |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 const char * const kMetricEnrollmentTimeCancel = | 47 const char* const kMetricEnrollmentTimeCancel = |
| 48 "Enterprise.EnrollmentTime.Cancel"; | 48 "Enterprise.EnrollmentTime.Cancel"; |
| 49 const char * const kMetricEnrollmentTimeFailure = | 49 const char* const kMetricEnrollmentTimeFailure = |
| 50 "Enterprise.EnrollmentTime.Failure"; | 50 "Enterprise.EnrollmentTime.Failure"; |
| 51 const char * const kMetricEnrollmentTimeSuccess = | 51 const char* const kMetricEnrollmentTimeSuccess = |
| 52 "Enterprise.EnrollmentTime.Success"; | 52 "Enterprise.EnrollmentTime.Success"; |
| 53 | 53 |
| 54 const char* const kLicenseTypePerpetual = "perpetual"; |
| 55 const char* const kLicenseTypeAnnual = "annual"; |
| 56 const char* const kLicenseTypeKiosk = "kiosk"; |
| 57 |
| 54 // Retry policy constants. | 58 // Retry policy constants. |
| 55 constexpr int kInitialDelayMS = 4 * 1000; // 4 seconds | 59 constexpr int kInitialDelayMS = 4 * 1000; // 4 seconds |
| 56 constexpr double kMultiplyFactor = 1.5; | 60 constexpr double kMultiplyFactor = 1.5; |
| 57 constexpr double kJitterFactor = 0.1; // +/- 10% jitter | 61 constexpr double kJitterFactor = 0.1; // +/- 10% jitter |
| 58 constexpr int64_t kMaxDelayMS = 8 * 60 * 1000; // 8 minutes | 62 constexpr int64_t kMaxDelayMS = 8 * 60 * 1000; // 8 minutes |
| 59 | 63 |
| 64 ::policy::LicenseType GetLicenseTypeById(const std::string& id) { |
| 65 if (id == kLicenseTypePerpetual) |
| 66 return ::policy::LicenseType::PERPETUAL; |
| 67 if (id == kLicenseTypeAnnual) |
| 68 return ::policy::LicenseType::ANNUAL; |
| 69 if (id == kLicenseTypeKiosk) |
| 70 return ::policy::LicenseType::KIOSK; |
| 71 return ::policy::LicenseType::UNKNOWN; |
| 72 } |
| 73 |
| 74 std::string GetLicenseIdByType(::policy::LicenseType type) { |
| 75 switch (type) { |
| 76 case ::policy::LicenseType::PERPETUAL: |
| 77 return kLicenseTypePerpetual; |
| 78 case ::policy::LicenseType::ANNUAL: |
| 79 return kLicenseTypeAnnual; |
| 80 case ::policy::LicenseType::KIOSK: |
| 81 return kLicenseTypeKiosk; |
| 82 default: |
| 83 NOTREACHED(); |
| 84 return std::string(); |
| 85 } |
| 86 } |
| 87 |
| 60 } // namespace | 88 } // namespace |
| 61 | 89 |
| 62 namespace chromeos { | 90 namespace chromeos { |
| 63 | 91 |
| 64 // static | 92 // static |
| 65 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { | 93 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { |
| 66 return static_cast<EnrollmentScreen*>( | 94 return static_cast<EnrollmentScreen*>( |
| 67 manager->GetScreen(OobeScreen::SCREEN_OOBE_ENROLLMENT)); | 95 manager->GetScreen(OobeScreen::SCREEN_OOBE_ENROLLMENT)); |
| 68 } | 96 } |
| 69 | 97 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 enrolling_user_domain_ = gaia::ExtractDomainName(user); | 223 enrolling_user_domain_ = gaia::ExtractDomainName(user); |
| 196 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted | 224 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted |
| 197 : policy::kMetricEnrollmentStarted); | 225 : policy::kMetricEnrollmentStarted); |
| 198 | 226 |
| 199 view_->ShowEnrollmentSpinnerScreen(); | 227 view_->ShowEnrollmentSpinnerScreen(); |
| 200 CreateEnrollmentHelper(); | 228 CreateEnrollmentHelper(); |
| 201 enrollment_helper_->EnrollUsingAuthCode( | 229 enrollment_helper_->EnrollUsingAuthCode( |
| 202 auth_code, shark_controller_ != nullptr /* fetch_additional_token */); | 230 auth_code, shark_controller_ != nullptr /* fetch_additional_token */); |
| 203 } | 231 } |
| 204 | 232 |
| 205 void EnrollmentScreen::OnLicenseTypeSelected(const std::string& license_type) {} | 233 void EnrollmentScreen::OnLicenseTypeSelected(const std::string& license_type) { |
| 234 view_->ShowEnrollmentSpinnerScreen(); |
| 235 ::policy::LicenseType license = GetLicenseTypeById(license_type); |
| 236 CHECK(license != ::policy::LicenseType::UNKNOWN) << "license_type = UNKNOWN"; |
| 237 enrollment_helper_->UseLicenseType(license); |
| 238 } |
| 206 | 239 |
| 207 void EnrollmentScreen::OnRetry() { | 240 void EnrollmentScreen::OnRetry() { |
| 208 retry_task_.Cancel(); | 241 retry_task_.Cancel(); |
| 209 ProcessRetry(); | 242 ProcessRetry(); |
| 210 } | 243 } |
| 211 | 244 |
| 212 void EnrollmentScreen::AutomaticRetry() { | 245 void EnrollmentScreen::AutomaticRetry() { |
| 213 retry_backoff_->InformOfRequest(false); | 246 retry_backoff_->InformOfRequest(false); |
| 214 retry_task_.Reset(base::Bind(&EnrollmentScreen::ProcessRetry, | 247 retry_task_.Reset(base::Bind(&EnrollmentScreen::ProcessRetry, |
| 215 weak_ptr_factory_.GetWeakPtr())); | 248 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 291 |
| 259 void EnrollmentScreen::OnAdJoined(const std::string& realm) { | 292 void EnrollmentScreen::OnAdJoined(const std::string& realm) { |
| 260 std::move(on_joined_callback_).Run(realm); | 293 std::move(on_joined_callback_).Run(realm); |
| 261 } | 294 } |
| 262 | 295 |
| 263 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { | 296 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { |
| 264 RecordEnrollmentErrorMetrics(); | 297 RecordEnrollmentErrorMetrics(); |
| 265 view_->ShowAuthError(error); | 298 view_->ShowAuthError(error); |
| 266 } | 299 } |
| 267 | 300 |
| 301 void EnrollmentScreen::OnMultipleLicensesAvailable( |
| 302 const EnrollmentLicenseMap& licenses) { |
| 303 base::DictionaryValue license_dict; |
| 304 for (const auto& it : licenses) |
| 305 license_dict.SetInteger(GetLicenseIdByType(it.first), it.second); |
| 306 view_->ShowLicenseTypeSelectionScreen(license_dict); |
| 307 } |
| 308 |
| 268 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) { | 309 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) { |
| 269 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 310 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
| 270 LOG(WARNING) << "Enrollment error occured: status=" << status.status() | 311 LOG(WARNING) << "Enrollment error occured: status=" << status.status() |
| 271 << " http status=" << status.http_status() | 312 << " http status=" << status.http_status() |
| 272 << " DM status=" << status.client_status(); | 313 << " DM status=" << status.client_status(); |
| 273 RecordEnrollmentErrorMetrics(); | 314 RecordEnrollmentErrorMetrics(); |
| 274 // If the DM server does not have a device pre-provisioned for attestation- | 315 // If the DM server does not have a device pre-provisioned for attestation- |
| 275 // based enrollment and we have a fallback authentication, show it. | 316 // based enrollment and we have a fallback authentication, show it. |
| 276 if (status.status() == policy::EnrollmentStatus::REGISTRATION_FAILED && | 317 if (status.status() == policy::EnrollmentStatus::REGISTRATION_FAILED && |
| 277 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND && | 318 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND && |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (elapsed_timer_) | 427 if (elapsed_timer_) |
| 387 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); | 428 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); |
| 388 } | 429 } |
| 389 | 430 |
| 390 void EnrollmentScreen::JoinDomain(OnDomainJoinedCallback on_joined_callback) { | 431 void EnrollmentScreen::JoinDomain(OnDomainJoinedCallback on_joined_callback) { |
| 391 on_joined_callback_ = std::move(on_joined_callback); | 432 on_joined_callback_ = std::move(on_joined_callback); |
| 392 view_->ShowAdJoin(); | 433 view_->ShowAdJoin(); |
| 393 } | 434 } |
| 394 | 435 |
| 395 } // namespace chromeos | 436 } // namespace chromeos |
| OLD | NEW |