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 actor_(actor), | 65 actor_(actor), |
66 enrollment_failed_once_(false), | 66 weak_ptr_factory_(this) {} |
67 weak_ptr_factory_(this) { | |
68 } | |
69 | 67 |
70 EnrollmentScreen::~EnrollmentScreen() { | 68 EnrollmentScreen::~EnrollmentScreen() { |
71 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); | 69 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); |
72 } | 70 } |
73 | 71 |
74 void EnrollmentScreen::SetParameters( | 72 void EnrollmentScreen::SetParameters( |
75 const policy::EnrollmentConfig& enrollment_config, | 73 const policy::EnrollmentConfig& enrollment_config, |
76 pairing_chromeos::ControllerPairingController* shark_controller) { | 74 pairing_chromeos::ControllerPairingController* shark_controller) { |
77 enrollment_config_ = enrollment_config; | 75 enrollment_config_ = enrollment_config; |
| 76 switch (enrollment_config_.auth_mechanism) { |
| 77 case EnrollmentConfig::AUTH_MECHANISM_INTERACTIVE: |
| 78 current_auth_ = AUTH_OAUTH; |
| 79 last_auth_ = AUTH_OAUTH; |
| 80 break; |
| 81 case EnrollmentConfig::AUTH_MECHANISM_ATTESTATION: |
| 82 current_auth_ = AUTH_ATTESTATION; |
| 83 last_auth_ = AUTH_ATTESTATION; |
| 84 break; |
| 85 case EnrollmentConfig::AUTH_MECHANISM_BEST_AVAILABLE: |
| 86 current_auth_ = AUTH_ATTESTATION; |
| 87 last_auth_ = enrollment_config_.should_enroll_interactively() |
| 88 ? AUTH_OAUTH |
| 89 : AUTH_ATTESTATION; |
| 90 break; |
| 91 default: |
| 92 NOTREACHED(); |
| 93 break; |
| 94 } |
78 shark_controller_ = shark_controller; | 95 shark_controller_ = shark_controller; |
79 actor_->SetParameters(this, enrollment_config_); | 96 SetConfig(); |
| 97 } |
| 98 |
| 99 void EnrollmentScreen::SetConfig() { |
| 100 config_ = enrollment_config_; |
| 101 if (current_auth_ == AUTH_ATTESTATION) { |
| 102 config_.mode = enrollment_config_.is_attestation_forced() |
| 103 ? policy::EnrollmentConfig::MODE_ATTESTATION_FORCED |
| 104 : policy::EnrollmentConfig::MODE_ATTESTATION; |
| 105 } |
| 106 actor_->SetParameters(this, config_); |
| 107 enrollment_helper_ = nullptr; |
| 108 } |
| 109 |
| 110 bool EnrollmentScreen::AdvanceToNextAuth() { |
| 111 if (current_auth_ != last_auth_ && current_auth_ == AUTH_ATTESTATION) { |
| 112 current_auth_ = AUTH_OAUTH; |
| 113 SetConfig(); |
| 114 return true; |
| 115 } |
| 116 return false; |
80 } | 117 } |
81 | 118 |
82 void EnrollmentScreen::CreateEnrollmentHelper() { | 119 void EnrollmentScreen::CreateEnrollmentHelper() { |
83 DCHECK(!enrollment_helper_); | 120 if (!enrollment_helper_) { |
84 enrollment_helper_ = EnterpriseEnrollmentHelper::Create( | 121 enrollment_helper_ = EnterpriseEnrollmentHelper::Create( |
85 this, enrollment_config_, enrolling_user_domain_); | 122 this, config_, enrolling_user_domain_); |
| 123 } |
86 } | 124 } |
87 | 125 |
88 void EnrollmentScreen::ClearAuth(const base::Closure& callback) { | 126 void EnrollmentScreen::ClearAuth(const base::Closure& callback) { |
89 if (!enrollment_helper_) { | 127 if (!enrollment_helper_) { |
90 callback.Run(); | 128 callback.Run(); |
91 return; | 129 return; |
92 } | 130 } |
93 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared, | 131 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared, |
94 weak_ptr_factory_.GetWeakPtr(), | 132 weak_ptr_factory_.GetWeakPtr(), |
95 callback)); | 133 callback)); |
96 } | 134 } |
97 | 135 |
98 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) { | 136 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) { |
99 enrollment_helper_.reset(); | 137 enrollment_helper_ = nullptr; |
100 callback.Run(); | 138 callback.Run(); |
101 } | 139 } |
102 | 140 |
103 void EnrollmentScreen::PrepareToShow() { | 141 void EnrollmentScreen::PrepareToShow() { |
104 actor_->PrepareToShow(); | 142 actor_->PrepareToShow(); |
105 } | 143 } |
106 | 144 |
107 void EnrollmentScreen::Show() { | 145 void EnrollmentScreen::Show() { |
108 UMA(policy::kMetricEnrollmentTriggered); | 146 UMA(policy::kMetricEnrollmentTriggered); |
| 147 switch (current_auth_) { |
| 148 case AUTH_OAUTH: |
| 149 ShowInteractiveScreen(); |
| 150 break; |
| 151 case AUTH_ATTESTATION: |
| 152 AuthenticateUsingAttestation(); |
| 153 break; |
| 154 default: |
| 155 NOTREACHED(); |
| 156 break; |
| 157 } |
| 158 } |
| 159 |
| 160 void EnrollmentScreen::ShowInteractiveScreen() { |
109 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 161 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
110 weak_ptr_factory_.GetWeakPtr())); | 162 weak_ptr_factory_.GetWeakPtr())); |
111 } | 163 } |
112 | 164 |
113 void EnrollmentScreen::Hide() { | 165 void EnrollmentScreen::Hide() { |
114 actor_->Hide(); | 166 actor_->Hide(); |
115 weak_ptr_factory_.InvalidateWeakPtrs(); | 167 weak_ptr_factory_.InvalidateWeakPtrs(); |
116 } | 168 } |
117 | 169 |
118 std::string EnrollmentScreen::GetName() const { | 170 std::string EnrollmentScreen::GetName() const { |
119 return WizardController::kEnrollmentScreenName; | 171 return WizardController::kEnrollmentScreenName; |
120 } | 172 } |
121 | 173 |
| 174 void EnrollmentScreen::AuthenticateUsingAttestation() { |
| 175 VLOG(1) << "Authenticating using attestation."; |
| 176 elapsed_timer_.reset(new base::ElapsedTimer()); |
| 177 actor_->Show(); |
| 178 actor_->ShowEnrollmentSpinnerScreen(); |
| 179 CreateEnrollmentHelper(); |
| 180 enrollment_helper_->EnrollUsingAttestation(); |
| 181 } |
| 182 |
122 void EnrollmentScreen::OnLoginDone(const std::string& user, | 183 void EnrollmentScreen::OnLoginDone(const std::string& user, |
123 const std::string& auth_code) { | 184 const std::string& auth_code) { |
124 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty."; | 185 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty."; |
125 elapsed_timer_.reset(new base::ElapsedTimer()); | 186 elapsed_timer_.reset(new base::ElapsedTimer()); |
126 enrolling_user_domain_ = gaia::ExtractDomainName(user); | 187 enrolling_user_domain_ = gaia::ExtractDomainName(user); |
127 | 188 |
128 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted | 189 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted |
129 : policy::kMetricEnrollmentStarted); | 190 : policy::kMetricEnrollmentStarted); |
130 | 191 |
131 actor_->ShowEnrollmentSpinnerScreen(); | 192 actor_->ShowEnrollmentSpinnerScreen(); |
132 CreateEnrollmentHelper(); | 193 CreateEnrollmentHelper(); |
133 enrollment_helper_->EnrollUsingAuthCode( | 194 enrollment_helper_->EnrollUsingAuthCode( |
134 auth_code, shark_controller_ != NULL /* fetch_additional_token */); | 195 auth_code, shark_controller_ != nullptr /* fetch_additional_token */); |
135 } | 196 } |
136 | 197 |
137 void EnrollmentScreen::OnRetry() { | 198 void EnrollmentScreen::OnRetry() { |
138 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 199 Show(); |
139 weak_ptr_factory_.GetWeakPtr())); | |
140 } | 200 } |
141 | 201 |
142 void EnrollmentScreen::OnCancel() { | 202 void EnrollmentScreen::OnCancel() { |
| 203 if (AdvanceToNextAuth()) { |
| 204 Show(); |
| 205 return; |
| 206 } |
| 207 |
143 UMA(policy::kMetricEnrollmentCancelled); | 208 UMA(policy::kMetricEnrollmentCancelled); |
144 if (elapsed_timer_) | 209 if (elapsed_timer_) |
145 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_); | 210 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_); |
146 | 211 |
147 const BaseScreenDelegate::ExitCodes exit_code = | 212 const BaseScreenDelegate::ExitCodes exit_code = |
148 enrollment_config_.is_forced() | 213 config_.is_forced() ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK |
149 ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK | 214 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED; |
150 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED; | |
151 ClearAuth( | 215 ClearAuth( |
152 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code)); | 216 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code)); |
153 } | 217 } |
154 | 218 |
155 void EnrollmentScreen::OnConfirmationClosed() { | 219 void EnrollmentScreen::OnConfirmationClosed() { |
156 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), | 220 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), |
157 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED)); | 221 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED)); |
158 } | 222 } |
159 | 223 |
160 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { | 224 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 309 } |
246 | 310 |
247 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { | 311 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { |
248 if (elapsed_timer_) | 312 if (elapsed_timer_) |
249 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); | 313 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); |
250 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( | 314 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( |
251 policy::EnrollmentStatus::STATUS_SUCCESS)); | 315 policy::EnrollmentStatus::STATUS_SUCCESS)); |
252 } | 316 } |
253 | 317 |
254 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { | 318 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { |
255 EnrollmentUMA(sample, enrollment_config_.mode); | 319 EnrollmentUMA(sample, config_.mode); |
256 } | 320 } |
257 | 321 |
258 void EnrollmentScreen::ShowSigninScreen() { | 322 void EnrollmentScreen::ShowSigninScreen() { |
259 actor_->Show(); | 323 actor_->Show(); |
260 actor_->ShowSigninScreen(); | 324 actor_->ShowSigninScreen(); |
261 } | 325 } |
262 | 326 |
263 void EnrollmentScreen::OnAnyEnrollmentError() { | 327 void EnrollmentScreen::OnAnyEnrollmentError() { |
264 enrollment_failed_once_ = true; | 328 enrollment_failed_once_ = true; |
| 329 // TODO(drcrash): Maybe create multiple metrics (http://crbug.com/640313)? |
265 if (elapsed_timer_) | 330 if (elapsed_timer_) |
266 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); | 331 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); |
267 } | 332 } |
268 | 333 |
269 } // namespace chromeos | 334 } // namespace chromeos |
OLD | NEW |