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