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