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 17 matching lines...) Expand all Loading... | |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 | 30 |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 using pairing_chromeos::HostPairingController; | 32 using pairing_chromeos::HostPairingController; |
33 | 33 |
34 namespace chromeos { | 34 namespace chromeos { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 constexpr const char kUserActionCancelUpdateShortcut[] = "cancel-update"; | |
39 constexpr const char kContextKeyEstimatedTimeLeftSec[] = "time-left-sec"; | |
40 constexpr const char kContextKeyShowEstimatedTimeLeft[] = "show-time-left"; | |
41 constexpr const char kContextKeyUpdateMessage[] = "update-msg"; | |
42 constexpr const char kContextKeyShowCurtain[] = "show-curtain"; | |
43 constexpr const char kContextKeyShowProgressMessage[] = "show-progress-msg"; | |
44 constexpr const char kContextKeyProgress[] = "progress"; | |
45 constexpr const char kContextKeyProgressMessage[] = "progress-msg"; | |
46 constexpr const char kContextKeyCancelUpdateShortcutEnabled[] = | |
47 "cancel-update-enabled"; | |
48 | |
38 // If reboot didn't happen, ask user to reboot device manually. | 49 // If reboot didn't happen, ask user to reboot device manually. |
39 const int kWaitForRebootTimeSec = 3; | 50 const int kWaitForRebootTimeSec = 3; |
40 | 51 |
41 // Progress bar stages. Each represents progress bar value | 52 // Progress bar stages. Each represents progress bar value |
42 // at the beginning of each stage. | 53 // at the beginning of each stage. |
43 // TODO(nkostylev): Base stage progress values on approximate time. | 54 // TODO(nkostylev): Base stage progress values on approximate time. |
44 // TODO(nkostylev): Animate progress during each state. | 55 // TODO(nkostylev): Animate progress during each state. |
45 const int kBeforeUpdateCheckProgress = 7; | 56 const int kBeforeUpdateCheckProgress = 7; |
46 const int kBeforeDownloadProgress = 14; | 57 const int kBeforeDownloadProgress = 14; |
47 const int kBeforeVerifyingProgress = 74; | 58 const int kBeforeVerifyingProgress = 74; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 114 |
104 // static | 115 // static |
105 UpdateScreen* UpdateScreen::Get(ScreenManager* manager) { | 116 UpdateScreen* UpdateScreen::Get(ScreenManager* manager) { |
106 return static_cast<UpdateScreen*>( | 117 return static_cast<UpdateScreen*>( |
107 manager->GetScreen(OobeScreen::SCREEN_OOBE_UPDATE)); | 118 manager->GetScreen(OobeScreen::SCREEN_OOBE_UPDATE)); |
108 } | 119 } |
109 | 120 |
110 UpdateScreen::UpdateScreen(BaseScreenDelegate* base_screen_delegate, | 121 UpdateScreen::UpdateScreen(BaseScreenDelegate* base_screen_delegate, |
111 UpdateView* view, | 122 UpdateView* view, |
112 HostPairingController* remora_controller) | 123 HostPairingController* remora_controller) |
113 : UpdateModel(base_screen_delegate), | 124 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_UPDATE), |
114 state_(STATE_IDLE), | |
115 reboot_check_delay_(kWaitForRebootTimeSec), | 125 reboot_check_delay_(kWaitForRebootTimeSec), |
116 is_checking_for_update_(true), | |
117 is_downloading_update_(false), | |
118 is_ignore_update_deadlines_(false), | |
119 is_shown_(false), | |
120 ignore_idle_status_(true), | |
121 view_(view), | 126 view_(view), |
122 remora_controller_(remora_controller), | 127 remora_controller_(remora_controller), |
123 is_first_detection_notification_(true), | |
124 is_first_portal_notification_(true), | |
125 histogram_helper_(new ErrorScreensHistogramHelper("Update")), | 128 histogram_helper_(new ErrorScreensHistogramHelper("Update")), |
126 weak_factory_(this) { | 129 weak_factory_(this) { |
127 if (view_) | 130 if (view_) |
128 view_->Bind(*this); | 131 view_->Bind(this); |
129 | 132 |
130 GetInstanceSet().insert(this); | 133 GetInstanceSet().insert(this); |
131 } | 134 } |
132 | 135 |
133 UpdateScreen::~UpdateScreen() { | 136 UpdateScreen::~UpdateScreen() { |
134 if (view_) | 137 if (view_) |
135 view_->Unbind(); | 138 view_->Unbind(); |
136 | 139 |
137 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | 140 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); |
138 network_portal_detector::GetInstance()->RemoveObserver(this); | 141 network_portal_detector::GetInstance()->RemoveObserver(this); |
139 GetInstanceSet().erase(this); | 142 GetInstanceSet().erase(this); |
140 } | 143 } |
141 | 144 |
145 void UpdateScreen::OnViewDestroyed(UpdateView* view) { | |
146 if (view_ == view) | |
147 view_ = nullptr; | |
148 } | |
149 | |
150 void UpdateScreen::StartNetworkCheck() { | |
151 // If portal detector is enabled and portal detection before AU is | |
152 // allowed, initiate network state check. Otherwise, directly | |
153 // proceed to update. | |
154 if (!network_portal_detector::GetInstance()->IsEnabled()) { | |
155 StartUpdateCheck(); | |
156 return; | |
157 } | |
158 state_ = STATE_FIRST_PORTAL_CHECK; | |
159 is_first_detection_notification_ = true; | |
160 is_first_portal_notification_ = true; | |
161 network_portal_detector::GetInstance()->AddAndFireObserver(this); | |
162 } | |
163 | |
164 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { | |
165 ignore_idle_status_ = ignore_idle_status; | |
166 } | |
167 | |
168 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { | |
169 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | |
170 network_portal_detector::GetInstance()->RemoveObserver(this); | |
171 SetHostPairingControllerStatus(HostPairingController::UPDATE_STATUS_UPDATED); | |
172 | |
173 switch (reason) { | |
174 case REASON_UPDATE_CANCELED: | |
175 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); | |
176 break; | |
177 case REASON_UPDATE_INIT_FAILED: | |
178 Finish(BaseScreenDelegate::UPDATE_ERROR_CHECKING_FOR_UPDATE); | |
179 break; | |
180 case REASON_UPDATE_NON_CRITICAL: | |
181 case REASON_UPDATE_ENDED: { | |
182 UpdateEngineClient* update_engine_client = | |
183 DBusThreadManager::Get()->GetUpdateEngineClient(); | |
184 switch (update_engine_client->GetLastStatus().status) { | |
185 case UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK: | |
186 break; | |
187 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | |
188 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | |
189 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | |
190 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | |
191 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | |
192 DCHECK(!HasCriticalUpdate()); | |
193 // Noncritical update, just exit screen as if there is no update. | |
194 // no break | |
195 case UpdateEngineClient::UPDATE_STATUS_IDLE: | |
196 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); | |
197 break; | |
198 case UpdateEngineClient::UPDATE_STATUS_ERROR: | |
199 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: | |
200 Finish(is_checking_for_update_ | |
201 ? BaseScreenDelegate::UPDATE_ERROR_CHECKING_FOR_UPDATE | |
202 : BaseScreenDelegate::UPDATE_ERROR_UPDATING); | |
203 break; | |
204 default: | |
205 NOTREACHED(); | |
206 } | |
207 } break; | |
208 default: | |
209 NOTREACHED(); | |
210 } | |
211 } | |
212 | |
142 void UpdateScreen::UpdateStatusChanged( | 213 void UpdateScreen::UpdateStatusChanged( |
143 const UpdateEngineClient::Status& status) { | 214 const UpdateEngineClient::Status& status) { |
144 if (is_checking_for_update_ && | 215 if (is_checking_for_update_ && |
145 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { | 216 status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) { |
146 is_checking_for_update_ = false; | 217 is_checking_for_update_ = false; |
147 } | 218 } |
148 if (ignore_idle_status_ && status.status > | 219 if (ignore_idle_status_ && status.status > |
149 UpdateEngineClient::UPDATE_STATUS_IDLE) { | 220 UpdateEngineClient::UPDATE_STATUS_IDLE) { |
150 ignore_idle_status_ = false; | 221 ignore_idle_status_ = false; |
151 } | 222 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 UpdateErrorMessage(network, status); | 371 UpdateErrorMessage(network, status); |
301 | 372 |
302 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) | 373 if (status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL) |
303 DelayErrorMessage(); | 374 DelayErrorMessage(); |
304 else | 375 else |
305 ShowErrorMessage(); | 376 ShowErrorMessage(); |
306 } | 377 } |
307 } | 378 } |
308 } | 379 } |
309 | 380 |
310 void UpdateScreen::StartNetworkCheck() { | 381 void UpdateScreen::CancelUpdate() { |
311 // If portal detector is enabled and portal detection before AU is | 382 VLOG(1) << "Forced update cancel"; |
312 // allowed, initiate network state check. Otherwise, directly | 383 ExitUpdate(REASON_UPDATE_CANCELED); |
313 // proceed to update. | 384 } |
314 if (!network_portal_detector::GetInstance()->IsEnabled()) { | 385 |
315 StartUpdateCheck(); | 386 base::OneShotTimer& UpdateScreen::GetErrorMessageTimerForTesting() { |
achuithb
2017/02/03 22:36:43
This should return a pointer, but let's not change
jdufault
2017/02/06 22:30:48
Added TODO
| |
316 return; | 387 return error_message_timer_; |
317 } | |
318 state_ = STATE_FIRST_PORTAL_CHECK; | |
319 is_first_detection_notification_ = true; | |
320 is_first_portal_notification_ = true; | |
321 network_portal_detector::GetInstance()->AddAndFireObserver(this); | |
322 } | 388 } |
323 | 389 |
324 void UpdateScreen::Show() { | 390 void UpdateScreen::Show() { |
325 is_shown_ = true; | 391 is_shown_ = true; |
326 histogram_helper_->OnScreenShow(); | 392 histogram_helper_->OnScreenShow(); |
327 | 393 |
328 #if !defined(OFFICIAL_BUILD) | 394 #if !defined(OFFICIAL_BUILD) |
329 GetContextEditor().SetBoolean(kContextKeyCancelUpdateShortcutEnabled, true); | 395 GetContextEditor().SetBoolean(kContextKeyCancelUpdateShortcutEnabled, true); |
330 #endif | 396 #endif |
331 GetContextEditor().SetInteger(kContextKeyProgress, | 397 GetContextEditor().SetInteger(kContextKeyProgress, |
332 kBeforeUpdateCheckProgress); | 398 kBeforeUpdateCheckProgress); |
333 | 399 |
334 if (view_) | 400 if (view_) |
335 view_->Show(); | 401 view_->Show(); |
336 } | 402 } |
337 | 403 |
338 void UpdateScreen::Hide() { | 404 void UpdateScreen::Hide() { |
339 if (view_) | 405 if (view_) |
340 view_->Hide(); | 406 view_->Hide(); |
341 is_shown_ = false; | 407 is_shown_ = false; |
342 } | 408 } |
343 | 409 |
344 void UpdateScreen::OnViewDestroyed(UpdateView* view) { | |
345 if (view_ == view) | |
346 view_ = nullptr; | |
347 } | |
348 | |
349 void UpdateScreen::OnUserAction(const std::string& action_id) { | 410 void UpdateScreen::OnUserAction(const std::string& action_id) { |
350 #if !defined(OFFICIAL_BUILD) | 411 #if !defined(OFFICIAL_BUILD) |
351 if (action_id == kUserActionCancelUpdateShortcut) | 412 if (action_id == kUserActionCancelUpdateShortcut) |
352 CancelUpdate(); | 413 CancelUpdate(); |
353 else | 414 else |
354 #endif | 415 #endif |
355 BaseScreen::OnUserAction(action_id); | 416 BaseScreen::OnUserAction(action_id); |
356 } | 417 } |
357 | 418 |
358 void UpdateScreen::OnContextKeyUpdated( | |
359 const ::login::ScreenContext::KeyType& key) { | |
360 UpdateModel::OnContextKeyUpdated(key); | |
361 } | |
362 | |
363 void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) { | |
364 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this); | |
365 network_portal_detector::GetInstance()->RemoveObserver(this); | |
366 SetHostPairingControllerStatus(HostPairingController::UPDATE_STATUS_UPDATED); | |
367 | |
368 | |
369 switch (reason) { | |
370 case REASON_UPDATE_CANCELED: | |
371 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); | |
372 break; | |
373 case REASON_UPDATE_INIT_FAILED: | |
374 Finish(BaseScreenDelegate::UPDATE_ERROR_CHECKING_FOR_UPDATE); | |
375 break; | |
376 case REASON_UPDATE_NON_CRITICAL: | |
377 case REASON_UPDATE_ENDED: | |
378 { | |
379 UpdateEngineClient* update_engine_client = | |
380 DBusThreadManager::Get()->GetUpdateEngineClient(); | |
381 switch (update_engine_client->GetLastStatus().status) { | |
382 case UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK: | |
383 break; | |
384 case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE: | |
385 case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT: | |
386 case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING: | |
387 case UpdateEngineClient::UPDATE_STATUS_FINALIZING: | |
388 case UpdateEngineClient::UPDATE_STATUS_VERIFYING: | |
389 DCHECK(!HasCriticalUpdate()); | |
390 // Noncritical update, just exit screen as if there is no update. | |
391 // no break | |
392 case UpdateEngineClient::UPDATE_STATUS_IDLE: | |
393 Finish(BaseScreenDelegate::UPDATE_NOUPDATE); | |
394 break; | |
395 case UpdateEngineClient::UPDATE_STATUS_ERROR: | |
396 case UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT: | |
397 Finish(is_checking_for_update_ | |
398 ? BaseScreenDelegate::UPDATE_ERROR_CHECKING_FOR_UPDATE | |
399 : BaseScreenDelegate::UPDATE_ERROR_UPDATING); | |
400 break; | |
401 default: | |
402 NOTREACHED(); | |
403 } | |
404 } | |
405 break; | |
406 default: | |
407 NOTREACHED(); | |
408 } | |
409 } | |
410 | |
411 void UpdateScreen::OnWaitForRebootTimeElapsed() { | |
412 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; | |
413 MakeSureScreenIsShown(); | |
414 GetContextEditor().SetString(kContextKeyUpdateMessage, | |
415 l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED)); | |
416 } | |
417 | |
418 void UpdateScreen::MakeSureScreenIsShown() { | |
419 if (!is_shown_) | |
420 get_base_screen_delegate()->ShowCurrentScreen(); | |
421 } | |
422 | |
423 void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) { | |
424 ignore_idle_status_ = ignore_idle_status; | |
425 } | |
426 | |
427 void UpdateScreen::CancelUpdate() { | |
428 VLOG(1) << "Forced update cancel"; | |
429 ExitUpdate(REASON_UPDATE_CANCELED); | |
430 } | |
431 | |
432 void UpdateScreen::UpdateDownloadingStats( | 419 void UpdateScreen::UpdateDownloadingStats( |
433 const UpdateEngineClient::Status& status) { | 420 const UpdateEngineClient::Status& status) { |
434 base::Time download_current_time = base::Time::Now(); | 421 base::Time download_current_time = base::Time::Now(); |
435 if (download_current_time >= | 422 if (download_current_time >= |
436 download_last_time_ + | 423 download_last_time_ + |
437 base::TimeDelta::FromSeconds(kMinTimeStepInSeconds)) { | 424 base::TimeDelta::FromSeconds(kMinTimeStepInSeconds)) { |
438 // Estimate downloading rate. | 425 // Estimate downloading rate. |
439 double progress_delta = | 426 double progress_delta = |
440 std::max(status.download_progress - download_last_progress_, 0.0); | 427 std::max(status.download_progress - download_last_progress_, 0.0); |
441 double time_delta = | 428 double time_delta = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 if (!base::ReadFileToString(update_deadline_file_path, &deadline) || | 479 if (!base::ReadFileToString(update_deadline_file_path, &deadline) || |
493 deadline.empty()) { | 480 deadline.empty()) { |
494 return false; | 481 return false; |
495 } | 482 } |
496 | 483 |
497 // TODO(dpolukhin): Analyze file content. Now we can just assume that | 484 // TODO(dpolukhin): Analyze file content. Now we can just assume that |
498 // if the file exists and not empty, there is critical update. | 485 // if the file exists and not empty, there is critical update. |
499 return true; | 486 return true; |
500 } | 487 } |
501 | 488 |
489 void UpdateScreen::OnWaitForRebootTimeElapsed() { | |
490 LOG(ERROR) << "Unable to reboot - asking user for a manual reboot."; | |
491 MakeSureScreenIsShown(); | |
492 GetContextEditor().SetString(kContextKeyUpdateMessage, | |
493 l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED)); | |
494 } | |
495 | |
496 void UpdateScreen::MakeSureScreenIsShown() { | |
497 if (!is_shown_) | |
498 get_base_screen_delegate()->ShowCurrentScreen(); | |
499 } | |
500 | |
501 void UpdateScreen::SetHostPairingControllerStatus( | |
502 HostPairingController::UpdateStatus update_status) { | |
503 if (remora_controller_) { | |
504 remora_controller_->OnUpdateStatusChanged(update_status); | |
505 } | |
506 } | |
507 | |
502 ErrorScreen* UpdateScreen::GetErrorScreen() { | 508 ErrorScreen* UpdateScreen::GetErrorScreen() { |
503 return get_base_screen_delegate()->GetErrorScreen(); | 509 return get_base_screen_delegate()->GetErrorScreen(); |
504 } | 510 } |
505 | 511 |
506 void UpdateScreen::StartUpdateCheck() { | 512 void UpdateScreen::StartUpdateCheck() { |
507 error_message_timer_.Stop(); | 513 error_message_timer_.Stop(); |
508 GetErrorScreen()->HideCaptivePortal(); | 514 GetErrorScreen()->HideCaptivePortal(); |
509 | 515 |
510 network_portal_detector::GetInstance()->RemoveObserver(this); | 516 network_portal_detector::GetInstance()->RemoveObserver(this); |
511 connect_request_subscription_.reset(); | 517 connect_request_subscription_.reset(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: | 568 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: |
563 GetErrorScreen()->SetErrorState(NetworkError::ERROR_STATE_PROXY, | 569 GetErrorScreen()->SetErrorState(NetworkError::ERROR_STATE_PROXY, |
564 std::string()); | 570 std::string()); |
565 break; | 571 break; |
566 default: | 572 default: |
567 NOTREACHED(); | 573 NOTREACHED(); |
568 break; | 574 break; |
569 } | 575 } |
570 } | 576 } |
571 | 577 |
572 void UpdateScreen::SetHostPairingControllerStatus( | |
573 HostPairingController::UpdateStatus update_status) { | |
574 if (remora_controller_) { | |
575 remora_controller_->OnUpdateStatusChanged(update_status); | |
576 } | |
577 } | |
578 | |
579 void UpdateScreen::DelayErrorMessage() { | 578 void UpdateScreen::DelayErrorMessage() { |
580 if (error_message_timer_.IsRunning()) | 579 if (error_message_timer_.IsRunning()) |
581 return; | 580 return; |
582 | 581 |
583 state_ = STATE_ERROR; | 582 state_ = STATE_ERROR; |
584 error_message_timer_.Start( | 583 error_message_timer_.Start( |
585 FROM_HERE, base::TimeDelta::FromSeconds(kDelayErrorMessageSec), this, | 584 FROM_HERE, base::TimeDelta::FromSeconds(kDelayErrorMessageSec), this, |
586 &UpdateScreen::ShowErrorMessage); | 585 &UpdateScreen::ShowErrorMessage); |
587 } | 586 } |
588 | 587 |
589 base::OneShotTimer& UpdateScreen::GetErrorMessageTimerForTesting() { | |
590 return error_message_timer_; | |
591 } | |
592 | |
593 void UpdateScreen::OnConnectRequested() { | 588 void UpdateScreen::OnConnectRequested() { |
594 if (state_ == STATE_ERROR) { | 589 if (state_ == STATE_ERROR) { |
595 LOG(WARNING) << "Hiding error message since AP was reselected"; | 590 LOG(WARNING) << "Hiding error message since AP was reselected"; |
596 StartUpdateCheck(); | 591 StartUpdateCheck(); |
597 } | 592 } |
598 } | 593 } |
599 | 594 |
600 } // namespace chromeos | 595 } // namespace chromeos |
OLD | NEW |