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/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"
22 class NetworkStateHelper;
25 class NetworkScreen : public BaseScreen,
26 public NetworkStateHandlerObserver,
27 public NetworkScreenActor::Delegate {
29 NetworkScreen(BaseScreenDelegate* base_screen_delegate,
30 NetworkScreenActor* actor);
31 virtual ~NetworkScreen();
33 static NetworkScreen* Get(ScreenManager* manager);
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;
41 // NetworkStateHandlerObserver implementation:
42 virtual void NetworkConnectionStateChanged(
43 const NetworkState* network) override;
44 virtual void DefaultNetworkChanged(const NetworkState* network) override;
46 // NetworkScreenActor::Delegate implementation:
47 virtual void OnActorDestroyed(NetworkScreenActor* actor) override;
48 virtual void OnContinuePressed() override;
50 NetworkScreenActor* actor() const { return actor_; }
53 // Subscribes NetworkScreen to the network change notification,
54 // forces refresh of current network state.
55 virtual void Refresh();
58 friend class NetworkScreenTest;
59 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, Timeout);
60 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, CanConnect);
62 // Sets the NetworkStateHelper for use in tests. This
63 // class will take ownership of the pointed object.
64 void SetNetworkStateHelperForTest(login::NetworkStateHelper* helper);
66 // Subscribes to network change notifications.
67 void SubscribeNetworkNotification();
69 // Unsubscribes from network change notifications.
70 void UnsubscribeNetworkNotification();
72 // Notifies wizard on successful connection.
73 void NotifyOnConnection();
75 // Called by |connection_timer_| when connection to the network timed out.
76 void OnConnectionTimeout();
78 // Update UI based on current network status.
81 // Stops waiting for network to connect.
82 void StopWaitingForConnection(const base::string16& network_id);
84 // Starts waiting for network connection. Shows spinner.
85 void WaitForConnection(const base::string16& network_id);
87 // True if subscribed to network change notification.
88 bool is_network_subscribed_;
90 // ID of the the network that we are waiting for.
91 base::string16 network_id_;
93 // True if user pressed continue button so we should proceed with OOBE
94 // as soon as we are connected.
95 bool continue_pressed_;
97 // Timer for connection timeout.
98 base::OneShotTimer<NetworkScreen> connection_timer_;
100 NetworkScreenActor* actor_;
101 scoped_ptr<login::NetworkStateHelper> network_state_helper_;
103 DISALLOW_COPY_AND_ASSIGN(NetworkScreen);
106 } // namespace chromeos
108 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_