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

Side by Side Diff: chrome/browser/chromeos/login/screens/update_screen.cc

Issue 2889383002: Revert of Make Hands-Off Zero-Touch Enrollment compatibile with tests (Closed)
Patch Set: Created 3 years, 7 months 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/screens/update_screen.h" 5 #include "chrome/browser/chromeos/login/screens/update_screen.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 switch (status.status) { 237 switch (status.status) {
238 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: 238 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE:
239 // Do nothing in these cases, we don't want to notify the user of the 239 // Do nothing in these cases, we don't want to notify the user of the
240 // check unless there is an update. 240 // check unless there is an update.
241 SetHostPairingControllerStatus( 241 SetHostPairingControllerStatus(
242 HostPairingController::UPDATE_STATUS_UPDATING); 242 HostPairingController::UPDATE_STATUS_UPDATING);
243 break; 243 break;
244 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: 244 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
245 ClearUpdateCheckNoUpdateTime();
246 MakeSureScreenIsShown(); 245 MakeSureScreenIsShown();
247 GetContextEditor() 246 GetContextEditor()
248 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) 247 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress)
249 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false); 248 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false);
250 if (!HasCriticalUpdate()) { 249 if (!HasCriticalUpdate()) {
251 VLOG(1) << "Noncritical update available: " << status.new_version; 250 VLOG(1) << "Noncritical update available: " << status.new_version;
252 ExitUpdate(REASON_UPDATE_NON_CRITICAL); 251 ExitUpdate(REASON_UPDATE_NON_CRITICAL);
253 } else { 252 } else {
254 VLOG(1) << "Critical update available: " << status.new_version; 253 VLOG(1) << "Critical update available: " << status.new_version;
255 GetContextEditor() 254 GetContextEditor()
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 547 }
549 548
550 void UpdateScreen::StartUpdateCheck() { 549 void UpdateScreen::StartUpdateCheck() {
551 error_message_timer_.Stop(); 550 error_message_timer_.Stop();
552 GetErrorScreen()->HideCaptivePortal(); 551 GetErrorScreen()->HideCaptivePortal();
553 552
554 network_portal_detector::GetInstance()->RemoveObserver(this); 553 network_portal_detector::GetInstance()->RemoveObserver(this);
555 connect_request_subscription_.reset(); 554 connect_request_subscription_.reset();
556 if (state_ == State::STATE_ERROR) 555 if (state_ == State::STATE_ERROR)
557 HideErrorMessage(); 556 HideErrorMessage();
558 557 state_ = State::STATE_UPDATE;
559 if (ShouldCheckForUpdate()) { 558 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this);
560 state_ = State::STATE_UPDATE; 559 VLOG(1) << "Initiate update check";
561 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); 560 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck(
562 VLOG(1) << "Initiate update check"; 561 base::Bind(StartUpdateCallback, this));
563 RecordUpdateCheckWithNoUpdateYet();
564 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck(
565 base::Bind(StartUpdateCallback, this));
566 } else {
567 LOG(WARNING) << "Skipping update check since one was done recently "
568 "which did not result in an update.";
569 CancelUpdate();
570 }
571 } 562 }
572 563
573 void UpdateScreen::ShowErrorMessage() { 564 void UpdateScreen::ShowErrorMessage() {
574 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; 565 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()";
575 566
576 error_message_timer_.Stop(); 567 error_message_timer_.Stop();
577 568
578 state_ = State::STATE_ERROR; 569 state_ = State::STATE_ERROR;
579 connect_request_subscription_ = 570 connect_request_subscription_ =
580 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( 571 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 &UpdateScreen::ShowErrorMessage); 622 &UpdateScreen::ShowErrorMessage);
632 } 623 }
633 624
634 void UpdateScreen::OnConnectRequested() { 625 void UpdateScreen::OnConnectRequested() {
635 if (state_ == State::STATE_ERROR) { 626 if (state_ == State::STATE_ERROR) {
636 LOG(WARNING) << "Hiding error message since AP was reselected"; 627 LOG(WARNING) << "Hiding error message since AP was reselected";
637 StartUpdateCheck(); 628 StartUpdateCheck();
638 } 629 }
639 } 630 }
640 631
641 void UpdateScreen::RecordUpdateCheckWithNoUpdateYet() {
642 StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::Now());
643 }
644
645 void UpdateScreen::ClearUpdateCheckNoUpdateTime() {
646 StartupUtils::ClearTimeOfLastUpdateCheckWithoutUpdate();
647 }
648
649 bool UpdateScreen::ShouldCheckForUpdate() {
650 // Always run update check for non hands-off enrollment.
651 if (!WizardController::UsingHandsOffEnrollment())
652 return true;
653
654 // If we check for an update and there is no need to perform an update,
655 // this is the time in hours we should wait before checking again.
656 const base::TimeDelta kUpdateCheckRecencyThreshold =
657 base::TimeDelta::FromHours(1);
658
659 base::Time now = base::Time::Now();
660 base::Time last = StartupUtils::GetTimeOfLastUpdateCheckWithoutUpdate();
661
662 // Return false if enough time has not passed since the last update check.
663 // Otherwise, return true.
664 if (now > last) {
665 return (now - last) > kUpdateCheckRecencyThreshold;
666 }
667
668 return true;
669 }
670
671 } // namespace chromeos 632 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/screens/update_screen.h ('k') | chrome/browser/chromeos/login/screens/update_screen_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698