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