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/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 // Delay before showing error message if captive portal is detected. | 86 // Delay before showing error message if captive portal is detected. |
87 // We wait for this delay to let captive portal to perform redirect and show | 87 // We wait for this delay to let captive portal to perform redirect and show |
88 // its login page before error message appears. | 88 // its login page before error message appears. |
89 const int kDelayErrorMessageSec = 10; | 89 const int kDelayErrorMessageSec = 10; |
90 | 90 |
91 // The delay in milliseconds at which we will send the host status to the Master | 91 // The delay in milliseconds at which we will send the host status to the Master |
92 // device periodically during the updating process. | 92 // device periodically during the updating process. |
93 const int kHostStatusReportDelay = 5 * 60 * 1000; | 93 const int kHostStatusReportDelay = 5 * 60 * 1000; |
94 | 94 |
95 // If we check for an update and there is no need to perform an update, | |
96 // this is the time in hours we should wait before checking again. | |
97 const int kUpdateCheckRecencyThresholdInHours = 1; | |
xiyuan
2017/05/09 22:03:52
nit: We can move this into where it is used since
kumarniranjan
2017/05/09 22:49:47
Done.
| |
98 | |
95 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. | 99 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. |
96 void StartUpdateCallback(UpdateScreen* screen, | 100 void StartUpdateCallback(UpdateScreen* screen, |
97 UpdateEngineClient::UpdateCheckResult result) { | 101 UpdateEngineClient::UpdateCheckResult result) { |
98 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; | 102 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; |
99 if (UpdateScreen::HasInstance(screen)) { | 103 if (UpdateScreen::HasInstance(screen)) { |
100 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) | 104 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) |
101 screen->SetIgnoreIdleStatus(false); | 105 screen->SetIgnoreIdleStatus(false); |
102 else | 106 else |
103 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); | 107 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); |
104 } | 108 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 break; | 198 break; |
195 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 199 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
196 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 200 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
197 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | 201 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
198 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | 202 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
199 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | 203 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
200 DCHECK(!HasCriticalUpdate()); | 204 DCHECK(!HasCriticalUpdate()); |
201 // Noncritical update, just exit screen as if there is no update. | 205 // Noncritical update, just exit screen as if there is no update. |
202 // no break | 206 // no break |
203 case UpdateEngineClient::UPDATE_STATUS_IDLE: | 207 case UpdateEngineClient::UPDATE_STATUS_IDLE: |
208 // At this point, there is either no update available, or there is | |
209 // a noncritical update available. No need to update during OOBE. | |
210 RecordUpdateNotRequired(); | |
204 Finish(ScreenExitCode::UPDATE_NOUPDATE); | 211 Finish(ScreenExitCode::UPDATE_NOUPDATE); |
205 break; | 212 break; |
206 case UpdateEngineClient::UPDATE_STATUS_ERROR: | 213 case UpdateEngineClient::UPDATE_STATUS_ERROR: |
207 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: | 214 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: |
208 if (is_checking_for_update_) { | 215 if (is_checking_for_update_) { |
209 Finish(ScreenExitCode::UPDATE_ERROR_CHECKING_FOR_UPDATE); | 216 Finish(ScreenExitCode::UPDATE_ERROR_CHECKING_FOR_UPDATE); |
210 } else if (HasCriticalUpdate()) { | 217 } else if (HasCriticalUpdate()) { |
211 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING_CRITICAL_UPDATE); | 218 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING_CRITICAL_UPDATE); |
212 } else { | 219 } else { |
213 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING); | 220 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 } | 552 } |
546 | 553 |
547 void UpdateScreen::StartUpdateCheck() { | 554 void UpdateScreen::StartUpdateCheck() { |
548 error_message_timer_.Stop(); | 555 error_message_timer_.Stop(); |
549 GetErrorScreen()->HideCaptivePortal(); | 556 GetErrorScreen()->HideCaptivePortal(); |
550 | 557 |
551 network_portal_detector::GetInstance()->RemoveObserver(this); | 558 network_portal_detector::GetInstance()->RemoveObserver(this); |
552 connect_request_subscription_.reset(); | 559 connect_request_subscription_.reset(); |
553 if (state_ == State::STATE_ERROR) | 560 if (state_ == State::STATE_ERROR) |
554 HideErrorMessage(); | 561 HideErrorMessage(); |
562 | |
563 if (UsingHandsOffEnrollment() && RecentUpdateCheckWithoutUpdate()) { | |
564 LOG(WARNING) << "Skipping update check since one was done recently " | |
565 "which did not result in an update."; | |
566 CancelUpdate(); | |
567 return; | |
568 } | |
569 | |
555 state_ = State::STATE_UPDATE; | 570 state_ = State::STATE_UPDATE; |
556 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 571 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
557 VLOG(1) << "Initiate update check"; | 572 VLOG(1) << "Initiate update check"; |
558 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | 573 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( |
559 base::Bind(StartUpdateCallback, this)); | 574 base::Bind(StartUpdateCallback, this)); |
560 } | 575 } |
561 | 576 |
562 void UpdateScreen::ShowErrorMessage() { | 577 void UpdateScreen::ShowErrorMessage() { |
563 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; | 578 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; |
564 | 579 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 &UpdateScreen::ShowErrorMessage); | 635 &UpdateScreen::ShowErrorMessage); |
621 } | 636 } |
622 | 637 |
623 void UpdateScreen::OnConnectRequested() { | 638 void UpdateScreen::OnConnectRequested() { |
624 if (state_ == State::STATE_ERROR) { | 639 if (state_ == State::STATE_ERROR) { |
625 LOG(WARNING) << "Hiding error message since AP was reselected"; | 640 LOG(WARNING) << "Hiding error message since AP was reselected"; |
626 StartUpdateCheck(); | 641 StartUpdateCheck(); |
627 } | 642 } |
628 } | 643 } |
629 | 644 |
645 void UpdateScreen::RecordUpdateCheckWithoutUpdate() { | |
646 StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::Now()); | |
647 } | |
648 | |
649 bool UpdateScreen::RecentUpdateCheckWithoutUpdate() { | |
650 return (base::Time::Now() - | |
xiyuan
2017/05/09 22:03:52
Wall clock could go backward. Let's do a compare b
kumarniranjan
2017/05/09 22:49:47
Done.
| |
651 StartupUtils::GetTimeOfLastUpdateCheckWithoutUpdate()) > | |
xiyuan
2017/05/09 22:03:52
GetTimeOfLastUpdateCheckWithoutUpdate() might not
kumarniranjan
2017/05/09 22:49:47
Is adding it to the PrefsRegistry enough? https://
| |
652 base::TimeDelta::FromHours(kUpdateCheckRecencyThresholdInHours); | |
653 } | |
654 | |
630 } // namespace chromeos | 655 } // namespace chromeos |
OLD | NEW |