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/update_screen.h" | 5 #include "chrome/browser/chromeos/login/update_screen.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 11 #include "chrome/browser/chromeos/login/screen_observer.h" | 12 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 12 #include "chrome/browser/chromeos/login/update_screen_actor.h" | 13 #include "chrome/browser/chromeos/login/update_screen_actor.h" |
| 13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 14 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 | 17 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 32 | 33 |
| 33 // Defines what part of update progress does download part takes. | 34 // Defines what part of update progress does download part takes. |
| 34 const int kDownloadProgressIncrement = 60; | 35 const int kDownloadProgressIncrement = 60; |
| 35 | 36 |
| 36 // Considering 10px shadow from each side. | 37 // Considering 10px shadow from each side. |
| 37 const int kUpdateScreenWidth = 580; | 38 const int kUpdateScreenWidth = 580; |
| 38 const int kUpdateScreenHeight = 305; | 39 const int kUpdateScreenHeight = 305; |
| 39 | 40 |
| 40 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; | 41 const char kUpdateDeadlineFile[] = "/tmp/update-check-response-deadline"; |
| 41 | 42 |
| 43 // Minimum timestep between two consecutive measurements for the | |
| 44 // download rate. | |
| 45 const base::TimeDelta kMinTimeStep = base::TimeDelta::FromMilliseconds(10); | |
|
Nikita (slow)
2012/05/10 16:04:31
Perhaps set it to at least 1s so that rate is not
ygorshenin1
2012/05/11 12:42:50
Done.
| |
| 46 // Minimum allowed progress between two consecutive ETAs. | |
|
Nikita (slow)
2012/05/10 16:04:31
nit: Insert extra line before each comment.
ygorshenin1
2012/05/11 12:42:50
Done.
| |
| 47 const double kMinProgressStep = 1e-3; | |
| 48 // Smooth factor that is used for the average downloading speed | |
| 49 // estimation. | |
| 50 const double kDownloadSpeedSmoothFactor = 0.01; | |
| 51 // Minumum allowed value for the average downloading speed. | |
| 52 const double kDownloadAverageSpeedDropBound = 1e-8; | |
| 53 | |
| 42 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. | 54 // Invoked from call to RequestUpdateCheck upon completion of the DBus call. |
| 43 void StartUpdateCallback(UpdateScreen* screen, | 55 void StartUpdateCallback(UpdateScreen* screen, |
| 44 UpdateEngineClient::UpdateCheckResult result) { | 56 UpdateEngineClient::UpdateCheckResult result) { |
| 45 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; | 57 VLOG(1) << "Callback from RequestUpdateCheck, result " << result; |
| 46 if (UpdateScreen::HasInstance(screen)) { | 58 if (UpdateScreen::HasInstance(screen)) { |
| 47 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) | 59 if (result == UpdateEngineClient::UPDATE_RESULT_SUCCESS) |
| 48 screen->SetIgnoreIdleStatus(false); | 60 screen->SetIgnoreIdleStatus(false); |
| 49 else | 61 else |
| 50 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); | 62 screen->ExitUpdate(UpdateScreen::REASON_UPDATE_INIT_FAILED); |
| 51 } | 63 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 const UpdateEngineClient::Status& status) { | 104 const UpdateEngineClient::Status& status) { |
| 93 if (is_checking_for_update_ && | 105 if (is_checking_for_update_ && |
| 94 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 106 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
| 95 is_checking_for_update_ = false; | 107 is_checking_for_update_ = false; |
| 96 } | 108 } |
| 97 if (ignore_idle_status_ && status.status > | 109 if (ignore_idle_status_ && status.status > |
| 98 UpdateEngineClient::UPDATE_STATUS_IDLE) { | 110 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
| 99 ignore_idle_status_ = false; | 111 ignore_idle_status_ = false; |
| 100 } | 112 } |
| 101 | 113 |
| 114 if (status.status == UpdateEngineClient::UPDATE_STATUS_DOWNLOADING) { | |
| 115 // |is_downloading_update_| is set below, so if it's value is | |
| 116 // false, then this is the first notification from the downloading | |
| 117 // stage. | |
| 118 if (!is_downloading_update_) | |
| 119 actor_->ShowUpdateDownloadingStats(true); | |
|
Nikita (slow)
2012/05/10 16:04:31
What would it show if we call ExitUpdate(REASON_UP
ygorshenin1
2012/05/11 12:42:50
Nothing. These stats will be shown iff curtain is
| |
| 120 } else if (is_downloading_update_) { | |
| 121 actor_->ShowUpdateDownloadingStats(false); | |
| 122 } | |
| 123 | |
| 102 switch (status.status) { | 124 switch (status.status) { |
| 103 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: | 125 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 104 // Do nothing in these cases, we don't want to notify the user of the | 126 // Do nothing in these cases, we don't want to notify the user of the |
| 105 // check unless there is an update. | 127 // check unless there is an update. |
| 106 break; | 128 break; |
| 107 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 129 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
| 108 MakeSureScreenIsShown(); | 130 MakeSureScreenIsShown(); |
| 109 actor_->SetProgress(kBeforeDownloadProgress); | 131 actor_->SetProgress(kBeforeDownloadProgress); |
| 110 if (!HasCriticalUpdate()) { | 132 if (!HasCriticalUpdate()) { |
| 111 LOG(INFO) << "Noncritical update available: " | 133 LOG(INFO) << "Noncritical update available: " |
| 112 << status.new_version; | 134 << status.new_version; |
| 113 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 135 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 114 } else { | 136 } else { |
| 115 LOG(INFO) << "Critical update available: " | 137 LOG(INFO) << "Critical update available: " |
| 116 << status.new_version; | 138 << status.new_version; |
| 117 actor_->ShowPreparingUpdatesInfo(true); | 139 actor_->ShowPreparingUpdatesInfo(true); |
| 118 actor_->ShowCurtain(false); | 140 actor_->ShowCurtain(false); |
| 119 } | 141 } |
| 120 break; | 142 break; |
| 121 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | 143 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
| 122 { | 144 { |
| 123 MakeSureScreenIsShown(); | 145 MakeSureScreenIsShown(); |
| 124 if (!is_downloading_update_) { | 146 if (!is_downloading_update_) { |
| 125 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE | 147 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE |
| 126 // we need to is update critical on first downloading notification. | 148 // we need to is update critical on first downloading notification. |
| 127 is_downloading_update_ = true; | 149 is_downloading_update_ = true; |
| 150 download_start_time_ = download_last_time_ = base::Time::Now(); | |
| 151 download_start_progress_ = status.download_progress; | |
| 152 download_last_progress_ = status.download_progress; | |
| 153 is_download_average_speed_computed_ = false; | |
| 154 download_average_speed_ = 0.0; | |
| 128 if (!HasCriticalUpdate()) { | 155 if (!HasCriticalUpdate()) { |
| 129 LOG(INFO) << "Non-critical update available: " | 156 LOG(INFO) << "Non-critical update available: " |
| 130 << status.new_version; | 157 << status.new_version; |
| 131 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 158 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
| 132 } else { | 159 } else { |
| 133 LOG(INFO) << "Critical update available: " | 160 LOG(INFO) << "Critical update available: " |
| 134 << status.new_version; | 161 << status.new_version; |
| 135 actor_->ShowPreparingUpdatesInfo(false); | 162 actor_->ShowPreparingUpdatesInfo(false); |
| 136 actor_->ShowCurtain(false); | 163 actor_->ShowCurtain(false); |
| 137 } | 164 } |
| 138 } | 165 } |
| 166 | |
| 167 base::Time download_current_time = base::Time::Now(); | |
|
Nikita (slow)
2012/05/10 16:04:31
Extract to a separate function.
ygorshenin1
2012/05/11 12:42:50
Done.
| |
| 168 if (download_current_time >= download_last_time_ + kMinTimeStep && | |
| 169 status.download_progress >= | |
| 170 download_last_progress_ + kMinProgressStep) { | |
| 171 // Estimate downloading rate. | |
| 172 double progress_delta = | |
| 173 std::max(status.download_progress - download_last_progress_, 0.0); | |
| 174 double time_delta = | |
| 175 (download_current_time - download_last_time_).InSecondsF(); | |
| 176 double download_rate = status.new_size * progress_delta / time_delta; | |
| 177 actor_->SetDownloadingRate(download_rate); | |
|
Nikita (slow)
2012/05/10 16:04:31
Move this call below to group with SetEstimatedTim
ygorshenin1
2012/05/11 12:42:50
Done.
| |
| 178 download_last_time_ = download_current_time; | |
| 179 download_last_progress_ = status.download_progress; | |
| 180 | |
| 181 // Estimate time left. | |
| 182 double progress_left = std::max(1.0 - status.download_progress, 0.0); | |
| 183 if (!is_download_average_speed_computed_) { | |
| 184 download_average_speed_ = download_rate; | |
| 185 is_download_average_speed_computed_ = true; | |
| 186 } | |
| 187 download_average_speed_ = | |
| 188 kDownloadSpeedSmoothFactor * download_rate + | |
| 189 (1.0 - kDownloadSpeedSmoothFactor) * download_average_speed_; | |
| 190 if (download_average_speed_ < kDownloadAverageSpeedDropBound) { | |
| 191 time_delta = | |
| 192 (download_current_time - download_start_time_).InSecondsF(); | |
| 193 download_average_speed_ = | |
| 194 status.new_size * | |
| 195 (status.download_progress - download_start_progress_) / | |
| 196 time_delta; | |
| 197 } | |
| 198 double work_left = progress_left * status.new_size; | |
| 199 double time_left = work_left / download_average_speed_; | |
| 200 actor_->SetEstimatedTimeLeft( | |
| 201 base::TimeDelta::FromSeconds(static_cast<int64>(time_left))); | |
| 202 } | |
| 203 | |
| 139 int download_progress = static_cast<int>( | 204 int download_progress = static_cast<int>( |
| 140 status.download_progress * kDownloadProgressIncrement); | 205 status.download_progress * kDownloadProgressIncrement); |
| 141 actor_->SetProgress(kBeforeDownloadProgress + download_progress); | 206 actor_->SetProgress(kBeforeDownloadProgress + download_progress); |
| 142 } | 207 } |
| 143 break; | 208 break; |
| 144 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | 209 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
| 145 MakeSureScreenIsShown(); | 210 MakeSureScreenIsShown(); |
| 146 actor_->SetProgress(kBeforeVerifyingProgress); | 211 actor_->SetProgress(kBeforeVerifyingProgress); |
| 147 break; | 212 break; |
| 148 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | 213 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 if (seconds <= 0) | 334 if (seconds <= 0) |
| 270 reboot_timer_.Stop(); | 335 reboot_timer_.Stop(); |
| 271 DCHECK(!reboot_timer_.IsRunning()); | 336 DCHECK(!reboot_timer_.IsRunning()); |
| 272 reboot_check_delay_ = seconds; | 337 reboot_check_delay_ = seconds; |
| 273 } | 338 } |
| 274 | 339 |
| 275 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { | 340 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { |
| 276 ignore_idle_status_ = ignore_idle_status; | 341 ignore_idle_status_ = ignore_idle_status; |
| 277 } | 342 } |
| 278 | 343 |
| 279 bool UpdateScreen::HasCriticalUpdate() { | 344 bool UpdateScreen::HasCriticalUpdate() { |
|
Nikita (slow)
2012/05/10 16:04:31
Remove test code.
ygorshenin1
2012/05/11 12:42:50
Done.
| |
| 280 if (is_ignore_update_deadlines_) | |
| 281 return true; | |
| 282 | |
| 283 std::string deadline; | |
| 284 // Checking for update flag file causes us to do blocking IO on UI thread. | |
| 285 // Temporarily allow it until we fix http://crosbug.com/11106 | |
| 286 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 287 FilePath update_deadline_file_path(kUpdateDeadlineFile); | |
| 288 if (!file_util::ReadFileToString(update_deadline_file_path, &deadline) || | |
| 289 deadline.empty()) { | |
| 290 return false; | |
| 291 } | |
| 292 | |
| 293 // TODO(dpolukhin): Analyze file content. Now we can just assume that | |
| 294 // if the file exists and not empty, there is critical update. | |
| 295 return true; | 345 return true; |
| 296 } | 346 } |
| 297 | 347 |
| 348 // bool UpdateScreen::HasCriticalUpdate() { | |
| 349 // if (is_ignore_update_deadlines_) | |
| 350 // return true; | |
| 351 | |
| 352 // std::string deadline; | |
| 353 // // Checking for update flag file causes us to do blocking IO on UI thread. | |
| 354 // // Temporarily allow it until we fix http://crosbug.com/11106 | |
| 355 // base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 356 // FilePath update_deadline_file_path(kUpdateDeadlineFile); | |
| 357 // if (!file_util::ReadFileToString(update_deadline_file_path, &deadline) || | |
| 358 // deadline.empty()) { | |
| 359 // return false; | |
| 360 // } | |
| 361 | |
| 362 // // TODO(dpolukhin): Analyze file content. Now we can just assume that | |
| 363 // // if the file exists and not empty, there is critical update. | |
| 364 // return true; | |
| 365 // } | |
| 366 | |
| 298 void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) { | 367 void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) { |
| 299 if (actor_ == actor) | 368 if (actor_ == actor) |
| 300 actor_ = NULL; | 369 actor_ = NULL; |
| 301 } | 370 } |
| 302 | 371 |
| 303 } // namespace chromeos | 372 } // namespace chromeos |
| OLD | NEW |