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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 const char * const kMetricEnrollmentTimeCancel = | 48 const char * const kMetricEnrollmentTimeCancel = |
49 "Enterprise.EnrollmentTime.Cancel"; | 49 "Enterprise.EnrollmentTime.Cancel"; |
50 const char * const kMetricEnrollmentTimeFailure = | 50 const char * const kMetricEnrollmentTimeFailure = |
51 "Enterprise.EnrollmentTime.Failure"; | 51 "Enterprise.EnrollmentTime.Failure"; |
52 const char * const kMetricEnrollmentTimeSuccess = | 52 const char * const kMetricEnrollmentTimeSuccess = |
53 "Enterprise.EnrollmentTime.Success"; | 53 "Enterprise.EnrollmentTime.Success"; |
54 | 54 |
55 // Retry policy constants. | |
56 const int INITIAL_DELAY_MS = 4 * 1000; // 4 seconds | |
xiyuan
2017/02/03 23:34:14
nit: constant should be name as kTheConstantName,
kumarniranjan
2017/02/06 21:38:24
Done.
| |
57 const double MULTIPLY_FACTOR = 1.5; | |
58 const double JITTER_FACTOR = 0.1; // +/- 10% jitter | |
59 const int64_t MAX_DELAY_MS = 8 * 60 * 1000; // 8 minutes | |
60 | |
61 // Helper function. Returns true if we are using Hands Off Enrollment. | |
62 bool UsingHandsOffEnrollment() { | |
63 return policy::DeviceCloudPolicyManagerChromeOS:: | |
64 GetZeroTouchEnrollmentMode() == | |
65 policy::ZeroTouchEnrollmentMode::HANDS_OFF; | |
66 } | |
67 | |
55 } // namespace | 68 } // namespace |
56 | 69 |
57 namespace chromeos { | 70 namespace chromeos { |
58 | 71 |
59 // static | 72 // static |
60 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { | 73 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { |
61 return static_cast<EnrollmentScreen*>( | 74 return static_cast<EnrollmentScreen*>( |
62 manager->GetScreen(OobeScreen::SCREEN_OOBE_ENROLLMENT)); | 75 manager->GetScreen(OobeScreen::SCREEN_OOBE_ENROLLMENT)); |
63 } | 76 } |
64 | 77 |
65 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, | 78 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, |
66 EnrollmentScreenActor* actor) | 79 EnrollmentScreenActor* actor) |
67 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_ENROLLMENT), | 80 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_ENROLLMENT), |
68 actor_(actor), | 81 actor_(actor), |
69 weak_ptr_factory_(this) {} | 82 weak_ptr_factory_(this) { |
83 retry_policy_.num_errors_to_ignore = 0; | |
84 retry_policy_.initial_delay_ms = INITIAL_DELAY_MS; | |
85 retry_policy_.multiply_factor = MULTIPLY_FACTOR; | |
86 retry_policy_.jitter_factor = JITTER_FACTOR; | |
87 retry_policy_.maximum_backoff_ms = MAX_DELAY_MS; | |
88 retry_policy_.entry_lifetime_ms = -1; | |
89 retry_policy_.always_use_initial_delay = true; | |
90 retry_backoff_.reset(new net::BackoffEntry(&retry_policy_)); | |
91 } | |
70 | 92 |
71 EnrollmentScreen::~EnrollmentScreen() { | 93 EnrollmentScreen::~EnrollmentScreen() { |
72 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); | 94 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); |
73 } | 95 } |
74 | 96 |
75 void EnrollmentScreen::SetParameters( | 97 void EnrollmentScreen::SetParameters( |
76 const policy::EnrollmentConfig& enrollment_config, | 98 const policy::EnrollmentConfig& enrollment_config, |
77 pairing_chromeos::ControllerPairingController* shark_controller) { | 99 pairing_chromeos::ControllerPairingController* shark_controller) { |
78 enrollment_config_ = enrollment_config; | 100 enrollment_config_ = enrollment_config; |
79 switch (enrollment_config_.auth_mechanism) { | 101 switch (enrollment_config_.auth_mechanism) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 // TODO(rsorokin): Move ShowAdJoin after STEP_REGISTRATION | 205 // TODO(rsorokin): Move ShowAdJoin after STEP_REGISTRATION |
184 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 206 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
185 chromeos::switches::kEnableAd)) { | 207 chromeos::switches::kEnableAd)) { |
186 actor_->ShowAdJoin(); | 208 actor_->ShowAdJoin(); |
187 } else { | 209 } else { |
188 OnAdJoined(""); | 210 OnAdJoined(""); |
189 } | 211 } |
190 } | 212 } |
191 | 213 |
192 void EnrollmentScreen::OnRetry() { | 214 void EnrollmentScreen::OnRetry() { |
215 retry_task_.Cancel(); | |
216 ProcessRetry(); | |
217 } | |
218 | |
219 void EnrollmentScreen::AutomaticRetry() { | |
220 retry_backoff_->InformOfRequest(false); | |
221 retry_task_.Reset(base::Bind(&EnrollmentScreen::ProcessRetry, | |
222 weak_ptr_factory_.GetWeakPtr())); | |
223 | |
224 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
225 FROM_HERE, retry_task_.callback(), retry_backoff_->GetTimeUntilRelease()); | |
226 } | |
227 | |
228 void EnrollmentScreen::ProcessRetry() { | |
229 num_retries_++; | |
xiyuan
2017/02/03 23:34:14
nit: use pre-increment,
i.e.
++num_retries_;
kumarniranjan
2017/02/06 21:38:24
Done.
| |
230 LOG(WARNING) << "Enrollment retry " << num_retries_; | |
193 Show(); | 231 Show(); |
194 } | 232 } |
195 | 233 |
196 void EnrollmentScreen::OnCancel() { | 234 void EnrollmentScreen::OnCancel() { |
197 if (AdvanceToNextAuth()) { | 235 if (AdvanceToNextAuth()) { |
198 Show(); | 236 Show(); |
199 return; | 237 return; |
200 } | 238 } |
201 | 239 |
202 UMA(policy::kMetricEnrollmentCancelled); | 240 UMA(policy::kMetricEnrollmentCancelled); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) { | 274 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) { |
237 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 275 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
238 LOG(WARNING) << "Enrollment error occured: status=" << status.status() | 276 LOG(WARNING) << "Enrollment error occured: status=" << status.status() |
239 << " http status=" << status.http_status() | 277 << " http status=" << status.http_status() |
240 << " DM status=" << status.client_status(); | 278 << " DM status=" << status.client_status(); |
241 RecordEnrollmentErrorMetrics(); | 279 RecordEnrollmentErrorMetrics(); |
242 // If the DM server does not have a device pre-provisioned for attestation- | 280 // If the DM server does not have a device pre-provisioned for attestation- |
243 // based enrollment and we have a fallback authentication, show it. | 281 // based enrollment and we have a fallback authentication, show it. |
244 if (status.status() == policy::EnrollmentStatus::REGISTRATION_FAILED && | 282 if (status.status() == policy::EnrollmentStatus::REGISTRATION_FAILED && |
245 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND && | 283 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND && |
246 current_auth_ == AUTH_ATTESTATION && AdvanceToNextAuth()) | 284 current_auth_ == AUTH_ATTESTATION && AdvanceToNextAuth()) { |
247 Show(); | 285 Show(); |
248 else | 286 } else { |
249 actor_->ShowEnrollmentStatus(status); | 287 actor_->ShowEnrollmentStatus(status); |
288 if (UsingHandsOffEnrollment()) | |
289 AutomaticRetry(); | |
290 } | |
250 } | 291 } |
251 | 292 |
252 void EnrollmentScreen::OnOtherError( | 293 void EnrollmentScreen::OnOtherError( |
253 EnterpriseEnrollmentHelper::OtherError error) { | 294 EnterpriseEnrollmentHelper::OtherError error) { |
254 RecordEnrollmentErrorMetrics(); | 295 RecordEnrollmentErrorMetrics(); |
255 actor_->ShowOtherError(error); | 296 actor_->ShowOtherError(error); |
297 if (UsingHandsOffEnrollment()) | |
298 AutomaticRetry(); | |
256 } | 299 } |
257 | 300 |
258 void EnrollmentScreen::OnDeviceEnrolled(const std::string& additional_token) { | 301 void EnrollmentScreen::OnDeviceEnrolled(const std::string& additional_token) { |
259 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. | 302 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. |
260 LOG(WARNING) << "Device is successfully enrolled."; | 303 LOG(WARNING) << "Device is successfully enrolled."; |
261 if (!additional_token.empty()) | 304 if (!additional_token.empty()) |
262 SendEnrollmentAuthToken(additional_token); | 305 SendEnrollmentAuthToken(additional_token); |
263 | 306 |
264 enrollment_helper_->GetDeviceAttributeUpdatePermission(); | 307 enrollment_helper_->GetDeviceAttributeUpdatePermission(); |
265 } | 308 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 std::string location = policy ? policy->annotated_location() : std::string(); | 359 std::string location = policy ? policy->annotated_location() : std::string(); |
317 actor_->ShowAttributePromptScreen(asset_id, location); | 360 actor_->ShowAttributePromptScreen(asset_id, location); |
318 } | 361 } |
319 | 362 |
320 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { | 363 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { |
321 DCHECK(shark_controller_); | 364 DCHECK(shark_controller_); |
322 shark_controller_->OnAuthenticationDone(enrolling_user_domain_, token); | 365 shark_controller_->OnAuthenticationDone(enrolling_user_domain_, token); |
323 } | 366 } |
324 | 367 |
325 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { | 368 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { |
369 retry_backoff_->InformOfRequest(true); | |
326 if (elapsed_timer_) | 370 if (elapsed_timer_) |
327 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); | 371 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); |
328 actor_->ShowEnrollmentStatus( | 372 actor_->ShowEnrollmentStatus( |
329 policy::EnrollmentStatus::ForStatus(policy::EnrollmentStatus::SUCCESS)); | 373 policy::EnrollmentStatus::ForStatus(policy::EnrollmentStatus::SUCCESS)); |
330 } | 374 } |
331 | 375 |
332 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { | 376 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { |
333 EnrollmentUMA(sample, config_.mode); | 377 EnrollmentUMA(sample, config_.mode); |
334 } | 378 } |
335 | 379 |
336 void EnrollmentScreen::ShowSigninScreen() { | 380 void EnrollmentScreen::ShowSigninScreen() { |
337 actor_->Show(); | 381 actor_->Show(); |
338 actor_->ShowSigninScreen(); | 382 actor_->ShowSigninScreen(); |
339 } | 383 } |
340 | 384 |
341 void EnrollmentScreen::RecordEnrollmentErrorMetrics() { | 385 void EnrollmentScreen::RecordEnrollmentErrorMetrics() { |
342 enrollment_failed_once_ = true; | 386 enrollment_failed_once_ = true; |
343 // TODO(drcrash): Maybe create multiple metrics (http://crbug.com/640313)? | 387 // TODO(drcrash): Maybe create multiple metrics (http://crbug.com/640313)? |
344 if (elapsed_timer_) | 388 if (elapsed_timer_) |
345 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); | 389 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); |
346 } | 390 } |
347 | 391 |
348 } // namespace chromeos | 392 } // namespace chromeos |
OLD | NEW |