| 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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chromeos/network/network_state_handler_observer.h" | 16 #include "chromeos/network/network_state_handler_observer.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class DictionaryValue; | 19 class DictionaryValue; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 class NetworkState; | 23 class NetworkState; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace ash { | 26 namespace ash { |
| 27 | 27 |
| 28 class NetworkConnect; |
| 29 |
| 28 // This class has two purposes: | 30 // This class has two purposes: |
| 29 // 1. ShowNetworkConnectError() gets called after any user initiated connect | 31 // 1. ShowNetworkConnectError() gets called after any user initiated connect |
| 30 // failure. This will handle displaying an error notification. | 32 // failure. This will handle displaying an error notification. |
| 31 // TODO(stevenjb): convert this class to use the new MessageCenter | 33 // TODO(stevenjb): convert this class to use the new MessageCenter |
| 32 // notification system. | 34 // notification system. |
| 33 // 2. It observes NetworkState changes to generate notifications when a | 35 // 2. It observes NetworkState changes to generate notifications when a |
| 34 // Cellular network is out of credits. | 36 // Cellular network is out of credits. |
| 35 class ASH_EXPORT NetworkStateNotifier : | 37 class ASH_EXPORT NetworkStateNotifier : |
| 36 public chromeos::NetworkStateHandlerObserver { | 38 public chromeos::NetworkStateHandlerObserver { |
| 37 public: | 39 public: |
| 38 NetworkStateNotifier(); | 40 explicit NetworkStateNotifier(NetworkConnect* network_connect); |
| 39 virtual ~NetworkStateNotifier(); | 41 virtual ~NetworkStateNotifier(); |
| 40 | 42 |
| 41 // NetworkStateHandlerObserver | 43 // NetworkStateHandlerObserver |
| 42 virtual void DefaultNetworkChanged( | 44 virtual void DefaultNetworkChanged( |
| 43 const chromeos::NetworkState* network) override; | 45 const chromeos::NetworkState* network) override; |
| 44 virtual void NetworkPropertiesUpdated( | 46 virtual void NetworkPropertiesUpdated( |
| 45 const chromeos::NetworkState* network) override; | 47 const chromeos::NetworkState* network) override; |
| 46 | 48 |
| 47 // Show a connection error notification. If |error_name| matches an error | 49 // Show a connection error notification. If |error_name| matches an error |
| 48 // defined in NetworkConnectionHandler for connect, configure, or activation | 50 // defined in NetworkConnectionHandler for connect, configure, or activation |
| 49 // failed, then the associated message is shown; otherwise use the last_error | 51 // failed, then the associated message is shown; otherwise use the last_error |
| 50 // value for the network or a Shill property if available. | 52 // value for the network or a Shill property if available. |
| 51 void ShowNetworkConnectError(const std::string& error_name, | 53 void ShowNetworkConnectError(const std::string& error_name, |
| 52 const std::string& service_path); | 54 const std::string& service_path); |
| 53 | 55 |
| 56 // Show a mobile activation error notification. |
| 57 void ShowMobileActivationkError(const std::string& service_path); |
| 58 |
| 59 // Removes any existing connect notifications. |
| 60 void RemoveConnectNotification(); |
| 61 |
| 62 static const char kNetworkConnectNotificationId[]; |
| 63 static const char kNetworkActivateNotificationId[]; |
| 64 static const char kNetworkOutOfCreditsNotificationId[]; |
| 65 |
| 54 private: | 66 private: |
| 55 void ConnectErrorPropertiesSucceeded( | 67 void ConnectErrorPropertiesSucceeded( |
| 56 const std::string& error_name, | 68 const std::string& error_name, |
| 57 const std::string& service_path, | 69 const std::string& service_path, |
| 58 const base::DictionaryValue& shill_properties); | 70 const base::DictionaryValue& shill_properties); |
| 59 void ConnectErrorPropertiesFailed( | 71 void ConnectErrorPropertiesFailed( |
| 60 const std::string& error_name, | 72 const std::string& error_name, |
| 61 const std::string& service_path, | 73 const std::string& service_path, |
| 62 const std::string& shill_connect_error, | 74 const std::string& shill_connect_error, |
| 63 scoped_ptr<base::DictionaryValue> shill_error_data); | 75 scoped_ptr<base::DictionaryValue> shill_error_data); |
| 64 void ShowConnectErrorNotification( | 76 void ShowConnectErrorNotification( |
| 65 const std::string& error_name, | 77 const std::string& error_name, |
| 66 const std::string& service_path, | 78 const std::string& service_path, |
| 67 const base::DictionaryValue& shill_properties); | 79 const base::DictionaryValue& shill_properties); |
| 68 | 80 |
| 69 // Returns true if the default network changed. | 81 // Returns true if the default network changed. |
| 70 bool UpdateDefaultNetwork(const chromeos::NetworkState* network); | 82 bool UpdateDefaultNetwork(const chromeos::NetworkState* network); |
| 71 | 83 |
| 72 // Helper methods to update state and check for notifications. | 84 // Helper methods to update state and check for notifications. |
| 73 void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular); | 85 void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular); |
| 74 void UpdateCellularActivating(const chromeos::NetworkState* cellular); | 86 void UpdateCellularActivating(const chromeos::NetworkState* cellular); |
| 75 | 87 |
| 88 // Invokes network_connect_->ShowNetworkSettings from a callback. |
| 89 void ShowNetworkSettings(const std::string& service_path); |
| 90 |
| 91 NetworkConnect* network_connect_; // unowned |
| 76 std::string last_default_network_; | 92 std::string last_default_network_; |
| 77 bool did_show_out_of_credits_; | 93 bool did_show_out_of_credits_; |
| 78 base::Time out_of_credits_notify_time_; | 94 base::Time out_of_credits_notify_time_; |
| 79 std::set<std::string> cellular_activating_; | 95 std::set<std::string> cellular_activating_; |
| 80 base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_; | 96 base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_; |
| 81 | 97 |
| 82 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); | 98 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); |
| 83 }; | 99 }; |
| 84 | 100 |
| 85 } // namespace ash | 101 } // namespace ash |
| 86 | 102 |
| 87 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 103 #endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ |
| OLD | NEW |