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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/strings/string16.h"
11 #include "base/timer/timer.h"
12 #include "chrome/browser/chromeos/login/screens/network_screen_actor.h"
13 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
14 #include "chromeos/network/network_state_handler_observer.h"
21 class NetworkStateHelper;
24 class NetworkScreen : public WizardScreen,
25 public NetworkStateHandlerObserver,
26 public NetworkScreenActor::Delegate {
28 NetworkScreen(ScreenObserver* screen_observer, NetworkScreenActor* actor);
29 virtual ~NetworkScreen();
31 static NetworkScreen* Get(ScreenManager* manager);
33 // WizardScreen implementation:
34 virtual void PrepareToShow() OVERRIDE;
35 virtual void Show() OVERRIDE;
36 virtual void Hide() OVERRIDE;
37 virtual std::string GetName() const OVERRIDE;
39 // NetworkStateHandlerObserver implementation:
40 virtual void NetworkConnectionStateChanged(
41 const NetworkState* network) OVERRIDE;
42 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE;
44 // NetworkScreenActor::Delegate implementation:
45 virtual void OnActorDestroyed(NetworkScreenActor* actor) OVERRIDE;
46 virtual void OnContinuePressed() OVERRIDE;
48 NetworkScreenActor* actor() const { return actor_; }
51 // Subscribes NetworkScreen to the network change notification,
52 // forces refresh of current network state.
53 virtual void Refresh();
56 friend class NetworkScreenTest;
57 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, Timeout);
58 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, CanConnect);
60 // Sets the NetworkStateHelper for use in tests. This
61 // class will take ownership of the pointed object.
62 void SetNetworkStateHelperForTest(login::NetworkStateHelper* helper);
64 // Subscribes to network change notifications.
65 void SubscribeNetworkNotification();
67 // Unsubscribes from network change notifications.
68 void UnsubscribeNetworkNotification();
70 // Notifies wizard on successful connection.
71 void NotifyOnConnection();
73 // Called by |connection_timer_| when connection to the network timed out.
74 void OnConnectionTimeout();
76 // Update UI based on current network status.
79 // Stops waiting for network to connect.
80 void StopWaitingForConnection(const base::string16& network_id);
82 // Starts waiting for network connection. Shows spinner.
83 void WaitForConnection(const base::string16& network_id);
85 // True if subscribed to network change notification.
86 bool is_network_subscribed_;
88 // ID of the the network that we are waiting for.
89 base::string16 network_id_;
91 // True if user pressed continue button so we should proceed with OOBE
92 // as soon as we are connected.
93 bool continue_pressed_;
95 // Timer for connection timeout.
96 base::OneShotTimer<NetworkScreen> connection_timer_;
98 NetworkScreenActor* actor_;
99 scoped_ptr<login::NetworkStateHelper> network_state_helper_;
101 DISALLOW_COPY_AND_ASSIGN(NetworkScreen);
104 } // namespace chromeos
106 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_