Chromium Code Reviews| Index: chrome/browser/chromeos/login/screens/update_screen.cc |
| diff --git a/chrome/browser/chromeos/login/screens/update_screen.cc b/chrome/browser/chromeos/login/screens/update_screen.cc |
| index 96a797ed24a134e20f9afe24d7822205b133bc7b..e16f0b32a028d52f4e5f545ecef432779132ab0f 100644 |
| --- a/chrome/browser/chromeos/login/screens/update_screen.cc |
| +++ b/chrome/browser/chromeos/login/screens/update_screen.cc |
| @@ -241,6 +241,7 @@ void UpdateScreen::UpdateStatusChanged( |
| HostPairingController::UPDATE_STATUS_UPDATING); |
| break; |
| case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
| + RecordUpdateCheckResultingInUpdate(); |
| MakeSureScreenIsShown(); |
| GetContextEditor() |
| .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) |
| @@ -552,11 +553,19 @@ void UpdateScreen::StartUpdateCheck() { |
| connect_request_subscription_.reset(); |
| if (state_ == State::STATE_ERROR) |
| HideErrorMessage(); |
| - state_ = State::STATE_UPDATE; |
| - DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
| - VLOG(1) << "Initiate update check"; |
| - DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( |
| - base::Bind(StartUpdateCallback, this)); |
| + |
| + if (ShouldCheckForUpdate()) { |
| + state_ = State::STATE_UPDATE; |
| + DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
| + VLOG(1) << "Initiate update check"; |
| + RecordUpdateCheckWithNoUpdateYet(); |
| + DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( |
| + base::Bind(StartUpdateCallback, this)); |
| + } else { |
| + LOG(WARNING) << "Skipping update check since one was done recently " |
| + "which did not result in an update."; |
| + CancelUpdate(); |
| + } |
| } |
| void UpdateScreen::ShowErrorMessage() { |
| @@ -627,4 +636,34 @@ void UpdateScreen::OnConnectRequested() { |
| } |
| } |
| +void UpdateScreen::RecordUpdateCheckWithNoUpdateYet() { |
| + StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::Now()); |
| +} |
| + |
| +void UpdateScreen::RecordUpdateCheckResultingInUpdate() { |
|
xiyuan
2017/05/15 17:24:22
This name is confusing. How about call it ClearUpd
kumarniranjan
2017/05/15 22:08:21
Done.
|
| + StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::UnixEpoch()); |
| +} |
| + |
| +bool UpdateScreen::ShouldCheckForUpdate() { |
| + // Always run update check for non hands-off enrollment. |
| + if (!WizardController::UsingHandsOffEnrollment()) |
| + return true; |
| + |
| + // If we check for an update and there is no need to perform an update, |
| + // this is the time in hours we should wait before checking again. |
| + const base::TimeDelta kUpdateCheckRecencyThreshold = |
| + base::TimeDelta::FromHours(1); |
| + |
| + base::Time now = base::Time::Now(); |
| + base::Time last = StartupUtils::GetTimeOfLastUpdateCheckWithoutUpdate(); |
| + |
| + // Return false if enough time has not passed since the last update check. |
| + // Otherwise, return true. |
| + if (now > last) { |
| + return (now - last) > kUpdateCheckRecencyThreshold; |
| + } else { |
|
xiyuan
2017/05/15 17:24:22
nit: get rid of "else"
kumarniranjan
2017/05/15 22:08:21
Done.
|
| + return true; |
| + } |
| +} |
| + |
| } // namespace chromeos |