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