| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/update_screen.h" | 5 #include "chrome/browser/chromeos/login/update_screen.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "chrome/browser/chromeos/login/screen_observer.h" | 9 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 10 #include "chrome/browser/chromeos/login/update_view.h" | 10 #include "chrome/browser/chromeos/login/update_view.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Update window should appear for at least kMinimalUpdateTime seconds. | |
| 15 const int kMinimalUpdateTimeSec = 3; | |
| 16 | |
| 17 // Time in seconds that we wait for the device to reboot. | |
| 18 // If reboot didn't happen, ask user to reboot device manually. | |
| 19 const int kWaitForRebootTimeSec = 3; | |
| 20 | |
| 21 // Progress bar stages. Each represents progress bar value | 14 // Progress bar stages. Each represents progress bar value |
| 22 // at the beginning of each stage. | 15 // at the beginning of each stage. |
| 23 // TODO(nkostylev): Base stage progress values on approximate time. | 16 // TODO(nkostylev): Base stage progress values on approximate time. |
| 24 // TODO(nkostylev): Animate progress during each state. | 17 // TODO(nkostylev): Animate progress during each state. |
| 25 const int kBeforeUpdateCheckProgress = 7; | 18 const int kBeforeUpdateCheckProgress = 7; |
| 26 const int kBeforeDownloadProgress = 14; | 19 const int kBeforeDownloadProgress = 14; |
| 27 const int kBeforeVerifyingProgress = 74; | 20 const int kBeforeVerifyingProgress = 74; |
| 28 const int kBeforeFinalizingProgress = 81; | 21 const int kBeforeFinalizingProgress = 81; |
| 29 const int kProgressComplete = 100; | 22 const int kProgressComplete = 100; |
| 30 | 23 |
| 31 // Defines what part of update progress does download part takes. | 24 // Defines what part of update progress does download part takes. |
| 32 const int kDownloadProgressIncrement = 60; | 25 const int kDownloadProgressIncrement = 60; |
| 33 | 26 |
| 34 } // anonymous namespace | 27 } // anonymous namespace |
| 35 | 28 |
| 36 namespace chromeos { | 29 namespace chromeos { |
| 37 | 30 |
| 38 UpdateScreen::UpdateScreen(WizardScreenDelegate* delegate) | 31 UpdateScreen::UpdateScreen(WizardScreenDelegate* delegate) |
| 39 : DefaultViewScreen<chromeos::UpdateView>(delegate), | 32 : DefaultViewScreen<chromeos::UpdateView>(delegate), |
| 40 proceed_with_oobe_(false), | 33 proceed_with_oobe_(false), |
| 41 checking_for_update_(true) { | 34 checking_for_update_(true), |
| 35 minimal_update_time_(0), |
| 36 reboot_check_delay_(0) { |
| 42 } | 37 } |
| 43 | 38 |
| 44 UpdateScreen::~UpdateScreen() { | 39 UpdateScreen::~UpdateScreen() { |
| 45 // Remove pointer to this object from view. | 40 // Remove pointer to this object from view. |
| 46 if (view()) | 41 if (view()) |
| 47 view()->set_controller(NULL); | 42 view()->set_controller(NULL); |
| 48 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); | 43 CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); |
| 49 } | 44 } |
| 50 | 45 |
| 51 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { | 46 void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { |
| 52 UpdateStatusOperation status = library->status().status; | 47 UpdateStatusOperation status = library->status().status; |
| 53 LOG(INFO) << "Update status: " << status; | |
| 54 if (checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 48 if (checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
| 55 checking_for_update_ = false; | 49 checking_for_update_ = false; |
| 56 } | 50 } |
| 57 | 51 |
| 58 switch (status) { | 52 switch (status) { |
| 59 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 53 case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 60 // Do nothing in these cases, we don't want to notify the user of the | 54 // Do nothing in these cases, we don't want to notify the user of the |
| 61 // check unless there is an update. | 55 // check unless there is an update. |
| 62 break; | 56 break; |
| 63 case UPDATE_STATUS_UPDATE_AVAILABLE: | 57 case UPDATE_STATUS_UPDATE_AVAILABLE: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 case UPDATE_STATUS_VERIFYING: | 68 case UPDATE_STATUS_VERIFYING: |
| 75 view()->SetProgress(kBeforeVerifyingProgress); | 69 view()->SetProgress(kBeforeVerifyingProgress); |
| 76 break; | 70 break; |
| 77 case UPDATE_STATUS_FINALIZING: | 71 case UPDATE_STATUS_FINALIZING: |
| 78 view()->SetProgress(kBeforeFinalizingProgress); | 72 view()->SetProgress(kBeforeFinalizingProgress); |
| 79 break; | 73 break; |
| 80 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 74 case UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 81 view()->SetProgress(kProgressComplete); | 75 view()->SetProgress(kProgressComplete); |
| 82 CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate(); | 76 CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate(); |
| 83 LOG(INFO) << "Reboot API was called. Waiting for reboot."; | 77 LOG(INFO) << "Reboot API was called. Waiting for reboot."; |
| 84 reboot_timer_.Start(base::TimeDelta::FromSeconds(kWaitForRebootTimeSec), | 78 reboot_timer_.Start(base::TimeDelta::FromSeconds(reboot_check_delay_), |
| 85 this, | 79 this, |
| 86 &UpdateScreen::OnWaitForRebootTimeElapsed); | 80 &UpdateScreen::OnWaitForRebootTimeElapsed); |
| 87 break; | 81 break; |
| 88 case UPDATE_STATUS_IDLE: | 82 case UPDATE_STATUS_IDLE: |
| 89 case UPDATE_STATUS_ERROR: | 83 case UPDATE_STATUS_ERROR: |
| 90 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 84 case UPDATE_STATUS_REPORTING_ERROR_EVENT: |
| 91 if (MinimalUpdateTimeElapsed()) { | 85 if (MinimalUpdateTimeElapsed()) { |
| 92 ExitUpdate(); | 86 ExitUpdate(); |
| 93 } | 87 } |
| 94 proceed_with_oobe_ = true; | 88 proceed_with_oobe_ = true; |
| 95 break; | 89 break; |
| 96 default: | 90 default: |
| 97 NOTREACHED(); | 91 NOTREACHED(); |
| 98 break; | 92 break; |
| 99 } | 93 } |
| 100 } | 94 } |
| 101 | 95 |
| 102 void UpdateScreen::StartUpdate() { | 96 void UpdateScreen::StartUpdate() { |
| 103 // Reset view. | 97 // Reset view. |
| 104 view()->Reset(); | 98 view()->Reset(); |
| 105 view()->set_controller(this); | 99 view()->set_controller(this); |
| 106 | 100 |
| 107 // Start the minimal update time timer. | 101 // Start the minimal update time timer. |
| 108 minimal_update_time_timer_.Start( | 102 if (minimal_update_time_ > 0) { |
| 109 base::TimeDelta::FromSeconds(kMinimalUpdateTimeSec), | 103 minimal_update_time_timer_.Start( |
| 110 this, | 104 base::TimeDelta::FromSeconds(minimal_update_time_), |
| 111 &UpdateScreen::OnMinimalUpdateTimeElapsed); | 105 this, |
| 106 &UpdateScreen::OnMinimalUpdateTimeElapsed); |
| 107 } |
| 112 | 108 |
| 113 view()->SetProgress(kBeforeUpdateCheckProgress); | 109 view()->SetProgress(kBeforeUpdateCheckProgress); |
| 114 | 110 |
| 115 if (!CrosLibrary::Get()->EnsureLoaded()) { | 111 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 116 LOG(ERROR) << "Error loading CrosLibrary"; | 112 LOG(ERROR) << "Error loading CrosLibrary"; |
| 117 } else { | 113 } else { |
| 118 CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this); | 114 CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this); |
| 119 LOG(INFO) << "Checking for update"; | 115 LOG(INFO) << "Checking for update"; |
| 120 if (!CrosLibrary::Get()->GetUpdateLibrary()->CheckForUpdate()) { | 116 if (!CrosLibrary::Get()->GetUpdateLibrary()->CheckForUpdate()) { |
| 121 ExitUpdate(); | 117 ExitUpdate(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void UpdateScreen::OnMinimalUpdateTimeElapsed() { | 157 void UpdateScreen::OnMinimalUpdateTimeElapsed() { |
| 162 if (proceed_with_oobe_) | 158 if (proceed_with_oobe_) |
| 163 ExitUpdate(); | 159 ExitUpdate(); |
| 164 } | 160 } |
| 165 | 161 |
| 166 void UpdateScreen::OnWaitForRebootTimeElapsed() { | 162 void UpdateScreen::OnWaitForRebootTimeElapsed() { |
| 167 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; | 163 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; |
| 168 view()->ShowManualRebootInfo(); | 164 view()->ShowManualRebootInfo(); |
| 169 } | 165 } |
| 170 | 166 |
| 167 void UpdateScreen::SetMinimalUpdateTime(int seconds) { |
| 168 if (seconds <= 0) |
| 169 minimal_update_time_timer_.Stop(); |
| 170 DCHECK(!minimal_update_time_timer_.IsRunning()); |
| 171 minimal_update_time_ = seconds; |
| 172 } |
| 173 |
| 174 void UpdateScreen::SetRebootCheckDelay(int seconds) { |
| 175 if (seconds <= 0) |
| 176 reboot_timer_.Stop(); |
| 177 DCHECK(!reboot_timer_.IsRunning()); |
| 178 reboot_check_delay_ = seconds; |
| 179 } |
| 180 |
| 171 } // namespace chromeos | 181 } // namespace chromeos |
| OLD | NEW |