| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 5 #ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ |
| 6 #define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 6 #define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/system/chromeos/network/network_tray_delegate.h" | 11 #include "ash/system/chromeos/network/network_tray_delegate.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chromeos/network/network_state_handler_observer.h" | 15 #include "chromeos/network/network_state_handler_observer.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 class NetworkState; | 18 class NetworkState; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 | 22 |
| 23 // This class observes NetworkStateHandler and generates notifications | 23 // This class has two purposes: |
| 24 // on connection failures. NOTE: The Observer for this class only triggers | 24 // 1. ShowNetworkConnectError() gets called after any user initiated connect |
| 25 // "Out of credits" notifications, and failures triggered from NetworkLibrary | 25 // failure. This will handle displaying an error notification. |
| 26 // calls (which sets NetworkStateHandler::connecting_network()). | 26 // NOTE: Because Shill sets the Error property of a Service *after* |
| 27 // Failures from NetworkStateListDetailedView::ConnectToNetwork are now | 27 // the Connect call fails, this class will delay the notification if |
| 28 // handled by the ConnectToNetwork callbacks. | 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. |
| 29 class ASH_EXPORT NetworkStateNotifier : | 36 class ASH_EXPORT NetworkStateNotifier : |
| 30 public chromeos::NetworkStateHandlerObserver, | 37 public chromeos::NetworkStateHandlerObserver, |
| 31 public NetworkTrayDelegate { | 38 public NetworkTrayDelegate { |
| 32 public: | 39 public: |
| 33 NetworkStateNotifier(); | 40 NetworkStateNotifier(); |
| 34 virtual ~NetworkStateNotifier(); | 41 virtual ~NetworkStateNotifier(); |
| 35 | 42 |
| 36 // NetworkStateHandlerObserver | 43 // NetworkStateHandlerObserver |
| 44 virtual void NetworkListChanged() OVERRIDE; |
| 37 virtual void DefaultNetworkChanged( | 45 virtual void DefaultNetworkChanged( |
| 38 const chromeos::NetworkState* network) OVERRIDE; | 46 const chromeos::NetworkState* network) OVERRIDE; |
| 39 virtual void NetworkConnectionStateChanged( | |
| 40 const chromeos::NetworkState* network) OVERRIDE; | |
| 41 virtual void NetworkPropertiesUpdated( | 47 virtual void NetworkPropertiesUpdated( |
| 42 const chromeos::NetworkState* network) OVERRIDE; | 48 const chromeos::NetworkState* network) OVERRIDE; |
| 43 | 49 |
| 44 // NetworkTrayDelegate | 50 // NetworkTrayDelegate |
| 45 virtual void NotificationLinkClicked( | 51 virtual void NotificationLinkClicked( |
| 46 NetworkObserver::MessageType message_type, | 52 NetworkObserver::MessageType message_type, |
| 47 size_t link_index) OVERRIDE; | 53 size_t link_index) OVERRIDE; |
| 48 | 54 |
| 49 // Show a connection error notification. | 55 // Show a connection error notification. |
| 50 void ShowNetworkConnectError(const std::string& error_name, | 56 void ShowNetworkConnectError(const std::string& error_name, |
| 51 const std::string& service_path); | 57 const std::string& service_path); |
| 52 | 58 |
| 53 private: | 59 private: |
| 54 typedef std::map<std::string, std::string> CachedStateMap; | 60 typedef std::map<std::string, std::string> CachedStateMap; |
| 55 | 61 |
| 56 void ShowConnectError(const std::string& error_name, | |
| 57 const chromeos::NetworkState* network); | |
| 58 | |
| 59 void InitializeNetworks(); | |
| 60 | |
| 61 CachedStateMap cached_state_; | |
| 62 std::string last_active_network_; | 62 std::string last_active_network_; |
| 63 std::string cellular_network_; | 63 std::string cellular_network_; |
| 64 std::string connect_failed_network_; |
| 64 bool cellular_out_of_credits_; | 65 bool cellular_out_of_credits_; |
| 65 base::Time out_of_credits_notify_time_; | 66 base::Time out_of_credits_notify_time_; |
| 66 | 67 |
| 67 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); | 68 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 } // namespace ash | 71 } // namespace ash |
| 71 | 72 |
| 72 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 73 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ |
| OLD | NEW |