Chromium Code Reviews| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 | 235 |
| 236 switch (status.status) { | 236 switch (status.status) { |
| 237 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: | 237 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 238 // Do nothing in these cases, we don't want to notify the user of the | 238 // Do nothing in these cases, we don't want to notify the user of the |
| 239 // check unless there is an update. | 239 // check unless there is an update. |
| 240 SetHostPairingControllerStatus( | 240 SetHostPairingControllerStatus( |
| 241 HostPairingController::UPDATE_STATUS_UPDATING); | 241 HostPairingController::UPDATE_STATUS_UPDATING); |
| 242 break; | 242 break; |
| 243 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 243 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
| 244 RecordUpdateCheckResultingInUpdate(); | |
| 244 MakeSureScreenIsShown(); | 245 MakeSureScreenIsShown(); |
| 245 GetContextEditor() | 246 GetContextEditor() |
| 246 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) | 247 .SetInteger(kContextKeyProgress, kBeforeDownloadProgress) |
| 247 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false); | 248 .SetBoolean(kContextKeyShowEstimatedTimeLeft, false); |
| 248 if (!HasCriticalUpdate()) { | 249 if (!HasCriticalUpdate()) { |
| 249 VLOG(1) << "Noncritical update available: " << status.new_version; | 250 VLOG(1) << "Noncritical update available: " << status.new_version; |
| 250 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 251 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 251 } else { | 252 } else { |
| 252 VLOG(1) << "Critical update available: " << status.new_version; | 253 VLOG(1) << "Critical update available: " << status.new_version; |
| 253 GetContextEditor() | 254 GetContextEditor() |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 } | 546 } |
| 546 | 547 |
| 547 void UpdateScreen::StartUpdateCheck() { | 548 void UpdateScreen::StartUpdateCheck() { |
| 548 error_message_timer_.Stop(); | 549 error_message_timer_.Stop(); |
| 549 GetErrorScreen()->HideCaptivePortal(); | 550 GetErrorScreen()->HideCaptivePortal(); |
| 550 | 551 |
| 551 network_portal_detector::GetInstance()->RemoveObserver(this); | 552 network_portal_detector::GetInstance()->RemoveObserver(this); |
| 552 connect_request_subscription_.reset(); | 553 connect_request_subscription_.reset(); |
| 553 if (state_ == State::STATE_ERROR) | 554 if (state_ == State::STATE_ERROR) |
| 554 HideErrorMessage(); | 555 HideErrorMessage(); |
| 555 state_ = State::STATE_UPDATE; | 556 |
| 556 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 557 if (ShouldCheckForUpdate()) { |
| 557 VLOG(1) << "Initiate update check"; | 558 state_ = State::STATE_UPDATE; |
| 558 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | 559 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
| 559 base::Bind(StartUpdateCallback, this)); | 560 VLOG(1) << "Initiate update check"; |
| 561 RecordUpdateCheckWithNoUpdateYet(); | |
| 562 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | |
| 563 base::Bind(StartUpdateCallback, this)); | |
| 564 } else { | |
| 565 LOG(WARNING) << "Skipping update check since one was done recently " | |
| 566 "which did not result in an update."; | |
| 567 CancelUpdate(); | |
| 568 } | |
| 560 } | 569 } |
| 561 | 570 |
| 562 void UpdateScreen::ShowErrorMessage() { | 571 void UpdateScreen::ShowErrorMessage() { |
| 563 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; | 572 LOG(WARNING) << "UpdateScreen::ShowErrorMessage()"; |
| 564 | 573 |
| 565 error_message_timer_.Stop(); | 574 error_message_timer_.Stop(); |
| 566 | 575 |
| 567 state_ = State::STATE_ERROR; | 576 state_ = State::STATE_ERROR; |
| 568 connect_request_subscription_ = | 577 connect_request_subscription_ = |
| 569 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( | 578 GetErrorScreen()->RegisterConnectRequestCallback(base::Bind( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 &UpdateScreen::ShowErrorMessage); | 629 &UpdateScreen::ShowErrorMessage); |
| 621 } | 630 } |
| 622 | 631 |
| 623 void UpdateScreen::OnConnectRequested() { | 632 void UpdateScreen::OnConnectRequested() { |
| 624 if (state_ == State::STATE_ERROR) { | 633 if (state_ == State::STATE_ERROR) { |
| 625 LOG(WARNING) << "Hiding error message since AP was reselected"; | 634 LOG(WARNING) << "Hiding error message since AP was reselected"; |
| 626 StartUpdateCheck(); | 635 StartUpdateCheck(); |
| 627 } | 636 } |
| 628 } | 637 } |
| 629 | 638 |
| 639 void UpdateScreen::RecordUpdateCheckWithNoUpdateYet() { | |
| 640 StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::Now()); | |
| 641 } | |
| 642 | |
| 643 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.
| |
| 644 StartupUtils::SaveTimeOfLastUpdateCheckWithoutUpdate(base::Time::UnixEpoch()); | |
| 645 } | |
| 646 | |
| 647 bool UpdateScreen::ShouldCheckForUpdate() { | |
| 648 // Always run update check for non hands-off enrollment. | |
| 649 if (!WizardController::UsingHandsOffEnrollment()) | |
| 650 return true; | |
| 651 | |
| 652 // If we check for an update and there is no need to perform an update, | |
| 653 // this is the time in hours we should wait before checking again. | |
| 654 const base::TimeDelta kUpdateCheckRecencyThreshold = | |
| 655 base::TimeDelta::FromHours(1); | |
| 656 | |
| 657 base::Time now = base::Time::Now(); | |
| 658 base::Time last = StartupUtils::GetTimeOfLastUpdateCheckWithoutUpdate(); | |
| 659 | |
| 660 // Return false if enough time has not passed since the last update check. | |
| 661 // Otherwise, return true. | |
| 662 if (now > last) { | |
| 663 return (now - last) > kUpdateCheckRecencyThreshold; | |
| 664 } else { | |
|
xiyuan
2017/05/15 17:24:22
nit: get rid of "else"
kumarniranjan
2017/05/15 22:08:21
Done.
| |
| 665 return true; | |
| 666 } | |
| 667 } | |
| 668 | |
| 630 } // namespace chromeos | 669 } // namespace chromeos |
| OLD | NEW |