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"
19 class NetworkStateHelper
;
22 class NetworkScreen
: public WizardScreen
,
23 public NetworkStateHandlerObserver
,
24 public NetworkScreenActor::Delegate
{
26 NetworkScreen(ScreenObserver
* screen_observer
, NetworkScreenActor
* actor
);
27 virtual ~NetworkScreen();
29 // WizardScreen implementation:
30 virtual void PrepareToShow() OVERRIDE
;
31 virtual void Show() OVERRIDE
;
32 virtual void Hide() OVERRIDE
;
33 virtual std::string
GetName() const OVERRIDE
;
35 // NetworkStateHandlerObserver implementation:
36 virtual void NetworkConnectionStateChanged(
37 const NetworkState
* network
) OVERRIDE
;
38 virtual void DefaultNetworkChanged(const NetworkState
* network
) OVERRIDE
;
40 // NetworkScreenActor::Delegate implementation:
41 virtual void OnActorDestroyed(NetworkScreenActor
* actor
) OVERRIDE
;
42 virtual void OnContinuePressed() OVERRIDE
;
44 NetworkScreenActor
* actor() const { return actor_
; }
47 // Subscribes NetworkScreen to the network change notification,
48 // forces refresh of current network state.
49 virtual void Refresh();
52 friend class NetworkScreenTest
;
53 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest
, Timeout
);
54 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest
, CanConnect
);
56 // Sets the NetworkStateHelper for use in tests. This
57 // class will take ownership of the pointed object.
58 void SetNetworkStateHelperForTest(login::NetworkStateHelper
* helper
);
60 // Subscribes to network change notifications.
61 void SubscribeNetworkNotification();
63 // Unsubscribes from network change notifications.
64 void UnsubscribeNetworkNotification();
66 // Notifies wizard on successful connection.
67 void NotifyOnConnection();
69 // Called by |connection_timer_| when connection to the network timed out.
70 void OnConnectionTimeout();
72 // Update UI based on current network status.
75 // Stops waiting for network to connect.
76 void StopWaitingForConnection(const base::string16
& network_id
);
78 // Starts waiting for network connection. Shows spinner.
79 void WaitForConnection(const base::string16
& network_id
);
81 // True if subscribed to network change notification.
82 bool is_network_subscribed_
;
84 // ID of the the network that we are waiting for.
85 base::string16 network_id_
;
87 // True if user pressed continue button so we should proceed with OOBE
88 // as soon as we are connected.
89 bool continue_pressed_
;
91 // Timer for connection timeout.
92 base::OneShotTimer
<NetworkScreen
> connection_timer_
;
94 NetworkScreenActor
* actor_
;
95 scoped_ptr
<login::NetworkStateHelper
> network_state_helper_
;
97 DISALLOW_COPY_AND_ASSIGN(NetworkScreen
);
100 } // namespace chromeos
102 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_