Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/chromeos/login/enrollment/enrollment_screen.cc

Issue 2526973002: Added retry policy (Closed)
Patch Set: Added retry policy Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // static 59 // static
60 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { 60 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) {
61 return static_cast<EnrollmentScreen*>( 61 return static_cast<EnrollmentScreen*>(
62 manager->GetScreen(WizardController::kEnrollmentScreenName)); 62 manager->GetScreen(WizardController::kEnrollmentScreenName));
63 } 63 }
64 64
65 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, 65 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate,
66 EnrollmentScreenActor* actor) 66 EnrollmentScreenActor* actor)
67 : BaseScreen(base_screen_delegate), 67 : BaseScreen(base_screen_delegate),
68 actor_(actor), 68 actor_(actor),
69 weak_ptr_factory_(this) {} 69 retry_backoff_(&retry_policy_),
xiyuan 2016/11/28 22:16:34 Can we use a unique_ptr and create |retry_backoff_
kumarniranjan 2016/12/05 22:04:53 Done.
70 num_retries_(0),
xiyuan 2016/11/28 22:16:34 nit: move the initializer to header https://chrom
kumarniranjan 2016/12/05 22:04:52 Done.
71 weak_ptr_factory_(this) {
72 // It is okay to initialize the fields of retry_policy_ after constructing
73 // retry_backoff_ with a pointer to this struct.
74 retry_policy_.num_errors_to_ignore = 0;
75 retry_policy_.initial_delay_ms = 4000;
76 retry_policy_.multiply_factor = 1.5;
77 retry_policy_.jitter_factor = 0.1;
78 retry_policy_.maximum_backoff_ms = 480000;
The one and only Dr. Crash 2016/11/30 23:30:08 You set a maximum backoff but you never call Shoul
kumarniranjan 2016/12/05 22:04:52 Jonathan wanted the maximum interval between retry
joth__google 2016/12/05 22:59:26 I gave a bit of reasoning in https://codereview.ch
79 retry_policy_.entry_lifetime_ms = -1;
80 retry_policy_.always_use_initial_delay = true;
81 }
70 82
71 EnrollmentScreen::~EnrollmentScreen() { 83 EnrollmentScreen::~EnrollmentScreen() {
72 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); 84 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown());
73 } 85 }
74 86
75 void EnrollmentScreen::SetParameters( 87 void EnrollmentScreen::SetParameters(
76 const policy::EnrollmentConfig& enrollment_config, 88 const policy::EnrollmentConfig& enrollment_config,
77 pairing_chromeos::ControllerPairingController* shark_controller) { 89 pairing_chromeos::ControllerPairingController* shark_controller) {
78 enrollment_config_ = enrollment_config; 90 enrollment_config_ = enrollment_config;
79 switch (enrollment_config_.auth_mechanism) { 91 switch (enrollment_config_.auth_mechanism) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // TODO(rsorokin): Move ShowAdJoin after STEP_REGISTRATION 203 // TODO(rsorokin): Move ShowAdJoin after STEP_REGISTRATION
192 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 204 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
193 chromeos::switches::kEnableAd)) { 205 chromeos::switches::kEnableAd)) {
194 actor_->ShowAdJoin(); 206 actor_->ShowAdJoin();
195 } else { 207 } else {
196 OnAdJoined(""); 208 OnAdJoined("");
197 } 209 }
198 } 210 }
199 211
200 void EnrollmentScreen::OnRetry() { 212 void EnrollmentScreen::OnRetry() {
213 num_retries_++;
xiyuan 2016/11/28 22:16:34 nit: ++num_retries_;
The one and only Dr. Crash 2016/11/30 23:09:56 Yes! (Sorry, I am a big fan of pre-increment/decre
kumarniranjan 2016/12/05 22:04:52 Done.
214 LOG(WARNING) << "Enrollment retry " << num_retries_
215 << " initiated by user button press.";
216 ProcessRetry();
xiyuan 2016/11/28 22:16:34 retry_timer_.Stop() in case the timer is running?
kumarniranjan 2016/12/05 22:04:52 Good catch! We don't want an automatic retry to ha
217 }
218
219 void EnrollmentScreen::AutomaticRetry() {
xiyuan 2016/11/28 22:16:34 nit: AutomaticRetry -> StartRetryTimer
220 retry_backoff_.InformOfRequest(false);
221 retry_timer_.Start(FROM_HERE, retry_backoff_.GetTimeUntilRelease(),
222 base::Bind(&EnrollmentScreen::ProcessRetry,
223 weak_ptr_factory_.GetWeakPtr()));
224 num_retries_++;
xiyuan 2016/11/28 22:16:34 nit: ditto
kumarniranjan 2016/12/05 22:04:52 Done.
225 LOG(WARNING) << "Enrollment retry " << num_retries_ << " initiated by timer.";
xiyuan 2016/11/28 22:16:34 What is the purpose of |num_retries_| other than o
kumarniranjan 2016/12/05 22:04:52 It gives us the capability to set an upper limit o
226 }
227
228 void EnrollmentScreen::ProcessRetry() {
201 Show(); 229 Show();
202 } 230 }
203 231
204 void EnrollmentScreen::OnCancel() { 232 void EnrollmentScreen::OnCancel() {
205 if (AdvanceToNextAuth()) { 233 if (AdvanceToNextAuth()) {
206 Show(); 234 Show();
207 return; 235 return;
208 } 236 }
209 237
210 UMA(policy::kMetricEnrollmentCancelled); 238 UMA(policy::kMetricEnrollmentCancelled);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) { 272 void EnrollmentScreen::OnEnrollmentError(policy::EnrollmentStatus status) {
245 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. 273 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed.
246 LOG(WARNING) << "Enrollment error occured: status=" << status.status() 274 LOG(WARNING) << "Enrollment error occured: status=" << status.status()
247 << " http status=" << status.http_status() 275 << " http status=" << status.http_status()
248 << " DM status=" << status.client_status(); 276 << " DM status=" << status.client_status();
249 RecordEnrollmentErrorMetrics(); 277 RecordEnrollmentErrorMetrics();
250 // If the DM server does not have a device pre-provisioned for attestation- 278 // If the DM server does not have a device pre-provisioned for attestation-
251 // based enrollment and we have a fallback authentication, show it. 279 // based enrollment and we have a fallback authentication, show it.
252 if (status.status() == policy::EnrollmentStatus::STATUS_REGISTRATION_FAILED && 280 if (status.status() == policy::EnrollmentStatus::STATUS_REGISTRATION_FAILED &&
253 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND && 281 status.client_status() == policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND &&
254 current_auth_ == AUTH_ATTESTATION && AdvanceToNextAuth()) 282 current_auth_ == AUTH_ATTESTATION && AdvanceToNextAuth()) {
255 Show(); 283 Show();
256 else 284 } else {
257 actor_->ShowEnrollmentStatus(status); 285 actor_->ShowEnrollmentStatus(status);
286 if (policy::DeviceCloudPolicyManagerChromeOS::
287 GetZeroTouchEnrollmentMode() ==
288 policy::ZeroTouchEnrollmentMode::HANDS_OFF)
xiyuan 2016/11/28 22:16:34 nit: wrap the condition into a helper function (e.
289 AutomaticRetry();
xiyuan 2016/11/28 22:16:34 nit: wrap with {} since condition takes more than
The one and only Dr. Crash 2016/11/30 23:09:56 Probably unnecessary once a helper method is avail
290 }
258 } 291 }
259 292
260 void EnrollmentScreen::OnOtherError( 293 void EnrollmentScreen::OnOtherError(
261 EnterpriseEnrollmentHelper::OtherError error) { 294 EnterpriseEnrollmentHelper::OtherError error) {
262 RecordEnrollmentErrorMetrics(); 295 RecordEnrollmentErrorMetrics();
263 actor_->ShowOtherError(error); 296 actor_->ShowOtherError(error);
297 if (policy::DeviceCloudPolicyManagerChromeOS::GetZeroTouchEnrollmentMode() ==
298 policy::ZeroTouchEnrollmentMode::HANDS_OFF)
299 AutomaticRetry();
xiyuan 2016/11/28 22:16:33 nit: wrap with {}
The one and only Dr. Crash 2016/11/30 23:09:56 Probably unnecessary once a helper method is avail
264 } 300 }
265 301
266 void EnrollmentScreen::OnDeviceEnrolled(const std::string& additional_token) { 302 void EnrollmentScreen::OnDeviceEnrolled(const std::string& additional_token) {
267 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. 303 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed.
268 LOG(WARNING) << "Device is successfully enrolled."; 304 LOG(WARNING) << "Device is successfully enrolled.";
269 if (!additional_token.empty()) 305 if (!additional_token.empty())
270 SendEnrollmentAuthToken(additional_token); 306 SendEnrollmentAuthToken(additional_token);
271 307
272 enrollment_helper_->GetDeviceAttributeUpdatePermission(); 308 enrollment_helper_->GetDeviceAttributeUpdatePermission();
273 } 309 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 std::string location = policy ? policy->annotated_location() : std::string(); 360 std::string location = policy ? policy->annotated_location() : std::string();
325 actor_->ShowAttributePromptScreen(asset_id, location); 361 actor_->ShowAttributePromptScreen(asset_id, location);
326 } 362 }
327 363
328 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { 364 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) {
329 DCHECK(shark_controller_); 365 DCHECK(shark_controller_);
330 shark_controller_->OnAuthenticationDone(enrolling_user_domain_, token); 366 shark_controller_->OnAuthenticationDone(enrolling_user_domain_, token);
331 } 367 }
332 368
333 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { 369 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() {
370 retry_backoff_.InformOfRequest(true);
334 if (elapsed_timer_) 371 if (elapsed_timer_)
335 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); 372 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_);
336 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( 373 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus(
337 policy::EnrollmentStatus::STATUS_SUCCESS)); 374 policy::EnrollmentStatus::STATUS_SUCCESS));
338 } 375 }
339 376
340 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { 377 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) {
341 EnrollmentUMA(sample, config_.mode); 378 EnrollmentUMA(sample, config_.mode);
342 } 379 }
343 380
344 void EnrollmentScreen::ShowSigninScreen() { 381 void EnrollmentScreen::ShowSigninScreen() {
345 actor_->Show(); 382 actor_->Show();
346 actor_->ShowSigninScreen(); 383 actor_->ShowSigninScreen();
347 } 384 }
348 385
349 void EnrollmentScreen::RecordEnrollmentErrorMetrics() { 386 void EnrollmentScreen::RecordEnrollmentErrorMetrics() {
350 enrollment_failed_once_ = true; 387 enrollment_failed_once_ = true;
351 // TODO(drcrash): Maybe create multiple metrics (http://crbug.com/640313)? 388 // TODO(drcrash): Maybe create multiple metrics (http://crbug.com/640313)?
352 if (elapsed_timer_) 389 if (elapsed_timer_)
353 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); 390 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_);
354 } 391 }
355 392
356 } // namespace chromeos 393 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698