Home | History | Annotate | Download | only in screens
      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 "chromeos/dbus/update_engine_client.h"
     19 #include "chromeos/network/portal_detector/network_portal_detector.h"
     20 
     21 namespace chromeos {
     22 
     23 class ErrorScreen;
     24 class NetworkState;
     25 class ScreenManager;
     26 class ScreenObserver;
     27 
     28 // Controller for the update screen. It does not depend on the specific
     29 // implementation of the screen showing (Views of WebUI based), the dependency
     30 // is moved to the UpdateScreenActor instead.
     31 class UpdateScreen: public UpdateEngineClient::Observer,
     32                     public UpdateScreenActor::Delegate,
     33                     public WizardScreen,
     34                     public NetworkPortalDetector::Observer {
     35  public:
     36   UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor);
     37   virtual ~UpdateScreen();
     38 
     39   static UpdateScreen* Get(ScreenManager* manager);
     40 
     41   // Overridden from WizardScreen.
     42   virtual void PrepareToShow() OVERRIDE;
     43   virtual void Show() OVERRIDE;
     44   virtual void Hide() OVERRIDE;
     45   virtual std::string GetName() const OVERRIDE;
     46 
     47   // UpdateScreenActor::Delegate implementation:
     48   virtual void CancelUpdate() OVERRIDE;
     49   virtual void OnActorDestroyed(UpdateScreenActor* actor) OVERRIDE;
     50   virtual void OnConnectToNetworkRequested() OVERRIDE;
     51 
     52   // Starts network check. Made virtual to simplify mocking.
     53   virtual void StartNetworkCheck();
     54 
     55   // Reboot check delay get/set, in seconds.
     56   int reboot_check_delay() const { return reboot_check_delay_; }
     57   void SetRebootCheckDelay(int seconds);
     58 
     59   // Returns true if this instance is still active (i.e. has not been deleted).
     60   static bool HasInstance(UpdateScreen* inst);
     61 
     62   void SetIgnoreIdleStatus(bool ignore_idle_status);
     63 
     64   enum ExitReason {
     65      REASON_UPDATE_CANCELED = 0,
     66      REASON_UPDATE_INIT_FAILED,
     67      REASON_UPDATE_NON_CRITICAL,
     68      REASON_UPDATE_ENDED
     69   };
     70   // Reports update results to the ScreenObserver.
     71   virtual void ExitUpdate(ExitReason reason);
     72 
     73   // UpdateEngineClient::Observer implementation:
     74   virtual void UpdateStatusChanged(
     75       const UpdateEngineClient::Status& status) OVERRIDE;
     76 
     77   // NetworkPortalDetector::Observer implementation:
     78   virtual void OnPortalDetectionCompleted(
     79       const NetworkState* network,
     80       const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
     81 
     82  private:
     83   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestBasic);
     84   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestUpdateAvailable);
     85   FRIEND_TEST_ALL_PREFIXES(UpdateScreenTest, TestAPReselection);
     86 
     87   enum State {
     88     STATE_IDLE = 0,
     89     STATE_FIRST_PORTAL_CHECK,
     90     STATE_UPDATE,
     91     STATE_ERROR
     92   };
     93 
     94   // Updates downloading stats (remaining time and downloading
     95   // progress) on the AU screen.
     96   void UpdateDownloadingStats(const UpdateEngineClient::Status& status);
     97 
     98   // Returns true if there is critical system update that requires installation
     99   // and immediate reboot.
    100   bool HasCriticalUpdate();
    101 
    102   // Timer notification handlers.
    103   void OnWaitForRebootTimeElapsed();
    104 
    105   // Checks that screen is shown, shows if not.
    106   void MakeSureScreenIsShown();
    107 
    108   // Returns an instance of the error screen.
    109   ErrorScreen* GetErrorScreen();
    110 
    111   void StartUpdateCheck();
    112   void ShowErrorMessage();
    113   void HideErrorMessage();
    114   void UpdateErrorMessage(
    115       const NetworkState* network,
    116       const NetworkPortalDetector::CaptivePortalStatus status);
    117   // Timer for the interval to wait for the reboot.
    118   // If reboot didn't happen - ask user to reboot manually.
    119   base::OneShotTimer<UpdateScreen> reboot_timer_;
    120 
    121   // Returns a static InstanceSet.
    122   typedef std::set<UpdateScreen*> InstanceSet;
    123   static InstanceSet& GetInstanceSet();
    124 
    125   // Current state of the update screen.
    126   State state_;
    127 
    128   // Time in seconds after which we decide that the device has not rebooted
    129   // automatically. If reboot didn't happen during this interval, ask user to
    130   // reboot device manually.
    131   int reboot_check_delay_;
    132 
    133   // True if in the process of checking for update.
    134   bool is_checking_for_update_;
    135   // Flag that is used to detect when update download has just started.
    136   bool is_downloading_update_;
    137   // If true, update deadlines are ignored.
    138   // Note, this is false by default.
    139   bool is_ignore_update_deadlines_;
    140   // Whether the update screen is shown.
    141   bool is_shown_;
    142   // Ignore fist IDLE status that is sent before update screen initiated check.
    143   bool ignore_idle_status_;
    144 
    145   // Keeps actor which is delegated with all showing operations.
    146   UpdateScreenActor* actor_;
    147 
    148   // Time of the first notification from the downloading stage.
    149   base::Time download_start_time_;
    150   double download_start_progress_;
    151 
    152   // Time of the last notification from the downloading stage.
    153   base::Time download_last_time_;
    154   double download_last_progress_;
    155 
    156   bool is_download_average_speed_computed_;
    157   double download_average_speed_;
    158 
    159   // True if there was no notification from NetworkPortalDetector
    160   // about state for the default network.
    161   bool is_first_detection_notification_;
    162 
    163   // True if there was no notification about captive portal state for
    164   // the default network.
    165   bool is_first_portal_notification_;
    166 
    167   base::WeakPtrFactory<UpdateScreen> weak_factory_;
    168 
    169   DISALLOW_COPY_AND_ASSIGN(UpdateScreen);
    170 };
    171 
    172 }  // namespace chromeos
    173 
    174 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_UPDATE_SCREEN_H_
    175