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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | 14 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" |
15 #include "chrome/browser/chromeos/login/screen_manager.h" | 15 #include "chrome/browser/chromeos/login/screen_manager.h" |
16 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" | 16 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" |
17 #include "chrome/browser/chromeos/login/screens/error_screen.h" | 17 #include "chrome/browser/chromeos/login/screens/error_screen.h" |
18 #include "chrome/browser/chromeos/login/screens/update_screen_actor.h" | 18 #include "chrome/browser/chromeos/login/screens/update_view.h" |
19 #include "chrome/browser/chromeos/login/startup_utils.h" | 19 #include "chrome/browser/chromeos/login/startup_utils.h" |
20 #include "chrome/browser/chromeos/login/wizard_controller.h" | 20 #include "chrome/browser/chromeos/login/wizard_controller.h" |
21 #include "chrome/grit/chromium_strings.h" | |
22 #include "chrome/grit/generated_resources.h" | |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "ui/base/l10n/l10n_util.h" | |
24 | 27 |
25 using content::BrowserThread; | 28 using content::BrowserThread; |
26 using pairing_chromeos::HostPairingController; | 29 using pairing_chromeos::HostPairingController; |
27 | 30 |
28 namespace chromeos { | 31 namespace chromeos { |
29 | 32 |
30 namespace { | 33 namespace { |
31 | 34 |
35 // If reboot didn't happen, ask user to reboot device manually. | |
36 const int kWaitForRebootTimeSec = 3; | |
37 | |
32 // Progress bar stages. Each represents progress bar value | 38 // Progress bar stages. Each represents progress bar value |
33 // at the beginning of each stage. | 39 // at the beginning of each stage. |
34 // TODO(nkostylev): Base stage progress values on approximate time. | 40 // TODO(nkostylev): Base stage progress values on approximate time. |
35 // TODO(nkostylev): Animate progress during each state. | 41 // TODO(nkostylev): Animate progress during each state. |
36 const int kBeforeUpdateCheckProgress = 7; | 42 const int kBeforeUpdateCheckProgress = 7; |
37 const int kBeforeDownloadProgress = 14; | 43 const int kBeforeDownloadProgress = 14; |
38 const int kBeforeVerifyingProgress = 74; | 44 const int kBeforeVerifyingProgress = 74; |
39 const int kBeforeFinalizingProgress = 81; | 45 const int kBeforeFinalizingProgress = 81; |
40 const int kProgressComplete = 100; | 46 const int kProgressComplete = 100; |
41 | 47 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 return (found != instance_set.end()); | 93 return (found != instance_set.end()); |
88 } | 94 } |
89 | 95 |
90 // static | 96 // static |
91 UpdateScreen* UpdateScreen::Get(ScreenManager* manager) { | 97 UpdateScreen* UpdateScreen::Get(ScreenManager* manager) { |
92 return static_cast<UpdateScreen*>( | 98 return static_cast<UpdateScreen*>( |
93 manager->GetScreen(WizardController::kUpdateScreenName)); | 99 manager->GetScreen(WizardController::kUpdateScreenName)); |
94 } | 100 } |
95 | 101 |
96 UpdateScreen::UpdateScreen(BaseScreenDelegate* base_screen_delegate, | 102 UpdateScreen::UpdateScreen(BaseScreenDelegate* base_screen_delegate, |
97 UpdateScreenActor* actor, | 103 UpdateView* view, |
98 HostPairingController* remora_controller) | 104 HostPairingController* remora_controller) |
99 : BaseScreen(base_screen_delegate), | 105 : UpdateModel(base_screen_delegate), |
100 state_(STATE_IDLE), | 106 state_(STATE_IDLE), |
101 reboot_check_delay_(0), | 107 reboot_check_delay_(kWaitForRebootTimeSec), |
102 is_checking_for_update_(true), | 108 is_checking_for_update_(true), |
103 is_downloading_update_(false), | 109 is_downloading_update_(false), |
104 is_ignore_update_deadlines_(false), | 110 is_ignore_update_deadlines_(true), |
105 is_shown_(false), | 111 is_shown_(false), |
106 ignore_idle_status_(true), | 112 ignore_idle_status_(true), |
107 actor_(actor), | 113 view_(view), |
108 remora_controller_(remora_controller), | 114 remora_controller_(remora_controller), |
109 is_first_detection_notification_(true), | 115 is_first_detection_notification_(true), |
110 is_first_portal_notification_(true), | 116 is_first_portal_notification_(true), |
111 histogram_helper_(new ErrorScreensHistogramHelper("Update")), | 117 histogram_helper_(new ErrorScreensHistogramHelper("Update")), |
112 weak_factory_(this) { | 118 weak_factory_(this) { |
113 DCHECK(actor_); | 119 if (view_) |
114 if (actor_) | 120 view_->Bind(*this); |
115 actor_->SetDelegate(this); | 121 |
116 GetInstanceSet().insert(this); | 122 GetInstanceSet().insert(this); |
117 } | 123 } |
118 | 124 |
119 UpdateScreen::~UpdateScreen() { | 125 UpdateScreen::~UpdateScreen() { |
126 if (view_) | |
127 view_->Unbind(); | |
128 | |
120 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | 129 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
121 NetworkPortalDetector::Get()->RemoveObserver(this); | 130 NetworkPortalDetector::Get()->RemoveObserver(this); |
122 GetInstanceSet().erase(this); | 131 GetInstanceSet().erase(this); |
123 if (actor_) | |
124 actor_->SetDelegate(NULL); | |
125 } | 132 } |
126 | 133 |
127 void UpdateScreen::UpdateStatusChanged( | 134 void UpdateScreen::UpdateStatusChanged( |
128 const UpdateEngineClient::Status& status) { | 135 const UpdateEngineClient::Status& status) { |
129 if (!actor_) | |
130 return; | |
131 | |
132 if (is_checking_for_update_ && | 136 if (is_checking_for_update_ && |
133 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 137 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
134 is_checking_for_update_ = false; | 138 is_checking_for_update_ = false; |
135 } | 139 } |
136 if (ignore_idle_status_ && status.status > | 140 if (ignore_idle_status_ && status.status > |
137 UpdateEngineClient::UPDATE_STATUS_IDLE) { | 141 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
138 ignore_idle_status_ = false; | 142 ignore_idle_status_ = false; |
139 } | 143 } |
140 | 144 |
141 switch (status.status) { | 145 switch (status.status) { |
142 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: | 146 case UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE: |
143 // Do nothing in these cases, we don't want to notify the user of the | 147 // Do nothing in these cases, we don't want to notify the user of the |
144 // check unless there is an update. | 148 // check unless there is an update. |
145 SetHostPairingControllerStatus( | 149 SetHostPairingControllerStatus( |
146 HostPairingController::UPDATE_STATUS_UPDATING); | 150 HostPairingController::UPDATE_STATUS_UPDATING); |
147 break; | 151 break; |
148 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | 152 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: |
149 MakeSureScreenIsShown(); | 153 MakeSureScreenIsShown(); |
150 actor_->SetProgress(kBeforeDownloadProgress); | 154 GetContextEditor().SetInteger(kContextKeyProgress, |
151 actor_->ShowEstimatedTimeLeft(false); | 155 kBeforeDownloadProgress); |
156 GetContextEditor().SetBoolean(kContextKeyShowEstimatedTimeLeft, false); | |
152 if (!HasCriticalUpdate()) { | 157 if (!HasCriticalUpdate()) { |
153 VLOG(1) << "Noncritical update available: " << status.new_version; | 158 VLOG(1) << "Noncritical update available: " << status.new_version; |
154 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 159 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
155 } else { | 160 } else { |
156 VLOG(1) << "Critical update available: " << status.new_version; | 161 VLOG(1) << "Critical update available: " << status.new_version; |
157 actor_->SetProgressMessage( | 162 GetContextEditor().SetString( |
158 UpdateScreenActor::PROGRESS_MESSAGE_UPDATE_AVAILABLE); | 163 kContextKeyProgressMessage, |
159 actor_->ShowProgressMessage(true); | 164 l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE)); |
160 actor_->ShowCurtain(false); | 165 GetContextEditor().SetBoolean(kContextKeyShowProgressMessage, true); |
166 GetContextEditor().SetBoolean(kContextKeyShowCurtain, false); | |
161 } | 167 } |
162 break; | 168 break; |
163 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | 169 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: |
164 { | 170 { |
165 MakeSureScreenIsShown(); | 171 MakeSureScreenIsShown(); |
166 if (!is_downloading_update_) { | 172 if (!is_downloading_update_) { |
167 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE | 173 // Because update engine doesn't send UPDATE_STATUS_UPDATE_AVAILABLE |
168 // we need to is update critical on first downloading notification. | 174 // we need to is update critical on first downloading notification. |
169 is_downloading_update_ = true; | 175 is_downloading_update_ = true; |
170 download_start_time_ = download_last_time_ = base::Time::Now(); | 176 download_start_time_ = download_last_time_ = base::Time::Now(); |
171 download_start_progress_ = status.download_progress; | 177 download_start_progress_ = status.download_progress; |
172 download_last_progress_ = status.download_progress; | 178 download_last_progress_ = status.download_progress; |
173 is_download_average_speed_computed_ = false; | 179 is_download_average_speed_computed_ = false; |
174 download_average_speed_ = 0.0; | 180 download_average_speed_ = 0.0; |
175 if (!HasCriticalUpdate()) { | 181 if (!HasCriticalUpdate()) { |
176 VLOG(1) << "Non-critical update available: " << status.new_version; | 182 VLOG(1) << "Non-critical update available: " << status.new_version; |
177 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 183 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
178 } else { | 184 } else { |
179 VLOG(1) << "Critical update available: " << status.new_version; | 185 VLOG(1) << "Critical update available: " << status.new_version; |
180 actor_->SetProgressMessage( | 186 GetContextEditor().SetString( |
181 UpdateScreenActor::PROGRESS_MESSAGE_INSTALLING_UPDATE); | 187 kContextKeyProgressMessage, |
182 actor_->ShowProgressMessage(true); | 188 l10n_util::GetStringUTF16(IDS_INSTALLING_UPDATE)); |
183 actor_->ShowCurtain(false); | 189 GetContextEditor().SetBoolean(kContextKeyShowProgressMessage, true); |
Denis Kuznetsov (DE-MUC)
2015/02/03 14:21:16
Here and below : please use shorcut:
GetContextEdi
Nikita (slow)
2015/02/03 15:01:18
Done.
| |
190 GetContextEditor().SetBoolean(kContextKeyShowCurtain, false); | |
184 } | 191 } |
185 } | 192 } |
186 UpdateDownloadingStats(status); | 193 UpdateDownloadingStats(status); |
187 } | 194 } |
188 break; | 195 break; |
189 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | 196 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: |
190 MakeSureScreenIsShown(); | 197 MakeSureScreenIsShown(); |
191 actor_->SetProgress(kBeforeVerifyingProgress); | 198 GetContextEditor().SetInteger(kContextKeyProgress, |
192 actor_->SetProgressMessage(UpdateScreenActor::PROGRESS_MESSAGE_VERIFYING); | 199 kBeforeVerifyingProgress); |
193 actor_->ShowProgressMessage(true); | 200 GetContextEditor().SetString( |
201 kContextKeyProgressMessage, | |
202 l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING)); | |
203 GetContextEditor().SetBoolean(kContextKeyShowProgressMessage, true); | |
194 break; | 204 break; |
195 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | 205 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: |
196 MakeSureScreenIsShown(); | 206 MakeSureScreenIsShown(); |
197 actor_->SetProgress(kBeforeFinalizingProgress); | 207 GetContextEditor().SetInteger(kContextKeyProgress, |
198 actor_->SetProgressMessage( | 208 kBeforeFinalizingProgress); |
199 UpdateScreenActor::PROGRESS_MESSAGE_FINALIZING); | 209 GetContextEditor().SetString( |
200 actor_->ShowProgressMessage(true); | 210 kContextKeyProgressMessage, |
211 l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING)); | |
212 GetContextEditor().SetBoolean(kContextKeyShowProgressMessage, true); | |
201 break; | 213 break; |
202 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | 214 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: |
203 MakeSureScreenIsShown(); | 215 MakeSureScreenIsShown(); |
204 actor_->SetProgress(kProgressComplete); | 216 GetContextEditor().SetInteger(kContextKeyProgress, kProgressComplete); |
205 actor_->ShowEstimatedTimeLeft(false); | 217 GetContextEditor().SetBoolean(kContextKeyShowEstimatedTimeLeft, false); |
206 if (HasCriticalUpdate()) { | 218 if (HasCriticalUpdate()) { |
207 actor_->ShowCurtain(false); | 219 GetContextEditor().SetBoolean(kContextKeyShowCurtain, false); |
208 VLOG(1) << "Initiate reboot after update"; | 220 VLOG(1) << "Initiate reboot after update"; |
209 SetHostPairingControllerStatus( | 221 SetHostPairingControllerStatus( |
210 HostPairingController::UPDATE_STATUS_REBOOTING); | 222 HostPairingController::UPDATE_STATUS_REBOOTING); |
211 DBusThreadManager::Get()->GetUpdateEngineClient()->RebootAfterUpdate(); | 223 DBusThreadManager::Get()->GetUpdateEngineClient()->RebootAfterUpdate(); |
212 reboot_timer_.Start(FROM_HERE, | 224 reboot_timer_.Start(FROM_HERE, |
213 base::TimeDelta::FromSeconds(reboot_check_delay_), | 225 base::TimeDelta::FromSeconds(reboot_check_delay_), |
214 this, | 226 this, |
215 &UpdateScreen::OnWaitForRebootTimeElapsed); | 227 &UpdateScreen::OnWaitForRebootTimeElapsed); |
216 } else { | 228 } else { |
217 ExitUpdate(REASON_UPDATE_NON_CRITICAL); | 229 ExitUpdate(REASON_UPDATE_NON_CRITICAL); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 if (!NetworkPortalDetector::Get()->IsEnabled()) { | 303 if (!NetworkPortalDetector::Get()->IsEnabled()) { |
292 StartUpdateCheck(); | 304 StartUpdateCheck(); |
293 return; | 305 return; |
294 } | 306 } |
295 state_ = STATE_FIRST_PORTAL_CHECK; | 307 state_ = STATE_FIRST_PORTAL_CHECK; |
296 is_first_detection_notification_ = true; | 308 is_first_detection_notification_ = true; |
297 is_first_portal_notification_ = true; | 309 is_first_portal_notification_ = true; |
298 NetworkPortalDetector::Get()->AddAndFireObserver(this); | 310 NetworkPortalDetector::Get()->AddAndFireObserver(this); |
299 } | 311 } |
300 | 312 |
301 void UpdateScreen::CancelUpdate() { | 313 void UpdateScreen::PrepareToShow() { |
302 VLOG(1) << "Forced update cancel"; | 314 if (!view_) |
303 ExitUpdate(REASON_UPDATE_CANCELED); | 315 return; |
316 | |
317 view_->PrepareToShow(); | |
304 } | 318 } |
305 | 319 |
306 void UpdateScreen::Show() { | 320 void UpdateScreen::Show() { |
307 is_shown_ = true; | 321 is_shown_ = true; |
308 histogram_helper_->OnScreenShow(); | 322 histogram_helper_->OnScreenShow(); |
309 if (actor_) { | 323 |
310 actor_->Show(); | 324 #if !defined(OFFICIAL_BUILD) |
311 actor_->SetProgress(kBeforeUpdateCheckProgress); | 325 GetContextEditor().SetBoolean(kContextKeyCancelUpdateShortcutEnabled, true); |
326 #endif | |
327 GetContextEditor().SetInteger(kContextKeyProgress, | |
328 kBeforeUpdateCheckProgress); | |
329 | |
330 if (view_) | |
331 view_->Show(); | |
332 } | |
333 | |
334 void UpdateScreen::Hide() { | |
335 if (view_) | |
336 view_->Hide(); | |
337 is_shown_ = false; | |
338 } | |
339 | |
340 void UpdateScreen::Initialize(::login::ScreenContext* context) { | |
341 UpdateModel::Initialize(context); | |
342 } | |
343 | |
344 void UpdateScreen::OnViewDestroyed(UpdateView* view) { | |
345 if (view_ == view) | |
346 view_ = nullptr; | |
347 } | |
348 | |
349 void UpdateScreen::OnUserAction(const std::string& action_id) { | |
350 #if !defined(OFFICIAL_BUILD) | |
351 if (action_id == kUserActionCancelUpdateShortcut) | |
352 CancelUpdate(); | |
353 #endif | |
354 } | |
355 | |
356 void UpdateScreen::OnContextKeyUpdated( | |
357 const ::login::ScreenContext::KeyType& key) { | |
358 UpdateModel::OnContextKeyUpdated(key); | |
359 } | |
360 | |
361 void UpdateScreen::OnConnectToNetworkRequested() { | |
362 if (state_ == STATE_ERROR) { | |
363 LOG(WARNING) << "Hiding error message since AP was reselected"; | |
364 StartUpdateCheck(); | |
312 } | 365 } |
313 } | 366 } |
314 | 367 |
315 void UpdateScreen::Hide() { | |
316 if (actor_) | |
317 actor_->Hide(); | |
318 is_shown_ = false; | |
319 } | |
320 | |
321 std::string UpdateScreen::GetName() const { | |
322 return WizardController::kUpdateScreenName; | |
323 } | |
324 | |
325 void UpdateScreen::PrepareToShow() { | |
326 if (actor_) | |
327 actor_->PrepareToShow(); | |
328 } | |
329 | |
330 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { | 368 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { |
331 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | 369 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
332 NetworkPortalDetector::Get()->RemoveObserver(this); | 370 NetworkPortalDetector::Get()->RemoveObserver(this); |
333 SetHostPairingControllerStatus(HostPairingController::UPDATE_STATUS_UPDATED); | 371 SetHostPairingControllerStatus(HostPairingController::UPDATE_STATUS_UPDATED); |
334 | 372 |
335 | 373 |
336 switch (reason) { | 374 switch (reason) { |
337 case REASON_UPDATE_CANCELED: | 375 case REASON_UPDATE_CANCELED: |
338 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); | 376 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); |
339 break; | 377 break; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 } | 409 } |
372 break; | 410 break; |
373 default: | 411 default: |
374 NOTREACHED(); | 412 NOTREACHED(); |
375 } | 413 } |
376 } | 414 } |
377 | 415 |
378 void UpdateScreen::OnWaitForRebootTimeElapsed() { | 416 void UpdateScreen::OnWaitForRebootTimeElapsed() { |
379 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; | 417 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; |
380 MakeSureScreenIsShown(); | 418 MakeSureScreenIsShown(); |
381 if (actor_) | 419 GetContextEditor().SetString(kContextKeyUpdateMessage, |
Denis Kuznetsov (DE-MUC)
2015/02/03 14:21:16
I see only one possible message.
Maybe it should b
Nikita (slow)
2015/02/03 15:01:18
I would prefer to keep this to push generic update
| |
382 actor_->ShowManualRebootInfo(); | 420 l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED)); |
383 } | 421 } |
384 | 422 |
385 void UpdateScreen::MakeSureScreenIsShown() { | 423 void UpdateScreen::MakeSureScreenIsShown() { |
386 if (!is_shown_) | 424 if (!is_shown_) |
387 get_base_screen_delegate()->ShowCurrentScreen(); | 425 get_base_screen_delegate()->ShowCurrentScreen(); |
388 } | 426 } |
389 | 427 |
390 void UpdateScreen::SetRebootCheckDelay(int seconds) { | |
391 if (seconds <= 0) | |
392 reboot_timer_.Stop(); | |
393 DCHECK(!reboot_timer_.IsRunning()); | |
394 reboot_check_delay_ = seconds; | |
395 } | |
396 | |
397 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { | 428 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { |
398 ignore_idle_status_ = ignore_idle_status; | 429 ignore_idle_status_ = ignore_idle_status; |
399 } | 430 } |
400 | 431 |
432 void UpdateScreen::CancelUpdate() { | |
433 VLOG(1) << "Forced update cancel"; | |
434 ExitUpdate(REASON_UPDATE_CANCELED); | |
435 } | |
436 | |
401 void UpdateScreen::UpdateDownloadingStats( | 437 void UpdateScreen::UpdateDownloadingStats( |
402 const UpdateEngineClient::Status& status) { | 438 const UpdateEngineClient::Status& status) { |
403 if (!actor_) | |
404 return; | |
405 base::Time download_current_time = base::Time::Now(); | 439 base::Time download_current_time = base::Time::Now(); |
406 if (download_current_time >= download_last_time_ + kMinTimeStep) { | 440 if (download_current_time >= download_last_time_ + kMinTimeStep) { |
407 // Estimate downloading rate. | 441 // Estimate downloading rate. |
408 double progress_delta = | 442 double progress_delta = |
409 std::max(status.download_progress - download_last_progress_, 0.0); | 443 std::max(status.download_progress - download_last_progress_, 0.0); |
410 double time_delta = | 444 double time_delta = |
411 (download_current_time - download_last_time_).InSecondsF(); | 445 (download_current_time - download_last_time_).InSecondsF(); |
412 double download_rate = status.new_size * progress_delta / time_delta; | 446 double download_rate = status.new_size * progress_delta / time_delta; |
413 | 447 |
414 download_last_time_ = download_current_time; | 448 download_last_time_ = download_current_time; |
(...skipping 15 matching lines...) Expand all Loading... | |
430 status.new_size * | 464 status.new_size * |
431 (status.download_progress - download_start_progress_) / | 465 (status.download_progress - download_start_progress_) / |
432 time_delta; | 466 time_delta; |
433 } | 467 } |
434 double work_left = progress_left * status.new_size; | 468 double work_left = progress_left * status.new_size; |
435 double time_left = work_left / download_average_speed_; | 469 double time_left = work_left / download_average_speed_; |
436 // |time_left| may be large enough or even +infinity. So we must | 470 // |time_left| may be large enough or even +infinity. So we must |
437 // |bound possible estimations. | 471 // |bound possible estimations. |
438 time_left = std::min(time_left, kMaxTimeLeft); | 472 time_left = std::min(time_left, kMaxTimeLeft); |
439 | 473 |
440 actor_->ShowEstimatedTimeLeft(true); | 474 GetContextEditor().SetBoolean(kContextKeyShowEstimatedTimeLeft, true); |
441 actor_->SetEstimatedTimeLeft( | 475 GetContextEditor().SetInteger(kContextKeyEstimatedTimeLeftSec, |
442 base::TimeDelta::FromSeconds(static_cast<int64>(time_left))); | 476 static_cast<int>(time_left)); |
443 } | 477 } |
444 | 478 |
445 int download_progress = static_cast<int>( | 479 int download_progress = static_cast<int>( |
446 status.download_progress * kDownloadProgressIncrement); | 480 status.download_progress * kDownloadProgressIncrement); |
447 actor_->SetProgress(kBeforeDownloadProgress + download_progress); | 481 GetContextEditor().SetInteger(kContextKeyProgress, |
482 kBeforeDownloadProgress + download_progress); | |
448 } | 483 } |
449 | 484 |
450 bool UpdateScreen::HasCriticalUpdate() { | 485 bool UpdateScreen::HasCriticalUpdate() { |
451 if (is_ignore_update_deadlines_) | 486 if (is_ignore_update_deadlines_) |
452 return true; | 487 return true; |
453 | 488 |
454 std::string deadline; | 489 std::string deadline; |
455 // Checking for update flag file causes us to do blocking IO on UI thread. | 490 // Checking for update flag file causes us to do blocking IO on UI thread. |
456 // Temporarily allow it until we fix http://crosbug.com/11106 | 491 // Temporarily allow it until we fix http://crosbug.com/11106 |
457 base::ThreadRestrictions::ScopedAllowIO allow_io; | 492 base::ThreadRestrictions::ScopedAllowIO allow_io; |
458 base::FilePath update_deadline_file_path(kUpdateDeadlineFile); | 493 base::FilePath update_deadline_file_path(kUpdateDeadlineFile); |
459 if (!base::ReadFileToString(update_deadline_file_path, &deadline) || | 494 if (!base::ReadFileToString(update_deadline_file_path, &deadline) || |
460 deadline.empty()) { | 495 deadline.empty()) { |
461 return false; | 496 return false; |
462 } | 497 } |
463 | 498 |
464 // TODO(dpolukhin): Analyze file content. Now we can just assume that | 499 // TODO(dpolukhin): Analyze file content. Now we can just assume that |
465 // if the file exists and not empty, there is critical update. | 500 // if the file exists and not empty, there is critical update. |
466 return true; | 501 return true; |
467 } | 502 } |
468 | 503 |
469 void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) { | |
470 if (actor_ == actor) | |
471 actor_ = NULL; | |
472 } | |
473 | |
474 void UpdateScreen::OnConnectToNetworkRequested() { | |
475 if (state_ == STATE_ERROR) { | |
476 LOG(WARNING) << "Hiding error message since AP was reselected"; | |
477 StartUpdateCheck(); | |
478 } | |
479 } | |
480 | |
481 ErrorScreen* UpdateScreen::GetErrorScreen() { | 504 ErrorScreen* UpdateScreen::GetErrorScreen() { |
482 return get_base_screen_delegate()->GetErrorScreen(); | 505 return get_base_screen_delegate()->GetErrorScreen(); |
483 } | 506 } |
484 | 507 |
485 void UpdateScreen::StartUpdateCheck() { | 508 void UpdateScreen::StartUpdateCheck() { |
486 NetworkPortalDetector::Get()->RemoveObserver(this); | 509 NetworkPortalDetector::Get()->RemoveObserver(this); |
487 if (state_ == STATE_ERROR) | 510 if (state_ == STATE_ERROR) |
488 HideErrorMessage(); | 511 HideErrorMessage(); |
489 state_ = STATE_UPDATE; | 512 state_ = STATE_UPDATE; |
490 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); | 513 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 } | 562 } |
540 | 563 |
541 void UpdateScreen::SetHostPairingControllerStatus( | 564 void UpdateScreen::SetHostPairingControllerStatus( |
542 HostPairingController::UpdateStatus update_status) { | 565 HostPairingController::UpdateStatus update_status) { |
543 if (remora_controller_) { | 566 if (remora_controller_) { |
544 remora_controller_->OnUpdateStatusChanged(update_status); | 567 remora_controller_->OnUpdateStatusChanged(update_status); |
545 } | 568 } |
546 } | 569 } |
547 | 570 |
548 } // namespace chromeos | 571 } // namespace chromeos |
OLD | NEW |