OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "chrome/browser/chromeos/login/screens/base_screen.h" |
17 #include "chrome/browser/chromeos/login/screens/error_screen.h" | 18 #include "chrome/browser/chromeos/login/screens/error_screen.h" |
18 #include "chrome/browser/chromeos/login/screens/update_model.h" | |
19 #include "chromeos/dbus/update_engine_client.h" | 19 #include "chromeos/dbus/update_engine_client.h" |
20 #include "chromeos/network/portal_detector/network_portal_detector.h" | 20 #include "chromeos/network/portal_detector/network_portal_detector.h" |
21 #include "components/pairing/host_pairing_controller.h" | 21 #include "components/pairing/host_pairing_controller.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
25 class BaseScreenDelegate; | 25 class BaseScreenDelegate; |
26 class ErrorScreen; | 26 class ErrorScreen; |
27 class ErrorScreensHistogramHelper; | 27 class ErrorScreensHistogramHelper; |
28 class NetworkState; | 28 class NetworkState; |
29 class ScreenManager; | 29 class ScreenManager; |
30 class UpdateView; | 30 class UpdateView; |
31 | 31 |
32 // Controller for the update screen. | 32 // Controller for the update screen. |
33 class UpdateScreen : public UpdateModel, | 33 class UpdateScreen : public BaseScreen, |
34 public UpdateEngineClient::Observer, | 34 public UpdateEngineClient::Observer, |
35 public NetworkPortalDetector::Observer { | 35 public NetworkPortalDetector::Observer { |
36 public: | 36 public: |
| 37 static UpdateScreen* Get(ScreenManager* manager); |
| 38 |
| 39 // Returns true if this instance is still active (i.e. has not been deleted). |
| 40 static bool HasInstance(UpdateScreen* inst); |
| 41 |
37 UpdateScreen(BaseScreenDelegate* base_screen_delegate, | 42 UpdateScreen(BaseScreenDelegate* base_screen_delegate, |
38 UpdateView* view, | 43 UpdateView* view, |
39 pairing_chromeos::HostPairingController* remora_controller); | 44 pairing_chromeos::HostPairingController* remora_controller); |
40 ~UpdateScreen() override; | 45 ~UpdateScreen() override; |
41 | 46 |
42 static UpdateScreen* Get(ScreenManager* manager); | 47 // Called when the being destroyed. This should call Unbind() on the |
43 | 48 // associated View if this class is destroyed before it. |
44 // UpdateModel: | 49 void OnViewDestroyed(UpdateView* view); |
45 void Show() override; | |
46 void Hide() override; | |
47 void OnViewDestroyed(UpdateView* view) override; | |
48 void OnUserAction(const std::string& action_id) override; | |
49 void OnContextKeyUpdated(const ::login::ScreenContext::KeyType& key) override; | |
50 | 50 |
51 // Starts network check. Made virtual to simplify mocking. | 51 // Starts network check. Made virtual to simplify mocking. |
52 virtual void StartNetworkCheck(); | 52 virtual void StartNetworkCheck(); |
53 | 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); | 54 void SetIgnoreIdleStatus(bool ignore_idle_status); |
58 | 55 |
59 enum ExitReason { | 56 enum ExitReason { |
60 REASON_UPDATE_CANCELED = 0, | 57 REASON_UPDATE_CANCELED = 0, |
61 REASON_UPDATE_INIT_FAILED, | 58 REASON_UPDATE_INIT_FAILED, |
62 REASON_UPDATE_NON_CRITICAL, | 59 REASON_UPDATE_NON_CRITICAL, |
63 REASON_UPDATE_ENDED | 60 REASON_UPDATE_ENDED |
64 }; | 61 }; |
65 // Reports update results to the BaseScreenDelegate. | 62 // Reports update results to the BaseScreenDelegate. |
66 virtual void ExitUpdate(ExitReason reason); | 63 virtual void ExitUpdate(ExitReason reason); |
67 | 64 |
68 // UpdateEngineClient::Observer implementation: | 65 // UpdateEngineClient::Observer implementation: |
69 void UpdateStatusChanged(const UpdateEngineClient::Status& status) override; | 66 void UpdateStatusChanged(const UpdateEngineClient::Status& status) override; |
70 | 67 |
71 // NetworkPortalDetector::Observer implementation: | 68 // NetworkPortalDetector::Observer implementation: |
72 void OnPortalDetectionCompleted( | 69 void OnPortalDetectionCompleted( |
73 const NetworkState* network, | 70 const NetworkState* network, |
74 const NetworkPortalDetector::CaptivePortalState& state) override; | 71 const NetworkPortalDetector::CaptivePortalState& state) override; |
75 | 72 |
76 // Skip update UI, usually used only in debug builds/tests. | 73 // Skip update UI, usually used only in debug builds/tests. |
77 void CancelUpdate(); | 74 void CancelUpdate(); |
78 | 75 |
79 base::OneShotTimer& GetErrorMessageTimerForTesting(); | 76 base::OneShotTimer& GetErrorMessageTimerForTesting(); |
80 | 77 |
81 private: | 78 private: |
82 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic); | 79 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic); |
83 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable); | 80 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable); |
84 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection); | 81 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection); |
85 | 82 |
86 enum State { | 83 enum class State { |
87 STATE_IDLE = 0, | 84 STATE_IDLE = 0, |
88 STATE_FIRST_PORTAL_CHECK, | 85 STATE_FIRST_PORTAL_CHECK, |
89 STATE_UPDATE, | 86 STATE_UPDATE, |
90 STATE_ERROR | 87 STATE_ERROR |
91 }; | 88 }; |
92 | 89 |
| 90 // BaseScreen: |
| 91 void Show() override; |
| 92 void Hide() override; |
| 93 void OnUserAction(const std::string& action_id) override; |
| 94 |
93 // Updates downloading stats (remaining time and downloading | 95 // Updates downloading stats (remaining time and downloading |
94 // progress) on the AU screen. | 96 // progress) on the AU screen. |
95 void UpdateDownloadingStats(const UpdateEngineClient::Status& status); | 97 void UpdateDownloadingStats(const UpdateEngineClient::Status& status); |
96 | 98 |
97 // Returns true if there is critical system update that requires installation | 99 // Returns true if there is critical system update that requires installation |
98 // and immediate reboot. | 100 // and immediate reboot. |
99 bool HasCriticalUpdate(); | 101 bool HasCriticalUpdate(); |
100 | 102 |
101 // Timer notification handlers. | 103 // Timer notification handlers. |
102 void OnWaitForRebootTimeElapsed(); | 104 void OnWaitForRebootTimeElapsed(); |
(...skipping 18 matching lines...) Expand all Loading... |
121 void DelayErrorMessage(); | 123 void DelayErrorMessage(); |
122 | 124 |
123 // The user requested an attempt to connect to the network should be made. | 125 // The user requested an attempt to connect to the network should be made. |
124 void OnConnectRequested(); | 126 void OnConnectRequested(); |
125 | 127 |
126 // Timer for the interval to wait for the reboot. | 128 // Timer for the interval to wait for the reboot. |
127 // If reboot didn't happen - ask user to reboot manually. | 129 // If reboot didn't happen - ask user to reboot manually. |
128 base::OneShotTimer reboot_timer_; | 130 base::OneShotTimer reboot_timer_; |
129 | 131 |
130 // Returns a static InstanceSet. | 132 // Returns a static InstanceSet. |
| 133 // TODO(jdufault): There should only ever be one instance of this class. |
| 134 // Remove support for supporting multiple instances. See crbug.com/672142. |
131 typedef std::set<UpdateScreen*> InstanceSet; | 135 typedef std::set<UpdateScreen*> InstanceSet; |
132 static InstanceSet& GetInstanceSet(); | 136 static InstanceSet& GetInstanceSet(); |
133 | 137 |
134 // Current state of the update screen. | 138 // Current state of the update screen. |
135 State state_; | 139 State state_ = State::STATE_IDLE; |
136 | 140 |
137 // Time in seconds after which we decide that the device has not rebooted | 141 // Time in seconds after which we decide that the device has not rebooted |
138 // automatically. If reboot didn't happen during this interval, ask user to | 142 // automatically. If reboot didn't happen during this interval, ask user to |
139 // reboot device manually. | 143 // reboot device manually. |
140 int reboot_check_delay_; | 144 int reboot_check_delay_ = 0; |
141 | 145 |
142 // True if in the process of checking for update. | 146 // True if in the process of checking for update. |
143 bool is_checking_for_update_; | 147 bool is_checking_for_update_ = true; |
144 // Flag that is used to detect when update download has just started. | 148 // Flag that is used to detect when update download has just started. |
145 bool is_downloading_update_; | 149 bool is_downloading_update_ = false; |
146 // If true, update deadlines are ignored. | 150 // If true, update deadlines are ignored. |
147 // Note, this is false by default. | 151 // Note, this is false by default. |
148 bool is_ignore_update_deadlines_; | 152 bool is_ignore_update_deadlines_ = false; |
149 // Whether the update screen is shown. | 153 // Whether the update screen is shown. |
150 bool is_shown_; | 154 bool is_shown_ = false; |
151 // Ignore fist IDLE status that is sent before update screen initiated check. | 155 // Ignore fist IDLE status that is sent before update screen initiated check. |
152 bool ignore_idle_status_; | 156 bool ignore_idle_status_ = true; |
153 | 157 |
154 UpdateView* view_; | 158 UpdateView* view_ = nullptr; |
155 | 159 |
156 // Used to track updates over Bluetooth. | 160 // Used to track updates over Bluetooth. |
157 pairing_chromeos::HostPairingController* remora_controller_; | 161 pairing_chromeos::HostPairingController* remora_controller_; |
158 | 162 |
159 // Time of the first notification from the downloading stage. | 163 // Time of the first notification from the downloading stage. |
160 base::Time download_start_time_; | 164 base::Time download_start_time_; |
161 double download_start_progress_; | 165 double download_start_progress_ = 0; |
162 | 166 |
163 // Time of the last notification from the downloading stage. | 167 // Time of the last notification from the downloading stage. |
164 base::Time download_last_time_; | 168 base::Time download_last_time_; |
165 double download_last_progress_; | 169 double download_last_progress_ = 0; |
166 | 170 |
167 bool is_download_average_speed_computed_; | 171 bool is_download_average_speed_computed_ = false; |
168 double download_average_speed_; | 172 double download_average_speed_ = 0; |
169 | 173 |
170 // True if there was no notification from NetworkPortalDetector | 174 // True if there was no notification from NetworkPortalDetector |
171 // about state for the default network. | 175 // about state for the default network. |
172 bool is_first_detection_notification_; | 176 bool is_first_detection_notification_ = true; |
173 | 177 |
174 // True if there was no notification about captive portal state for | 178 // True if there was no notification about captive portal state for |
175 // the default network. | 179 // the default network. |
176 bool is_first_portal_notification_; | 180 bool is_first_portal_notification_ = true; |
177 | 181 |
178 std::unique_ptr<ErrorScreensHistogramHelper> histogram_helper_; | 182 std::unique_ptr<ErrorScreensHistogramHelper> histogram_helper_; |
179 | 183 |
180 // Timer for the captive portal detector to show portal login page. | 184 // Timer for the captive portal detector to show portal login page. |
181 // If redirect did not happen during this delay, error message is shown | 185 // If redirect did not happen during this delay, error message is shown |
182 // instead. | 186 // instead. |
183 base::OneShotTimer error_message_timer_; | 187 base::OneShotTimer error_message_timer_; |
184 | 188 |
185 ErrorScreen::ConnectRequestCallbackSubscription connect_request_subscription_; | 189 ErrorScreen::ConnectRequestCallbackSubscription connect_request_subscription_; |
186 | 190 |
187 base::WeakPtrFactory<UpdateScreen> weak_factory_; | 191 base::WeakPtrFactory<UpdateScreen> weak_factory_; |
188 | 192 |
189 DISALLOW_COPY_AND_ASSIGN(UpdateScreen); | 193 DISALLOW_COPY_AND_ASSIGN(UpdateScreen); |
190 }; | 194 }; |
191 | 195 |
192 } // namespace chromeos | 196 } // namespace chromeos |
193 | 197 |
194 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ | 198 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_ |
OLD | NEW |