Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / screens / network_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_NETWORK_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
12 #include "base/timer/timer.h"
13 #include "chrome/browser/chromeos/login/screens/base_screen.h"
14 #include "chrome/browser/chromeos/login/screens/network_screen_actor.h"
15 #include "chromeos/network/network_state_handler_observer.h"
16
17 namespace chromeos {
18
19 class ScreenManager;
20
21 namespace login {
22 class NetworkStateHelper;
23 }  // namespace login
24
25 class NetworkScreen : public BaseScreen,
26                       public NetworkStateHandlerObserver,
27                       public NetworkScreenActor::Delegate {
28  public:
29   NetworkScreen(BaseScreenDelegate* base_screen_delegate,
30                 NetworkScreenActor* actor);
31   virtual ~NetworkScreen();
32
33   static NetworkScreen* Get(ScreenManager* manager);
34
35   // BaseScreen implementation:
36   virtual void PrepareToShow() override;
37   virtual void Show() override;
38   virtual void Hide() override;
39   virtual std::string GetName() const override;
40
41   // NetworkStateHandlerObserver implementation:
42   virtual void NetworkConnectionStateChanged(
43       const NetworkState* network) override;
44   virtual void DefaultNetworkChanged(const NetworkState* network) override;
45
46   // NetworkScreenActor::Delegate implementation:
47   virtual void OnActorDestroyed(NetworkScreenActor* actor) override;
48   virtual void OnContinuePressed() override;
49
50   NetworkScreenActor* actor() const { return actor_; }
51
52  protected:
53   // Subscribes NetworkScreen to the network change notification,
54   // forces refresh of current network state.
55   virtual void Refresh();
56
57  private:
58   friend class NetworkScreenTest;
59   FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, Timeout);
60   FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, CanConnect);
61
62   // Sets the NetworkStateHelper for use in tests. This
63   // class will take ownership of the pointed object.
64   void SetNetworkStateHelperForTest(login::NetworkStateHelper* helper);
65
66   // Subscribes to network change notifications.
67   void SubscribeNetworkNotification();
68
69   // Unsubscribes from network change notifications.
70   void UnsubscribeNetworkNotification();
71
72   // Notifies wizard on successful connection.
73   void NotifyOnConnection();
74
75   // Called by |connection_timer_| when connection to the network timed out.
76   void OnConnectionTimeout();
77
78   // Update UI based on current network status.
79   void UpdateStatus();
80
81   // Stops waiting for network to connect.
82   void StopWaitingForConnection(const base::string16& network_id);
83
84   // Starts waiting for network connection. Shows spinner.
85   void WaitForConnection(const base::string16& network_id);
86
87   // True if subscribed to network change notification.
88   bool is_network_subscribed_;
89
90   // ID of the the network that we are waiting for.
91   base::string16 network_id_;
92
93   // True if user pressed continue button so we should proceed with OOBE
94   // as soon as we are connected.
95   bool continue_pressed_;
96
97   // Timer for connection timeout.
98   base::OneShotTimer<NetworkScreen> connection_timer_;
99
100   NetworkScreenActor* actor_;
101   scoped_ptr<login::NetworkStateHelper> network_state_helper_;
102
103   DISALLOW_COPY_AND_ASSIGN(NetworkScreen);
104 };
105
106 }  // namespace chromeos
107
108 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_