network_screen.h revision 5e3f23d412006dc4db4e659864679f29341e113f
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.h"
12#include "chrome/browser/chromeos/login/language_switch_menu.h"
13#include "chrome/browser/chromeos/login/screens/network_screen_actor.h"
14#include "chrome/browser/chromeos/login/screens/wizard_screen.h"
15#include "chrome/browser/chromeos/net/connectivity_state_helper_observer.h"
16
17namespace chromeos {
18
19class NetworkScreen : public WizardScreen,
20                      public ConnectivityStateHelperObserver,
21                      public NetworkScreenActor::Delegate {
22 public:
23  NetworkScreen(ScreenObserver* screen_observer, NetworkScreenActor* actor);
24  virtual ~NetworkScreen();
25
26  // WizardScreen implementation:
27  virtual void PrepareToShow() OVERRIDE;
28  virtual void Show() OVERRIDE;
29  virtual void Hide() OVERRIDE;
30  virtual std::string GetName() const OVERRIDE;
31
32  // ConnectivityStateHelperObserver implementation:
33  virtual void NetworkManagerChanged() OVERRIDE;
34  virtual void DefaultNetworkChanged() OVERRIDE;
35
36  // NetworkScreenActor::Delegate implementation:
37  virtual void OnActorDestroyed(NetworkScreenActor* actor) OVERRIDE;
38  virtual void OnContinuePressed() OVERRIDE;
39
40  NetworkScreenActor* actor() const { return actor_; }
41
42 protected:
43  // Subscribes NetworkScreen to the network change notification,
44  // forces refresh of current network state.
45  virtual void Refresh();
46
47 private:
48  FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, Timeout);
49
50  // Subscribes to network change notifications.
51  void SubscribeNetworkNotification();
52
53  // Unsubscribes from network change notifications.
54  void UnsubscribeNetworkNotification();
55
56  // Notifies wizard on successful connection.
57  void NotifyOnConnection();
58
59  // Called by |connection_timer_| when connection to the network timed out.
60  void OnConnectionTimeout();
61
62  // Update UI based on current network status.
63  void UpdateStatus();
64
65  // Stops waiting for network to connect.
66  void StopWaitingForConnection(const string16& network_id);
67
68  // Starts waiting for network connection. Shows spinner.
69  void WaitForConnection(const string16& network_id);
70
71  // True if subscribed to network change notification.
72  bool is_network_subscribed_;
73
74  // ID of the the network that we are waiting for.
75  string16 network_id_;
76
77  // True if user pressed continue button so we should proceed with OOBE
78  // as soon as we are connected.
79  bool continue_pressed_;
80
81  // Timer for connection timeout.
82  base::OneShotTimer<NetworkScreen> connection_timer_;
83
84  NetworkScreenActor* actor_;
85
86  DISALLOW_COPY_AND_ASSIGN(NetworkScreen);
87};
88
89}  // namespace chromeos
90
91#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_
92