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