Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / ui / chromeos / network / network_state_notifier.h
blob85741ea4a5fc30894f74ad6f7ea5dad658ad5029
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 ConnectFailed(const std::string& service_path,
49 const std::string& error_name) override;
50 void DiconnectRequested(const std::string& service_path) override;
52 // NetworkStateHandlerObserver
53 void DefaultNetworkChanged(const chromeos::NetworkState* network) override;
54 void NetworkConnectionStateChanged(
55 const chromeos::NetworkState* network) override;
56 void NetworkPropertiesUpdated(const chromeos::NetworkState* network) override;
58 // Show a connection error notification. If |error_name| matches an error
59 // defined in NetworkConnectionHandler for connect, configure, or activation
60 // failed, then the associated message is shown; otherwise use the last_error
61 // value for the network or a Shill property if available.
62 void ShowNetworkConnectError(const std::string& error_name,
63 const std::string& service_path);
65 // Show a mobile activation error notification.
66 void ShowMobileActivationError(const std::string& service_path);
68 // Removes any existing connect notifications.
69 void RemoveConnectNotification();
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[];
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 scoped_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);
93 // Returns true if the default network changed.
94 bool UpdateDefaultNetwork(const chromeos::NetworkState* network);
96 // Helper methods to update state and check for notifications.
97 void UpdateVpnConnectionState(const chromeos::NetworkState* vpn);
98 void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular);
99 void UpdateCellularActivating(const chromeos::NetworkState* cellular);
101 // Invokes network_connect_->ShowNetworkSettingsForPath from a callback.
102 void ShowNetworkSettingsForPath(const std::string& service_path);
104 NetworkConnect* network_connect_; // unowned
105 std::string last_default_network_;
106 bool did_show_out_of_credits_;
107 base::Time out_of_credits_notify_time_;
108 std::set<std::string> cellular_activating_;
109 bool need_vpn_disconnection_notify_;
110 base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_;
112 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier);
115 } // namespace ui
117 #endif // UI_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_