Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / update_screen.h
blob44de547ecac9899bc26d72d3f3141ca6b06e96bd
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_
8 #include <set>
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/error_screen.h"
17 #include "chrome/browser/chromeos/login/screens/update_model.h"
18 #include "chromeos/dbus/update_engine_client.h"
19 #include "chromeos/network/portal_detector/network_portal_detector.h"
20 #include "components/pairing/host_pairing_controller.h"
22 namespace chromeos {
24 class BaseScreenDelegate;
25 class ErrorScreen;
26 class ErrorScreensHistogramHelper;
27 class NetworkState;
28 class ScreenManager;
29 class UpdateView;
31 // Controller for the update screen.
32 class UpdateScreen : public UpdateModel,
33 public UpdateEngineClient::Observer,
34 public NetworkPortalDetector::Observer {
35 public:
36 UpdateScreen(BaseScreenDelegate* base_screen_delegate,
37 UpdateView* view,
38 pairing_chromeos::HostPairingController* remora_controller);
39 ~UpdateScreen() override;
41 static UpdateScreen* Get(ScreenManager* manager);
43 // UpdateModel:
44 void PrepareToShow() override;
45 void Show() override;
46 void Hide() override;
47 void Initialize(::login::ScreenContext* context) override;
48 void OnViewDestroyed(UpdateView* view) override;
49 void OnUserAction(const std::string& action_id) override;
50 void OnContextKeyUpdated(const ::login::ScreenContext::KeyType& key) override;
52 // Starts network check. Made virtual to simplify mocking.
53 virtual void StartNetworkCheck();
55 // Returns true if this instance is still active (i.e. has not been deleted).
56 static bool HasInstance(UpdateScreen* inst);
58 void SetIgnoreIdleStatus(bool ignore_idle_status);
60 enum ExitReason {
61 REASON_UPDATE_CANCELED = 0,
62 REASON_UPDATE_INIT_FAILED,
63 REASON_UPDATE_NON_CRITICAL,
64 REASON_UPDATE_ENDED
66 // Reports update results to the BaseScreenDelegate.
67 virtual void ExitUpdate(ExitReason reason);
69 // UpdateEngineClient::Observer implementation:
70 void UpdateStatusChanged(const UpdateEngineClient::Status& status) override;
72 // NetworkPortalDetector::Observer implementation:
73 void OnPortalDetectionCompleted(
74 const NetworkState* network,
75 const NetworkPortalDetector::CaptivePortalState& state) override;
77 // Skip update UI, usually used only in debug builds/tests.
78 void CancelUpdate();
80 base::OneShotTimer<UpdateScreen>& GetErrorMessageTimerForTesting();
82 private:
83 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic);
84 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable);
85 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection);
87 enum State {
88 STATE_IDLE = 0,
89 STATE_FIRST_PORTAL_CHECK,
90 STATE_UPDATE,
91 STATE_ERROR
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 // Send update status to host pairing controller.
109 void SetHostPairingControllerStatus(
110 pairing_chromeos::HostPairingController::UpdateStatus update_status);
112 // Returns an instance of the error screen.
113 ErrorScreen* GetErrorScreen();
115 void StartUpdateCheck();
116 void ShowErrorMessage();
117 void HideErrorMessage();
118 void UpdateErrorMessage(
119 const NetworkState* network,
120 const NetworkPortalDetector::CaptivePortalStatus status);
122 void DelayErrorMessage();
124 // The user requested an attempt to connect to the network should be made.
125 void OnConnectRequested();
127 // Timer for the interval to wait for the reboot.
128 // If reboot didn't happen - ask user to reboot manually.
129 base::OneShotTimer<UpdateScreen> reboot_timer_;
131 // Returns a static InstanceSet.
132 typedef std::set<UpdateScreen*> InstanceSet;
133 static InstanceSet& GetInstanceSet();
135 // Current state of the update screen.
136 State state_;
138 // Time in seconds after which we decide that the device has not rebooted
139 // automatically. If reboot didn't happen during this interval, ask user to
140 // reboot device manually.
141 int reboot_check_delay_;
143 // True if in the process of checking for update.
144 bool is_checking_for_update_;
145 // Flag that is used to detect when update download has just started.
146 bool is_downloading_update_;
147 // If true, update deadlines are ignored.
148 // Note, this is false by default.
149 bool is_ignore_update_deadlines_;
150 // Whether the update screen is shown.
151 bool is_shown_;
152 // Ignore fist IDLE status that is sent before update screen initiated check.
153 bool ignore_idle_status_;
155 UpdateView* view_;
157 // Used to track updates over Bluetooth.
158 pairing_chromeos::HostPairingController* remora_controller_;
160 // Time of the first notification from the downloading stage.
161 base::Time download_start_time_;
162 double download_start_progress_;
164 // Time of the last notification from the downloading stage.
165 base::Time download_last_time_;
166 double download_last_progress_;
168 bool is_download_average_speed_computed_;
169 double download_average_speed_;
171 // True if there was no notification from NetworkPortalDetector
172 // about state for the default network.
173 bool is_first_detection_notification_;
175 // True if there was no notification about captive portal state for
176 // the default network.
177 bool is_first_portal_notification_;
179 scoped_ptr<ErrorScreensHistogramHelper> histogram_helper_;
181 // Timer for the captive portal detector to show portal login page.
182 // If redirect did not happen during this delay, error message is shown
183 // instead.
184 base::OneShotTimer<UpdateScreen> error_message_timer_;
186 ErrorScreen::ConnectRequestCallbackSubscription connect_request_subscription_;
188 base::WeakPtrFactory<UpdateScreen> weak_factory_;
190 DISALLOW_COPY_AND_ASSIGN(UpdateScreen);
193 } // namespace chromeos
195 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_