Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2010 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_UPDATE_SCREEN_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UPDATE_SCREEN_H_
      7 #pragma once
      8 
      9 #include "base/timer.h"
     10 #include "chrome/browser/chromeos/cros/update_library.h"
     11 #include "chrome/browser/chromeos/login/update_view.h"
     12 #include "chrome/browser/chromeos/login/view_screen.h"
     13 
     14 namespace chromeos {
     15 
     16 class UpdateController {
     17  public:
     18   // Starts update.
     19   virtual void StartUpdate() = 0;
     20   // Cancels pending update without error.
     21   virtual void CancelUpdate() = 0;
     22 };
     23 
     24 class UpdateScreen: public DefaultViewScreen<chromeos::UpdateView>,
     25                     public UpdateLibrary::Observer,
     26                     public UpdateController {
     27  public:
     28   explicit UpdateScreen(WizardScreenDelegate* delegate);
     29   virtual ~UpdateScreen();
     30 
     31   // UpdateLibrary::Observer implementation:
     32   virtual void UpdateStatusChanged(UpdateLibrary* library);
     33 
     34   // Overridden from UpdateController:
     35   virtual void StartUpdate();
     36   virtual void CancelUpdate();
     37 
     38   // Overridden from ViewScreen.
     39   virtual void Show();
     40 
     41   enum ExitReason {
     42      REASON_UPDATE_CANCELED,
     43      REASON_UPDATE_INIT_FAILED,
     44      REASON_UPDATE_NON_CRITICAL,
     45      REASON_UPDATE_ENDED
     46   };
     47 
     48   // Reports update results to the ScreenObserver.
     49   virtual void ExitUpdate(ExitReason reason);
     50 
     51   // Reboot check delay get/set, in seconds.
     52   int reboot_check_delay() const { return reboot_check_delay_; }
     53   void SetRebootCheckDelay(int seconds);
     54 
     55   // Returns true if there is critical system update that requires installation
     56   // and immediate reboot.
     57   bool HasCriticalUpdate();
     58 
     59   // Set flag to treat all updates as critical (for test purpose mainly).
     60   // Default value is false.
     61   void SetAllUpdatesCritical(bool is_critical);
     62 
     63   // Returns true if this instance is still active (i.e. has not been deleted).
     64   static bool HasInstance(UpdateScreen* inst);
     65 
     66  private:
     67   // Timer notification handlers.
     68   void OnWaitForRebootTimeElapsed();
     69 
     70   // Checks that screen is shown, shows if not.
     71   void MakeSureScreenIsShown();
     72 
     73   // Timer for the interval to wait for the reboot.
     74   // If reboot didn't happen - ask user to reboot manually.
     75   base::OneShotTimer<UpdateScreen> reboot_timer_;
     76 
     77   // Returns a static InstanceSet.
     78   typedef std::set<UpdateScreen*> InstanceSet;
     79   static InstanceSet& GetInstanceSet();
     80 
     81   // True if in the process of checking for update.
     82   bool checking_for_update_;
     83 
     84   // Time in seconds after which we decide that the device has not rebooted
     85   // automatically. If reboot didn't happen during this interval, ask user to
     86   // reboot device manually.
     87   int reboot_check_delay_;
     88 
     89   // Flag that is used to detect when update download has just started.
     90   bool is_downloading_update_;
     91 
     92   // Is all updates critical? If true, update deadlines are ignored.
     93   bool is_all_updates_critical_;
     94 
     95   DISALLOW_COPY_AND_ASSIGN(UpdateScreen);
     96 };
     97 
     98 }  // namespace chromeos
     99 
    100 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UPDATE_SCREEN_H_
    101