update_screen.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ 7 8#include <set> 9 10#include "base/callback.h" 11#include "base/compiler_specific.h" 12#include "base/gtest_prod_util.h" 13#include "base/memory/weak_ptr.h" 14#include "base/time.h" 15#include "base/timer.h" 16#include "chrome/browser/chromeos/login/screens/update_screen_actor.h" 17#include "chrome/browser/chromeos/login/screens/wizard_screen.h" 18#include "chrome/browser/chromeos/net/network_portal_detector.h" 19#include "chromeos/dbus/update_engine_client.h" 20 21namespace chromeos { 22 23class ErrorScreen; 24class ScreenObserver; 25 26// Controller for the update screen. It does not depend on the specific 27// implementation of the screen showing (Views of WebUI based), the dependency 28// is moved to the UpdateScreenActor instead. 29class UpdateScreen: public UpdateEngineClient::Observer, 30 public UpdateScreenActor::Delegate, 31 public WizardScreen, 32 public NetworkPortalDetector::Observer { 33 public: 34 UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor); 35 virtual ~UpdateScreen(); 36 37 // Overridden from WizardScreen. 38 virtual void PrepareToShow() OVERRIDE; 39 virtual void Show() OVERRIDE; 40 virtual void Hide() OVERRIDE; 41 virtual std::string GetName() const OVERRIDE; 42 43 // UpdateScreenActor::Delegate implementation: 44 virtual void CancelUpdate() OVERRIDE; 45 virtual void OnActorDestroyed(UpdateScreenActor* actor) OVERRIDE; 46 47 // Starts network check. Made virtual to simplify mocking. 48 virtual void StartNetworkCheck(); 49 50 // Reboot check delay get/set, in seconds. 51 int reboot_check_delay() const { return reboot_check_delay_; } 52 void SetRebootCheckDelay(int seconds); 53 54 // Returns true if this instance is still active (i.e. has not been deleted). 55 static bool HasInstance(UpdateScreen* inst); 56 57 void SetIgnoreIdleStatus(bool ignore_idle_status); 58 59 enum ExitReason { 60 REASON_UPDATE_CANCELED = 0, 61 REASON_UPDATE_INIT_FAILED, 62 REASON_UPDATE_NON_CRITICAL, 63 REASON_UPDATE_ENDED 64 }; 65 // Reports update results to the ScreenObserver. 66 virtual void ExitUpdate(ExitReason reason); 67 68 // UpdateEngineClient::Observer implementation: 69 virtual void UpdateStatusChanged( 70 const UpdateEngineClient::Status& status) OVERRIDE; 71 72 // NetworkPortalDetector::Observer implementation: 73 virtual void OnPortalDetectionCompleted( 74 const Network* network, 75 const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; 76 77 private: 78 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic); 79 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable); 80 81 enum State { 82 STATE_IDLE = 0, 83 STATE_FIRST_PORTAL_CHECK, 84 STATE_UPDATE, 85 STATE_ERROR 86 }; 87 88 // Updates downloading stats (remaining time and downloading 89 // progress) on the AU screen. 90 void UpdateDownloadingStats(const UpdateEngineClient::Status& status); 91 92 // Returns true if there is critical system update that requires installation 93 // and immediate reboot. 94 bool HasCriticalUpdate(); 95 96 // Timer notification handlers. 97 void OnWaitForRebootTimeElapsed(); 98 99 // Checks that screen is shown, shows if not. 100 void MakeSureScreenIsShown(); 101 102 // Returns an instance of the error screen. 103 ErrorScreen* GetErrorScreen(); 104 105 void StartUpdateCheck(); 106 void ShowErrorMessage(); 107 void HideErrorMessage(); 108 void UpdateErrorMessage( 109 const Network* network, 110 const NetworkPortalDetector::CaptivePortalStatus status); 111 // Timer for the interval to wait for the reboot. 112 // If reboot didn't happen - ask user to reboot manually. 113 base::OneShotTimer<UpdateScreen> reboot_timer_; 114 115 // Returns a static InstanceSet. 116 typedef std::set<UpdateScreen*> InstanceSet; 117 static InstanceSet& GetInstanceSet(); 118 119 // Current state of the update screen. 120 State state_; 121 122 // Time in seconds after which we decide that the device has not rebooted 123 // automatically. If reboot didn't happen during this interval, ask user to 124 // reboot device manually. 125 int reboot_check_delay_; 126 127 // True if in the process of checking for update. 128 bool is_checking_for_update_; 129 // Flag that is used to detect when update download has just started. 130 bool is_downloading_update_; 131 // If true, update deadlines are ignored. 132 // Note, this is false by default. 133 bool is_ignore_update_deadlines_; 134 // Whether the update screen is shown. 135 bool is_shown_; 136 // Ignore fist IDLE status that is sent before update screen initiated check. 137 bool ignore_idle_status_; 138 139 // Keeps actor which is delegated with all showing operations. 140 UpdateScreenActor* actor_; 141 142 // Time of the first notification from the downloading stage. 143 base::Time download_start_time_; 144 double download_start_progress_; 145 146 // Time of the last notification from the downloading stage. 147 base::Time download_last_time_; 148 double download_last_progress_; 149 150 bool is_download_average_speed_computed_; 151 double download_average_speed_; 152 153 bool is_first_portal_notification_; 154 155 base::WeakPtrFactory<UpdateScreen> weak_factory_; 156 157 DISALLOW_COPY_AND_ASSIGN(UpdateScreen); 158}; 159 160} // namespace chromeos 161 162#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ 163