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