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