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/base_screen.h"
17 #include "chrome/browser/chromeos/login/screens/update_screen_actor.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"
24 class BaseScreenDelegate;
26 class ErrorScreensHistogramHelper;
30 // Controller for the update screen. It does not depend on the specific
31 // implementation of the screen showing (Views of WebUI based), the dependency
32 // is moved to the UpdateScreenActor instead.
33 class UpdateScreen : public UpdateEngineClient::Observer,
34 public UpdateScreenActor::Delegate,
36 public NetworkPortalDetector::Observer {
38 UpdateScreen(BaseScreenDelegate* base_screen_delegate,
39 UpdateScreenActor* actor,
40 pairing_chromeos::HostPairingController* remora_controller);
41 virtual ~UpdateScreen();
43 static UpdateScreen* Get(ScreenManager* manager);
45 // Overridden from BaseScreen.
46 virtual void PrepareToShow() override;
47 virtual void Show() override;
48 virtual void Hide() override;
49 virtual std::string GetName() const override;
51 // UpdateScreenActor::Delegate implementation:
52 virtual void CancelUpdate() override;
53 virtual void OnActorDestroyed(UpdateScreenActor* actor) override;
54 virtual void OnConnectToNetworkRequested() override;
56 // Starts network check. Made virtual to simplify mocking.
57 virtual void StartNetworkCheck();
59 // Reboot check delay get/set, in seconds.
60 int reboot_check_delay() const { return reboot_check_delay_; }
61 void SetRebootCheckDelay(int seconds);
63 // Returns true if this instance is still active (i.e. has not been deleted).
64 static bool HasInstance(UpdateScreen* inst);
66 void SetIgnoreIdleStatus(bool ignore_idle_status);
69 REASON_UPDATE_CANCELED = 0,
70 REASON_UPDATE_INIT_FAILED,
71 REASON_UPDATE_NON_CRITICAL,
74 // Reports update results to the BaseScreenDelegate.
75 virtual void ExitUpdate(ExitReason reason);
77 // UpdateEngineClient::Observer implementation:
78 virtual void UpdateStatusChanged(
79 const UpdateEngineClient::Status& status) override;
81 // NetworkPortalDetector::Observer implementation:
82 virtual void OnPortalDetectionCompleted(
83 const NetworkState* network,
84 const NetworkPortalDetector::CaptivePortalState& state) override;
87 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic);
88 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable);
89 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection);
93 STATE_FIRST_PORTAL_CHECK,
98 // Updates downloading stats (remaining time and downloading
99 // progress) on the AU screen.
100 void UpdateDownloadingStats(const UpdateEngineClient::Status& status);
102 // Returns true if there is critical system update that requires installation
103 // and immediate reboot.
104 bool HasCriticalUpdate();
106 // Timer notification handlers.
107 void OnWaitForRebootTimeElapsed();
109 // Checks that screen is shown, shows if not.
110 void MakeSureScreenIsShown();
112 // Send update status to host pairing controller.
113 void SetHostPairingControllerStatus(
114 pairing_chromeos::HostPairingController::UpdateStatus update_status);
116 // Returns an instance of the error screen.
117 ErrorScreen* GetErrorScreen();
119 void StartUpdateCheck();
120 void ShowErrorMessage();
121 void HideErrorMessage();
122 void UpdateErrorMessage(
123 const NetworkState* network,
124 const NetworkPortalDetector::CaptivePortalStatus status);
125 // Timer for the interval to wait for the reboot.
126 // If reboot didn't happen - ask user to reboot manually.
127 base::OneShotTimer<UpdateScreen> reboot_timer_;
129 // Returns a static InstanceSet.
130 typedef std::set<UpdateScreen*> InstanceSet;
131 static InstanceSet& GetInstanceSet();
133 // Current state of the update screen.
136 // Time in seconds after which we decide that the device has not rebooted
137 // automatically. If reboot didn't happen during this interval, ask user to
138 // reboot device manually.
139 int reboot_check_delay_;
141 // True if in the process of checking for update.
142 bool is_checking_for_update_;
143 // Flag that is used to detect when update download has just started.
144 bool is_downloading_update_;
145 // If true, update deadlines are ignored.
146 // Note, this is false by default.
147 bool is_ignore_update_deadlines_;
148 // Whether the update screen is shown.
150 // Ignore fist IDLE status that is sent before update screen initiated check.
151 bool ignore_idle_status_;
153 // Keeps actor which is delegated with all showing operations.
154 UpdateScreenActor* actor_;
156 // Used to track updates over Bluetooth.
157 pairing_chromeos::HostPairingController* remora_controller_;
159 // Time of the first notification from the downloading stage.
160 base::Time download_start_time_;
161 double download_start_progress_;
163 // Time of the last notification from the downloading stage.
164 base::Time download_last_time_;
165 double download_last_progress_;
167 bool is_download_average_speed_computed_;
168 double download_average_speed_;
170 // True if there was no notification from NetworkPortalDetector
171 // about state for the default network.
172 bool is_first_detection_notification_;
174 // True if there was no notification about captive portal state for
175 // the default network.
176 bool is_first_portal_notification_;
178 scoped_ptr<ErrorScreensHistogramHelper> histogram_helper_;
180 base::WeakPtrFactory<UpdateScreen> weak_factory_;
182 DISALLOW_COPY_AND_ASSIGN(UpdateScreen);
185 } // namespace chromeos
187 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_