| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 559 if (ShouldCheckForUpdate()) { | 558 state_ = State::STATE_UPDATE; |
| 560 state_ = State::STATE_UPDATE; | 559 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
| 561 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 560 VLOG(1) << "Initiate update check"; |
| 562 VLOG(1) << "Initiate update check"; | 561 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( |
| 563 RecordUpdateCheckWithNoUpdateYet(); | 562 base::Bind(StartUpdateCallback, this)); |
| 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 } | 563 } |
| 572 | 564 |
| 573 void UpdateScreen::ShowErrorMessage() { | 565 void UpdateScreen::ShowErrorMessage() { |
| 574 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; | 566 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; |
| 575 | 567 |
| 576 error_message_timer_.Stop(); | 568 error_message_timer_.Stop(); |
| 577 | 569 |
| 578 state_ = State::STATE_ERROR; | 570 state_ = State::STATE_ERROR; |
| 579 connect_request_subscription_ = | 571 connect_request_subscription_ = |
| 580 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( | 572 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 &UpdateScreen::ShowErrorMessage); | 623 &UpdateScreen::ShowErrorMessage); |
| 632 } | 624 } |
| 633 | 625 |
| 634 void UpdateScreen::OnConnectRequested() { | 626 void UpdateScreen::OnConnectRequested() { |
| 635 if (state_ == State::STATE_ERROR) { | 627 if (state_ == State::STATE_ERROR) { |
| 636 LOG(WARNING) << "Hiding error message since AP was reselected"; | 628 LOG(WARNING) << "Hiding error message since AP was reselected"; |
| 637 StartUpdateCheck(); | 629 StartUpdateCheck(); |
| 638 } | 630 } |
| 639 } | 631 } |
| 640 | 632 |
| 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 | 633 } // namespace chromeos |
| OLD | NEW |