| 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 UI_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_STATE_NOTIFIER_H_ |
| 6 #define UI_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_STATE_NOTIFIER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.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_connection_observer.h" | 16 #include "chromeos/network/network_connection_observer.h" |
| 17 #include "chromeos/network/network_state_handler_observer.h" | 17 #include "chromeos/network/network_state_handler_observer.h" |
| 18 #include "ui/chromeos/ui_chromeos_export.h" | |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 class DictionaryValue; | 20 class DictionaryValue; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace chromeos { | 23 namespace chromeos { |
| 24 |
| 25 class NetworkState; | 25 class NetworkState; |
| 26 } | |
| 27 | |
| 28 namespace ui { | |
| 29 | |
| 30 class NetworkConnect; | |
| 31 | 26 |
| 32 // This class provides user notifications in the following cases: | 27 // This class provides user notifications in the following cases: |
| 33 // 1. ShowNetworkConnectError() gets called after any user initiated connect | 28 // 1. ShowNetworkConnectError() gets called after any user initiated connect |
| 34 // failure. This will handle displaying an error notification. | 29 // failure. This will handle displaying an error notification. |
| 35 // TODO(stevenjb): convert this class to use the new MessageCenter | 30 // TODO(stevenjb): convert this class to use the new MessageCenter |
| 36 // notification system. | 31 // notification system. |
| 37 // 2. It observes NetworkState changes to generate notifications when a | 32 // 2. It observes NetworkState changes to generate notifications when a |
| 38 // Cellular network is out of credits. | 33 // Cellular network is out of credits. |
| 39 // 3. Generates a notification when VPN is disconnected not as a result of | 34 // 3. Generates a notification when VPN is disconnected not as a result of |
| 40 // user's action. | 35 // user's action. |
| 41 class UI_CHROMEOS_EXPORT NetworkStateNotifier | 36 class NetworkStateNotifier : public NetworkConnectionObserver, |
| 42 : public chromeos::NetworkConnectionObserver, | 37 public NetworkStateHandlerObserver { |
| 43 public chromeos::NetworkStateHandlerObserver { | |
| 44 public: | 38 public: |
| 45 explicit NetworkStateNotifier(NetworkConnect* network_connect); | 39 NetworkStateNotifier(); |
| 46 ~NetworkStateNotifier() override; | 40 ~NetworkStateNotifier() override; |
| 47 | 41 |
| 48 // NetworkConnectionObserver | 42 // NetworkConnectionObserver |
| 49 void ConnectToNetworkRequested(const std::string& service_path) override; | 43 void ConnectToNetworkRequested(const std::string& service_path) override; |
| 50 void ConnectSucceeded(const std::string& service_path) override; | 44 void ConnectSucceeded(const std::string& service_path) override; |
| 51 void ConnectFailed(const std::string& service_path, | 45 void ConnectFailed(const std::string& service_path, |
| 52 const std::string& error_name) override; | 46 const std::string& error_name) override; |
| 53 void DisconnectRequested(const std::string& service_path) override; | 47 void DisconnectRequested(const std::string& service_path) override; |
| 54 | 48 |
| 55 // NetworkStateHandlerObserver | 49 // NetworkStateHandlerObserver |
| 56 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; | 50 void DefaultNetworkChanged(const NetworkState* network) override; |
| 57 void NetworkConnectionStateChanged( | 51 void NetworkConnectionStateChanged(const NetworkState* network) override; |
| 58 const chromeos::NetworkState* network) override; | 52 void NetworkPropertiesUpdated(const NetworkState* network) override; |
| 59 void NetworkPropertiesUpdated(const chromeos::NetworkState* network) override; | |
| 60 | 53 |
| 61 // Show a connection error notification. If |error_name| matches an error | 54 // Show a connection error notification. If |error_name| matches an error |
| 62 // defined in NetworkConnectionHandler for connect, configure, or activation | 55 // defined in NetworkConnectionHandler for connect, configure, or activation |
| 63 // failed, then the associated message is shown; otherwise use the last_error | 56 // failed, then the associated message is shown; otherwise use the last_error |
| 64 // value for the network or a Shill property if available. | 57 // value for the network or a Shill property if available. |
| 65 void ShowNetworkConnectError(const std::string& error_name, | 58 void ShowNetworkConnectError(const std::string& error_name, |
| 66 const std::string& service_path); | 59 const std::string& service_path); |
| 67 | 60 |
| 68 // Show a mobile activation error notification. | 61 // Show a mobile activation error notification. |
| 69 void ShowMobileActivationError(const std::string& service_path); | 62 void ShowMobileActivationError(const std::string& service_path); |
| 70 | 63 |
| 71 static const char kNotifierNetwork[]; | |
| 72 static const char kNotifierNetworkError[]; | |
| 73 static const char kNetworkConnectNotificationId[]; | 64 static const char kNetworkConnectNotificationId[]; |
| 74 static const char kNetworkActivateNotificationId[]; | 65 static const char kNetworkActivateNotificationId[]; |
| 75 static const char kNetworkOutOfCreditsNotificationId[]; | 66 static const char kNetworkOutOfCreditsNotificationId[]; |
| 76 | 67 |
| 77 private: | 68 private: |
| 78 void ConnectErrorPropertiesSucceeded( | 69 void ConnectErrorPropertiesSucceeded( |
| 79 const std::string& error_name, | 70 const std::string& error_name, |
| 80 const std::string& service_path, | 71 const std::string& service_path, |
| 81 const base::DictionaryValue& shill_properties); | 72 const base::DictionaryValue& shill_properties); |
| 82 void ConnectErrorPropertiesFailed( | 73 void ConnectErrorPropertiesFailed( |
| 83 const std::string& error_name, | 74 const std::string& error_name, |
| 84 const std::string& service_path, | 75 const std::string& service_path, |
| 85 const std::string& shill_connect_error, | 76 const std::string& shill_connect_error, |
| 86 std::unique_ptr<base::DictionaryValue> shill_error_data); | 77 std::unique_ptr<base::DictionaryValue> shill_error_data); |
| 87 void ShowConnectErrorNotification( | 78 void ShowConnectErrorNotification( |
| 88 const std::string& error_name, | 79 const std::string& error_name, |
| 89 const std::string& service_path, | 80 const std::string& service_path, |
| 90 const base::DictionaryValue& shill_properties); | 81 const base::DictionaryValue& shill_properties); |
| 91 void ShowVpnDisconnectedNotification(const chromeos::NetworkState* vpn); | 82 void ShowVpnDisconnectedNotification(const NetworkState* vpn); |
| 92 | 83 |
| 93 // Removes any existing connect notifications. | 84 // Removes any existing connect notifications. |
| 94 void RemoveConnectNotification(); | 85 void RemoveConnectNotification(); |
| 95 | 86 |
| 96 // Returns true if the default network changed. | 87 // Returns true if the default network changed. |
| 97 bool UpdateDefaultNetwork(const chromeos::NetworkState* network); | 88 bool UpdateDefaultNetwork(const NetworkState* network); |
| 98 | 89 |
| 99 // Helper methods to update state and check for notifications. | 90 // Helper methods to update state and check for notifications. |
| 100 void UpdateVpnConnectionState(const chromeos::NetworkState* vpn); | 91 void UpdateVpnConnectionState(const NetworkState* vpn); |
| 101 void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular); | 92 void UpdateCellularOutOfCredits(const NetworkState* cellular); |
| 102 void UpdateCellularActivating(const chromeos::NetworkState* cellular); | 93 void UpdateCellularActivating(const NetworkState* cellular); |
| 103 | 94 |
| 104 // Invokes network_connect_->ShowNetworkSettingsForPath from a callback. | 95 // Shows the network settings for |network_id|. |
| 105 void ShowNetworkSettingsForPath(const std::string& service_path); | 96 void ShowNetworkSettings(const std::string& network_id); |
| 106 | 97 |
| 107 NetworkConnect* network_connect_; // unowned | |
| 108 std::string last_default_network_; | 98 std::string last_default_network_; |
| 109 bool did_show_out_of_credits_; | 99 bool did_show_out_of_credits_; |
| 110 base::Time out_of_credits_notify_time_; | 100 base::Time out_of_credits_notify_time_; |
| 111 std::set<std::string> cellular_activating_; | 101 std::set<std::string> cellular_activating_; |
| 112 std::string connected_vpn_; | 102 std::string connected_vpn_; |
| 113 base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_; | 103 base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_; |
| 114 | 104 |
| 115 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); | 105 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); |
| 116 }; | 106 }; |
| 117 | 107 |
| 118 } // namespace ui | 108 } // namespace chromeos |
| 119 | 109 |
| 120 #endif // UI_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ | 110 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_STATE_NOTIFIER_H_ |
| OLD | NEW |