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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 break; | 194 break; |
195 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 195 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
196 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 196 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
197 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | 197 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
198 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | 198 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
199 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | 199 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
200 DCHECK(!HasCriticalUpdate()); | 200 DCHECK(!HasCriticalUpdate()); |
201 // Noncritical update, just exit screen as if there is no update. | 201 // Noncritical update, just exit screen as if there is no update. |
202 // no break | 202 // no break |
203 case UpdateEngineClient::UPDATE_STATUS_IDLE: | 203 case UpdateEngineClient::UPDATE_STATUS_IDLE: |
204 // At this point, there is either no update available, or there is | |
205 // a noncritical update available. No need to update during OOBE. | |
xiyuan
2017/05/10 16:29:19
nit: "No need to update during OOBE." -> "Record t
kumarniranjan
2017/05/13 04:42:36
Done.
| |
206 RecordUpdateCheckWithoutUpdate(); | |
204 Finish(ScreenExitCode::UPDATE_NOUPDATE); | 207 Finish(ScreenExitCode::UPDATE_NOUPDATE); |
205 break; | 208 break; |
206 case UpdateEngineClient::UPDATE_STATUS_ERROR: | 209 case UpdateEngineClient::UPDATE_STATUS_ERROR: |
207 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: | 210 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: |
208 if (is_checking_for_update_) { | 211 if (is_checking_for_update_) { |
209 Finish(ScreenExitCode::UPDATE_ERROR_CHECKING_FOR_UPDATE); | 212 Finish(ScreenExitCode::UPDATE_ERROR_CHECKING_FOR_UPDATE); |
210 } else if (HasCriticalUpdate()) { | 213 } else if (HasCriticalUpdate()) { |
211 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING_CRITICAL_UPDATE); | 214 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING_CRITICAL_UPDATE); |
212 } else { | 215 } else { |
213 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING); | 216 Finish(ScreenExitCode::UPDATE_ERROR_UPDATING); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 } | 548 } |
546 | 549 |
547 void UpdateScreen::StartUpdateCheck() { | 550 void UpdateScreen::StartUpdateCheck() { |
548 error_message_timer_.Stop(); | 551 error_message_timer_.Stop(); |
549 GetErrorScreen()->HideCaptivePortal(); | 552 GetErrorScreen()->HideCaptivePortal(); |
550 | 553 |
551 network_portal_detector::GetInstance()->RemoveObserver(this); | 554 network_portal_detector::GetInstance()->RemoveObserver(this); |
552 connect_request_subscription_.reset(); | 555 connect_request_subscription_.reset(); |
553 if (state_ == State::STATE_ERROR) | 556 if (state_ == State::STATE_ERROR) |
554 HideErrorMessage(); | 557 HideErrorMessage(); |
555 state_ = State::STATE_UPDATE; | 558 |
556 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 559 if (ShouldCheckForUpdate()) { |
557 VLOG(1) << "Initiate update check"; | 560 state_ = State::STATE_UPDATE; |
558 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | 561 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
559 base::Bind(StartUpdateCallback, this)); | 562 VLOG(1) << "Initiate update check"; |
563 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | |
564 base::Bind(StartUpdateCallback, this)); | |
565 } else { | |
566 LOG(WARNING) << "Skipping update check since one was done recently " | |
567 "which did not result in an update."; | |
568 CancelUpdate(); | |
569 } | |
560 } | 570 } |
561 | 571 |
562 void UpdateScreen::ShowErrorMessage() { | 572 void UpdateScreen::ShowErrorMessage() { |
563 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; | 573 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; |
564 | 574 |
565 error_message_timer_.Stop(); | 575 error_message_timer_.Stop(); |
566 | 576 |
567 state_ = State::STATE_ERROR; | 577 state_ = State::STATE_ERROR; |
568 connect_request_subscription_ = | 578 connect_request_subscription_ = |
569 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( | 579 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 &UpdateScreen::ShowErrorMessage); | 630 &UpdateScreen::ShowErrorMessage); |
621 } | 631 } |
622 | 632 |
623 void UpdateScreen::OnConnectRequested() { | 633 void UpdateScreen::OnConnectRequested() { |
624 if (state_ == State::STATE_ERROR) { | 634 if (state_ == State::STATE_ERROR) { |
625 LOG(WARNING) << "Hiding error message since AP was reselected"; | 635 LOG(WARNING) << "Hiding error message since AP was reselected"; |
626 StartUpdateCheck(); | 636 StartUpdateCheck(); |
627 } | 637 } |
628 } | 638 } |
629 | 639 |
640 void UpdateScreen::RecordUpdateCheckWithoutUpdate() { | |
641 StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::Now()); | |
642 } | |
643 | |
644 bool UpdateScreen::ShouldCheckForUpdate() { | |
645 // If we check for an update and there is no need to perform an update, | |
646 // this is the time in hours we should wait before checking again. | |
647 const int kUpdateCheckRecencyThresholdInHours = 1; | |
xiyuan
2017/05/10 16:29:19
nit: since we are in a function scoped, we can use
kumarniranjan
2017/05/13 04:42:35
Done.
| |
648 | |
649 base::Time now = base::Time::Now(); | |
650 base::Time last = StartupUtils::GetTimeOfLastUpdateCheckWithoutUpdate(); | |
651 | |
652 if (WizardController::UsingHandsOffEnrollment()) { | |
653 if (now > last) { | |
654 return (now - last) > | |
655 base::TimeDelta::FromHours(kUpdateCheckRecencyThresholdInHours); | |
656 } else { | |
657 return false; | |
xiyuan
2017/05/10 16:29:19
I think we should "return true" to allow update ch
kumarniranjan
2017/05/13 04:42:35
Done.
| |
658 } | |
659 } else { | |
660 return true; | |
xiyuan
2017/05/10 16:29:20
nit: move this to the beginning of the function an
kumarniranjan
2017/05/13 04:42:35
Done.
| |
661 } | |
662 } | |
663 | |
630 } // namespace chromeos | 664 } // namespace chromeos |
OLD | NEW |