| 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(); |
| 245 MakeSureScreenIsShown(); | 246 MakeSureScreenIsShown(); |
| 246 GetContextEditor() | 247 GetContextEditor() |
| 247 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) | 248 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) |
| 248 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false); | 249 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false); |
| 249 if (!HasCriticalUpdate()) { | 250 if (!HasCriticalUpdate()) { |
| 250 VLOG(1) << "Noncritical update available: " << status.new_version; | 251 VLOG(1) << "Noncritical update available: " << status.new_version; |
| 251 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 252 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 252 } else { | 253 } else { |
| 253 VLOG(1) << "Critical update available: " << status.new_version; | 254 VLOG(1) << "Critical update available: " << status.new_version; |
| 254 GetContextEditor() | 255 GetContextEditor() |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 548 } |
| 548 | 549 |
| 549 void UpdateScreen::StartUpdateCheck() { | 550 void UpdateScreen::StartUpdateCheck() { |
| 550 error_message_timer_.Stop(); | 551 error_message_timer_.Stop(); |
| 551 GetErrorScreen()->HideCaptivePortal(); | 552 GetErrorScreen()->HideCaptivePortal(); |
| 552 | 553 |
| 553 network_portal_detector::GetInstance()->RemoveObserver(this); | 554 network_portal_detector::GetInstance()->RemoveObserver(this); |
| 554 connect_request_subscription_.reset(); | 555 connect_request_subscription_.reset(); |
| 555 if (state_ == State::STATE_ERROR) | 556 if (state_ == State::STATE_ERROR) |
| 556 HideErrorMessage(); | 557 HideErrorMessage(); |
| 557 state_ = State::STATE_UPDATE; | 558 |
| 558 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 559 if (ShouldCheckForUpdate()) { |
| 559 VLOG(1) << "Initiate update check"; | 560 state_ = State::STATE_UPDATE; |
| 560 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | 561 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
| 561 base::Bind(StartUpdateCallback, this)); | 562 VLOG(1) << "Initiate update check"; |
| 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 } |
| 562 } | 571 } |
| 563 | 572 |
| 564 void UpdateScreen::ShowErrorMessage() { | 573 void UpdateScreen::ShowErrorMessage() { |
| 565 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; | 574 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; |
| 566 | 575 |
| 567 error_message_timer_.Stop(); | 576 error_message_timer_.Stop(); |
| 568 | 577 |
| 569 state_ = State::STATE_ERROR; | 578 state_ = State::STATE_ERROR; |
| 570 connect_request_subscription_ = | 579 connect_request_subscription_ = |
| 571 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( | 580 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 &UpdateScreen::ShowErrorMessage); | 631 &UpdateScreen::ShowErrorMessage); |
| 623 } | 632 } |
| 624 | 633 |
| 625 void UpdateScreen::OnConnectRequested() { | 634 void UpdateScreen::OnConnectRequested() { |
| 626 if (state_ == State::STATE_ERROR) { | 635 if (state_ == State::STATE_ERROR) { |
| 627 LOG(WARNING) << "Hiding error message since AP was reselected"; | 636 LOG(WARNING) << "Hiding error message since AP was reselected"; |
| 628 StartUpdateCheck(); | 637 StartUpdateCheck(); |
| 629 } | 638 } |
| 630 } | 639 } |
| 631 | 640 |
| 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 |
| 632 } // namespace chromeos | 671 } // namespace chromeos |
| OLD | NEW |