network_screen.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_ 6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_ 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/compiler_specific.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/ref_counted.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/strings/string16.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/timer/timer.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/chromeos/login/screens/network_screen_actor.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/chromeos/login/screens/wizard_screen.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chromeos/network/network_state_handler_observer.h" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace chromeos { 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace login { 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class NetworkStateHelper; 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace login 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class NetworkScreen : public WizardScreen, 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public NetworkStateHandlerObserver, 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public NetworkScreenActor::Delegate { 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NetworkScreen(ScreenObserver* screen_observer, NetworkScreenActor* actor); 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ~NetworkScreen(); 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // WizardScreen implementation: 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void PrepareToShow() OVERRIDE; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void Show() OVERRIDE; 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void Hide() OVERRIDE; 33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 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 base::string16& network_id); 77 78 // Starts waiting for network connection. Shows spinner. 79 void WaitForConnection(const base::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 base::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