• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_
7 
8 #include <set>
9 
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"
20 
21 namespace chromeos {
22 
23 class ErrorScreen;
24 class NetworkState;
25 class ScreenObserver;
26 
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,
32                     public WizardScreen,
33                     public NetworkPortalDetector::Observer {
34  public:
35   UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor);
36   virtual ~UpdateScreen();
37 
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;
43 
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;
49 
50   // Starts network check. Made virtual to simplify mocking.
51   virtual void StartNetworkCheck();
52 
53   // Reboot check delay get/set, in seconds.
reboot_check_delay()54   int reboot_check_delay() const { return reboot_check_delay_; }
55   void SetRebootCheckDelay(int seconds);
56 
57   // Returns true if this instance is still active (i.e. has not been deleted).
58   static bool HasInstance(UpdateScreen* inst);
59 
60   void SetIgnoreIdleStatus(bool ignore_idle_status);
61 
62   enum ExitReason {
63      REASON_UPDATE_CANCELED = 0,
64      REASON_UPDATE_INIT_FAILED,
65      REASON_UPDATE_NON_CRITICAL,
66      REASON_UPDATE_ENDED
67   };
68   // Reports update results to the ScreenObserver.
69   virtual void ExitUpdate(ExitReason reason);
70 
71   // UpdateEngineClient::Observer implementation:
72   virtual void UpdateStatusChanged(
73       const UpdateEngineClient::Status& status) OVERRIDE;
74 
75   // NetworkPortalDetector::Observer implementation:
76   virtual void OnPortalDetectionCompleted(
77       const NetworkState* network,
78       const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
79 
80  private:
81   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic);
82   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable);
83   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection);
84 
85   enum State {
86     STATE_IDLE = 0,
87     STATE_FIRST_PORTAL_CHECK,
88     STATE_UPDATE,
89     STATE_ERROR
90   };
91 
92   // Updates downloading stats (remaining time and downloading
93   // progress) on the AU screen.
94   void UpdateDownloadingStats(const UpdateEngineClient::Status& status);
95 
96   // Returns true if there is critical system update that requires installation
97   // and immediate reboot.
98   bool HasCriticalUpdate();
99 
100   // Timer notification handlers.
101   void OnWaitForRebootTimeElapsed();
102 
103   // Checks that screen is shown, shows if not.
104   void MakeSureScreenIsShown();
105 
106   // Returns an instance of the error screen.
107   ErrorScreen* GetErrorScreen();
108 
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_;
118 
119   // Returns a static InstanceSet.
120   typedef std::set<UpdateScreen*> InstanceSet;
121   static InstanceSet& GetInstanceSet();
122 
123   // Current state of the update screen.
124   State state_;
125 
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_;
130 
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.
139   bool is_shown_;
140   // Ignore fist IDLE status that is sent before update screen initiated check.
141   bool ignore_idle_status_;
142 
143   // Keeps actor which is delegated with all showing operations.
144   UpdateScreenActor* actor_;
145 
146   // Time of the first notification from the downloading stage.
147   base::Time download_start_time_;
148   double download_start_progress_;
149 
150   // Time of the last notification from the downloading stage.
151   base::Time download_last_time_;
152   double download_last_progress_;
153 
154   bool is_download_average_speed_computed_;
155   double download_average_speed_;
156 
157   // True if there was no notification from NetworkPortalDetector
158   // about state for the default network.
159   bool is_first_detection_notification_;
160 
161   // True if there was no notification about captive portal state for
162   // the default network.
163   bool is_first_portal_notification_;
164 
165   base::WeakPtrFactory<UpdateScreen> weak_factory_;
166 
167   DISALLOW_COPY_AND_ASSIGN(UpdateScreen);
168 };
169 
170 }  // namespace chromeos
171 
172 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_
173