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/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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/browser_process_platform_part.h" | 14 #include "chrome/browser/browser_process_platform_part.h" |
| 15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" | 15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" |
| 16 #include "chrome/browser/chromeos/login/screen_manager.h" | 16 #include "chrome/browser/chromeos/login/screen_manager.h" |
| 17 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" | 17 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" |
| 18 #include "chrome/browser/chromeos/login/startup_utils.h" | 18 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 19 #include "chrome/browser/chromeos/login/wizard_controller.h" | 19 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 23 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 24 #include "chromeos/dbus/dbus_method_call_status.h" | 24 #include "chromeos/dbus/dbus_method_call_status.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
| 26 #include "components/pairing/controller_pairing_controller.h" | 26 #include "components/pairing/controller_pairing_controller.h" |
| 27 #include "google_apis/gaia/gaia_auth_util.h" | 27 #include "google_apis/gaia/gaia_auth_util.h" |
| 28 | 28 |
| 29 using namespace pairing_chromeos; | 29 using namespace pairing_chromeos; |
| 30 using policy::EnrollmentConfig; | |
| 30 | 31 |
| 31 // Do not change the UMA histogram parameters without renaming the histograms! | 32 // Do not change the UMA histogram parameters without renaming the histograms! |
| 32 #define UMA_ENROLLMENT_TIME(histogram_name, elapsed_timer) \ | 33 #define UMA_ENROLLMENT_TIME(histogram_name, elapsed_timer) \ |
| 33 do { \ | 34 do { \ |
| 34 UMA_HISTOGRAM_CUSTOM_TIMES( \ | 35 UMA_HISTOGRAM_CUSTOM_TIMES( \ |
| 35 (histogram_name), \ | 36 (histogram_name), \ |
| 36 (elapsed_timer)->Elapsed(), \ | 37 (elapsed_timer)->Elapsed(), \ |
| 37 base::TimeDelta::FromMilliseconds(100) /* min */, \ | 38 base::TimeDelta::FromMilliseconds(100) /* min */, \ |
| 38 base::TimeDelta::FromMinutes(15) /* max */, \ | 39 base::TimeDelta::FromMinutes(15) /* max */, \ |
| 39 100 /* bucket_count */); \ | 40 100 /* bucket_count */); \ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 54 | 55 |
| 55 // static | 56 // static |
| 56 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { | 57 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { |
| 57 return static_cast<EnrollmentScreen*>( | 58 return static_cast<EnrollmentScreen*>( |
| 58 manager->GetScreen(WizardController::kEnrollmentScreenName)); | 59 manager->GetScreen(WizardController::kEnrollmentScreenName)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, | 62 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, |
| 62 EnrollmentScreenActor* actor) | 63 EnrollmentScreenActor* actor) |
| 63 : BaseScreen(base_screen_delegate), | 64 : BaseScreen(base_screen_delegate), |
| 64 shark_controller_(NULL), | 65 shark_controller_(NULL), |
|
achuithb
2016/08/23 18:16:44
We prefer in-class initialization. Also, change th
The one and only Dr. Crash
2016/08/23 21:24:18
Done.
| |
| 65 actor_(actor), | 66 actor_(actor), |
| 67 current_auth_(AUTH_OAUTH), | |
| 68 last_auth_(AUTH_OAUTH), | |
| 66 enrollment_failed_once_(false), | 69 enrollment_failed_once_(false), |
| 67 weak_ptr_factory_(this) { | 70 weak_ptr_factory_(this) {} |
| 68 } | |
| 69 | 71 |
| 70 EnrollmentScreen::~EnrollmentScreen() { | 72 EnrollmentScreen::~EnrollmentScreen() { |
| 71 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); | 73 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void EnrollmentScreen::SetParameters( | 76 void EnrollmentScreen::SetParameters( |
| 75 const policy::EnrollmentConfig& enrollment_config, | 77 const policy::EnrollmentConfig& enrollment_config, |
| 76 pairing_chromeos::ControllerPairingController* shark_controller) { | 78 pairing_chromeos::ControllerPairingController* shark_controller) { |
| 77 enrollment_config_ = enrollment_config; | 79 enrollment_config_ = enrollment_config; |
| 80 switch (enrollment_config_.auth_mechanism) { | |
| 81 case EnrollmentConfig::AUTH_MECHANISM_INTERACTIVE: | |
| 82 current_auth_ = AUTH_OAUTH; | |
| 83 last_auth_ = AUTH_OAUTH; | |
| 84 break; | |
| 85 case EnrollmentConfig::AUTH_MECHANISM_ATTESTATION: | |
| 86 current_auth_ = AUTH_ATTESTATION; | |
| 87 last_auth_ = AUTH_ATTESTATION; | |
| 88 break; | |
| 89 case EnrollmentConfig::AUTH_MECHANISM_BEST_AVAILABLE: | |
| 90 current_auth_ = AUTH_ATTESTATION; | |
| 91 last_auth_ = enrollment_config_.should_enroll_interactively() | |
| 92 ? AUTH_OAUTH | |
| 93 : AUTH_ATTESTATION; | |
| 94 break; | |
| 95 } | |
| 78 shark_controller_ = shark_controller; | 96 shark_controller_ = shark_controller; |
| 79 actor_->SetParameters(this, enrollment_config_); | 97 SetConfig(); |
| 98 } | |
| 99 | |
| 100 void EnrollmentScreen::SetConfig() { | |
| 101 config_ = enrollment_config_; | |
| 102 if (current_auth_ == AUTH_ATTESTATION) { | |
| 103 config_.mode = enrollment_config_.is_attestation_forced() | |
| 104 ? policy::EnrollmentConfig::MODE_ATTESTATION_FORCED | |
| 105 : policy::EnrollmentConfig::MODE_ATTESTATION; | |
| 106 } | |
| 107 actor_->SetParameters(this, config_); | |
| 108 enrollment_helper_ = nullptr; | |
| 109 } | |
| 110 | |
| 111 bool EnrollmentScreen::AdvanceToNextAuth() { | |
| 112 if (current_auth_ != last_auth_ && current_auth_ == AUTH_ATTESTATION) { | |
|
achuithb
2016/08/23 18:16:44
I would reverse this and do an early exit with ret
| |
| 113 current_auth_ = AUTH_OAUTH; | |
| 114 SetConfig(); | |
| 115 return true; | |
| 116 } | |
| 117 return false; | |
| 80 } | 118 } |
| 81 | 119 |
| 82 void EnrollmentScreen::CreateEnrollmentHelper() { | 120 void EnrollmentScreen::CreateEnrollmentHelper() { |
| 83 DCHECK(!enrollment_helper_); | 121 if (!enrollment_helper_) { |
| 84 enrollment_helper_ = EnterpriseEnrollmentHelper::Create( | 122 enrollment_helper_ = EnterpriseEnrollmentHelper::Create( |
| 85 this, enrollment_config_, enrolling_user_domain_); | 123 this, config_, enrolling_user_domain_); |
| 124 } | |
| 86 } | 125 } |
| 87 | 126 |
| 88 void EnrollmentScreen::ClearAuth(const base::Closure& callback) { | 127 void EnrollmentScreen::ClearAuth(const base::Closure& callback) { |
| 89 if (!enrollment_helper_) { | 128 if (!enrollment_helper_) { |
| 90 callback.Run(); | 129 callback.Run(); |
| 91 return; | 130 return; |
| 92 } | 131 } |
| 93 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared, | 132 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared, |
| 94 weak_ptr_factory_.GetWeakPtr(), | 133 weak_ptr_factory_.GetWeakPtr(), |
| 95 callback)); | 134 callback)); |
| 96 } | 135 } |
| 97 | 136 |
| 98 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) { | 137 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) { |
| 99 enrollment_helper_.reset(); | 138 enrollment_helper_ = nullptr; |
| 100 callback.Run(); | 139 callback.Run(); |
| 101 } | 140 } |
| 102 | 141 |
| 103 void EnrollmentScreen::PrepareToShow() { | 142 void EnrollmentScreen::PrepareToShow() { |
| 104 actor_->PrepareToShow(); | 143 actor_->PrepareToShow(); |
| 105 } | 144 } |
| 106 | 145 |
| 107 void EnrollmentScreen::Show() { | 146 void EnrollmentScreen::Show() { |
| 108 UMA(policy::kMetricEnrollmentTriggered); | 147 UMA(policy::kMetricEnrollmentTriggered); |
| 148 switch (current_auth_) { | |
| 149 case AUTH_OAUTH: | |
| 150 ShowInteractiveScreen(); | |
| 151 break; | |
| 152 case AUTH_ATTESTATION: | |
| 153 AuthenticateUsingAttestation(); | |
| 154 break; | |
| 155 } | |
|
achuithb
2016/08/23 18:16:44
Add default with NOTREACHED() to future proof
The one and only Dr. Crash
2016/08/23 21:24:18
Done.
| |
| 156 } | |
| 157 | |
| 158 void EnrollmentScreen::ShowInteractiveScreen() { | |
| 109 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 159 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
| 110 weak_ptr_factory_.GetWeakPtr())); | 160 weak_ptr_factory_.GetWeakPtr())); |
| 111 } | 161 } |
| 112 | 162 |
| 113 void EnrollmentScreen::Hide() { | 163 void EnrollmentScreen::Hide() { |
| 114 actor_->Hide(); | 164 actor_->Hide(); |
| 115 weak_ptr_factory_.InvalidateWeakPtrs(); | 165 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 116 } | 166 } |
| 117 | 167 |
| 118 std::string EnrollmentScreen::GetName() const { | 168 std::string EnrollmentScreen::GetName() const { |
| 119 return WizardController::kEnrollmentScreenName; | 169 return WizardController::kEnrollmentScreenName; |
| 120 } | 170 } |
| 121 | 171 |
| 172 void EnrollmentScreen::AuthenticateUsingAttestation() { | |
| 173 VLOG(1) << "Authenticating using attestation."; | |
| 174 elapsed_timer_.reset(new base::ElapsedTimer()); | |
| 175 actor_->Show(); | |
| 176 actor_->ShowEnrollmentSpinnerScreen(); | |
| 177 CreateEnrollmentHelper(); | |
| 178 enrollment_helper_->EnrollUsingAttestation(); | |
| 179 } | |
| 180 | |
| 122 void EnrollmentScreen::OnLoginDone(const std::string& user, | 181 void EnrollmentScreen::OnLoginDone(const std::string& user, |
| 123 const std::string& auth_code) { | 182 const std::string& auth_code) { |
| 124 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty."; | 183 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty."; |
| 125 elapsed_timer_.reset(new base::ElapsedTimer()); | 184 elapsed_timer_.reset(new base::ElapsedTimer()); |
| 126 enrolling_user_domain_ = gaia::ExtractDomainName(user); | 185 enrolling_user_domain_ = gaia::ExtractDomainName(user); |
| 127 | 186 |
| 128 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted | 187 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted |
| 129 : policy::kMetricEnrollmentStarted); | 188 : policy::kMetricEnrollmentStarted); |
| 130 | 189 |
| 131 actor_->ShowEnrollmentSpinnerScreen(); | 190 actor_->ShowEnrollmentSpinnerScreen(); |
| 132 CreateEnrollmentHelper(); | 191 CreateEnrollmentHelper(); |
| 133 enrollment_helper_->EnrollUsingAuthCode( | 192 enrollment_helper_->EnrollUsingAuthCode( |
| 134 auth_code, shark_controller_ != NULL /* fetch_additional_token */); | 193 auth_code, shark_controller_ != NULL /* fetch_additional_token */); |
| 135 } | 194 } |
| 136 | 195 |
| 137 void EnrollmentScreen::OnRetry() { | 196 void EnrollmentScreen::OnRetry() { |
| 138 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 197 Show(); |
| 139 weak_ptr_factory_.GetWeakPtr())); | |
| 140 } | 198 } |
| 141 | 199 |
| 142 void EnrollmentScreen::OnCancel() { | 200 void EnrollmentScreen::OnCancel() { |
| 201 if (AdvanceToNextAuth()) { | |
| 202 Show(); | |
| 203 return; | |
| 204 } | |
| 205 | |
| 143 UMA(policy::kMetricEnrollmentCancelled); | 206 UMA(policy::kMetricEnrollmentCancelled); |
| 144 if (elapsed_timer_) | 207 if (elapsed_timer_) |
| 145 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_); | 208 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_); |
| 146 | 209 |
| 147 const BaseScreenDelegate::ExitCodes exit_code = | 210 const BaseScreenDelegate::ExitCodes exit_code = |
| 148 enrollment_config_.is_forced() | 211 config_.is_forced() ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK |
| 149 ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK | 212 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED; |
| 150 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED; | |
| 151 ClearAuth( | 213 ClearAuth( |
| 152 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code)); | 214 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code)); |
| 153 } | 215 } |
| 154 | 216 |
| 155 void EnrollmentScreen::OnConfirmationClosed() { | 217 void EnrollmentScreen::OnConfirmationClosed() { |
| 156 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), | 218 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), |
| 157 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED)); | 219 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED)); |
| 158 } | 220 } |
| 159 | 221 |
| 160 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { | 222 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 307 } |
| 246 | 308 |
| 247 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { | 309 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { |
| 248 if (elapsed_timer_) | 310 if (elapsed_timer_) |
| 249 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); | 311 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); |
| 250 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( | 312 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( |
| 251 policy::EnrollmentStatus::STATUS_SUCCESS)); | 313 policy::EnrollmentStatus::STATUS_SUCCESS)); |
| 252 } | 314 } |
| 253 | 315 |
| 254 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { | 316 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { |
| 255 EnrollmentUMA(sample, enrollment_config_.mode); | 317 EnrollmentUMA(sample, config_.mode); |
| 256 } | 318 } |
| 257 | 319 |
| 258 void EnrollmentScreen::ShowSigninScreen() { | 320 void EnrollmentScreen::ShowSigninScreen() { |
| 259 actor_->Show(); | 321 actor_->Show(); |
| 260 actor_->ShowSigninScreen(); | 322 actor_->ShowSigninScreen(); |
| 261 } | 323 } |
| 262 | 324 |
| 263 void EnrollmentScreen::OnAnyEnrollmentError() { | 325 void EnrollmentScreen::OnAnyEnrollmentError() { |
| 264 enrollment_failed_once_ = true; | 326 enrollment_failed_once_ = true; |
| 327 // TODO(drcrash): Maybe create multiple metrics for attestation vs oauth? | |
|
achuithb
2016/08/23 18:16:44
File a bug and reference it here.
The one and only Dr. Crash
2016/08/23 21:24:18
Done.
| |
| 265 if (elapsed_timer_) | 328 if (elapsed_timer_) |
| 266 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); | 329 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); |
| 267 } | 330 } |
| 268 | 331 |
| 269 } // namespace chromeos | 332 } // namespace chromeos |
| OLD | NEW |