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 "chrome/browser/chromeos/net/network_portal_detector.h"
19 #include "chromeos/dbus/update_engine_client.h"
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.
30 class UpdateScreen
: public UpdateEngineClient::Observer
,
31 public UpdateScreenActor::Delegate
,
33 public NetworkPortalDetector::Observer
{
35 UpdateScreen(ScreenObserver
* screen_observer
, UpdateScreenActor
* actor
);
36 virtual ~UpdateScreen();
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
;
44 // UpdateScreenActor::Delegate implementation:
45 virtual void CancelUpdate() OVERRIDE
;
46 virtual void OnActorDestroyed(UpdateScreenActor
* actor
) OVERRIDE
;
47 virtual void OnConnectToNetworkRequested(
48 const std::string
& service_path
) OVERRIDE
;
50 // Starts network check. Made virtual to simplify mocking.
51 virtual void StartNetworkCheck();
53 // Reboot check delay get/set, in seconds.
54 int reboot_check_delay() const { return reboot_check_delay_
; }
55 void SetRebootCheckDelay(int seconds
);
57 // Returns true if this instance is still active (i.e. has not been deleted).
58 static bool HasInstance(UpdateScreen
* inst
);
60 void SetIgnoreIdleStatus(bool ignore_idle_status
);
63 REASON_UPDATE_CANCELED
= 0,
64 REASON_UPDATE_INIT_FAILED
,
65 REASON_UPDATE_NON_CRITICAL
,
68 // Reports update results to the ScreenObserver.
69 virtual void ExitUpdate(ExitReason reason
);
71 // UpdateEngineClient::Observer implementation:
72 virtual void UpdateStatusChanged(
73 const UpdateEngineClient::Status
& status
) OVERRIDE
;
75 // NetworkPortalDetector::Observer implementation:
76 virtual void OnPortalDetectionCompleted(
77 const NetworkState
* network
,
78 const NetworkPortalDetector::CaptivePortalState
& state
) OVERRIDE
;
81 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest
, TestBasic
);
82 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest
, TestUpdateAvailable
);
83 FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest
, TestAPReselection
);
87 STATE_FIRST_PORTAL_CHECK
,
92 // Updates downloading stats (remaining time and downloading
93 // progress) on the AU screen.
94 void UpdateDownloadingStats(const UpdateEngineClient::Status
& status
);
96 // Returns true if there is critical system update that requires installation
97 // and immediate reboot.
98 bool HasCriticalUpdate();
100 // Timer notification handlers.
101 void OnWaitForRebootTimeElapsed();
103 // Checks that screen is shown, shows if not.
104 void MakeSureScreenIsShown();
106 // Returns an instance of the error screen.
107 ErrorScreen
* GetErrorScreen();
109 void StartUpdateCheck();
110 void ShowErrorMessage();
111 void HideErrorMessage();
112 void UpdateErrorMessage(
113 const NetworkState
* network
,
114 const NetworkPortalDetector::CaptivePortalStatus status
);
115 // Timer for the interval to wait for the reboot.
116 // If reboot didn't happen - ask user to reboot manually.
117 base::OneShotTimer
<UpdateScreen
> reboot_timer_
;
119 // Returns a static InstanceSet.
120 typedef std::set
<UpdateScreen
*> InstanceSet
;
121 static InstanceSet
& GetInstanceSet();
123 // Current state of the update screen.
126 // Time in seconds after which we decide that the device has not rebooted
127 // automatically. If reboot didn't happen during this interval, ask user to
128 // reboot device manually.
129 int reboot_check_delay_
;
131 // True if in the process of checking for update.
132 bool is_checking_for_update_
;
133 // Flag that is used to detect when update download has just started.
134 bool is_downloading_update_
;
135 // If true, update deadlines are ignored.
136 // Note, this is false by default.
137 bool is_ignore_update_deadlines_
;
138 // Whether the update screen is shown.
140 // Ignore fist IDLE status that is sent before update screen initiated check.
141 bool ignore_idle_status_
;
143 // Keeps actor which is delegated with all showing operations.
144 UpdateScreenActor
* actor_
;
146 // Time of the first notification from the downloading stage.
147 base::Time download_start_time_
;
148 double download_start_progress_
;
150 // Time of the last notification from the downloading stage.
151 base::Time download_last_time_
;
152 double download_last_progress_
;
154 bool is_download_average_speed_computed_
;
155 double download_average_speed_
;
157 // True if there was no notification from NetworkPortalDetector
158 // about state for the default network.
159 bool is_first_detection_notification_
;
161 // True if there was no notification about captive portal state for
162 // the default network.
163 bool is_first_portal_notification_
;
165 base::WeakPtrFactory
<UpdateScreen
> weak_factory_
;
167 DISALLOW_COPY_AND_ASSIGN(UpdateScreen
);
170 } // namespace chromeos
172 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_