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 ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ 6 #define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ 7 8 #include <map> 9 10 #include "ash/ash_export.h" 11 #include "ash/system/chromeos/network/network_tray_delegate.h" 12 #include "base/basictypes.h" 13 #include "base/compiler_specific.h" 14 #include "base/time/time.h" 15 #include "chromeos/network/network_state_handler_observer.h" 16 17 namespace chromeos { 18 class NetworkState; 19 } 20 21 namespace ash { 22 23 // This class has two purposes: 24 // 1. ShowNetworkConnectError() gets called after any user initiated connect 25 // failure. This will handle displaying an error notification. 26 // NOTE: Because Shill sets the Error property of a Service *after* 27 // the Connect call fails, this class will delay the notification if 28 // necessary until the Error property is set so that the correct 29 // message can be displayed. 30 // TODO(stevenjb): convert this class to use the new MessageCenter 31 // notification system, generate a notification immediately, and update 32 // it when the Error property is set to guarantee that a notification is 33 // displayed for every failure. 34 // 2. It observes NetworkState changes to generate notifications when a 35 // Cellular network is out of credits. 36 class ASH_EXPORT NetworkStateNotifier : 37 public chromeos::NetworkStateHandlerObserver, 38 public NetworkTrayDelegate { 39 public: 40 NetworkStateNotifier(); 41 virtual ~NetworkStateNotifier(); 42 43 // NetworkStateHandlerObserver 44 virtual void NetworkListChanged() OVERRIDE; 45 virtual void DefaultNetworkChanged( 46 const chromeos::NetworkState* network) OVERRIDE; 47 virtual void NetworkPropertiesUpdated( 48 const chromeos::NetworkState* network) OVERRIDE; 49 50 // NetworkTrayDelegate 51 virtual void NotificationLinkClicked( 52 NetworkObserver::MessageType message_type, 53 size_t link_index) OVERRIDE; 54 55 // Show a connection error notification. 56 void ShowNetworkConnectError(const std::string& error_name, 57 const std::string& service_path); 58 59 private: 60 typedef std::map<std::string, std::string> CachedStateMap; 61 62 std::string last_active_network_; 63 std::string cellular_network_; 64 std::string connect_failed_network_; 65 bool cellular_out_of_credits_; 66 base::Time out_of_credits_notify_time_; 67 68 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); 69 }; 70 71 } // namespace ash 72 73 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ 74