- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / network / network_state_notifier.h
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 ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_
6 #define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_
7
8 #include <set>
9
10 #include "ash/ash_export.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "chromeos/network/network_state_handler_observer.h"
17
18 namespace base {
19 class DictionaryValue;
20 }
21
22 namespace chromeos {
23 class NetworkState;
24 }
25
26 namespace ash {
27
28 // This class has two purposes:
29 // 1. ShowNetworkConnectError() gets called after any user initiated connect
30 //    failure. This will handle displaying an error notification.
31 //    TODO(stevenjb): convert this class to use the new MessageCenter
32 //    notification system.
33 // 2. It observes NetworkState changes to generate notifications when a
34 //    Cellular network is out of credits.
35 class ASH_EXPORT NetworkStateNotifier :
36       public chromeos::NetworkStateHandlerObserver {
37  public:
38   NetworkStateNotifier();
39   virtual ~NetworkStateNotifier();
40
41   // NetworkStateHandlerObserver
42   virtual void DefaultNetworkChanged(
43       const chromeos::NetworkState* network) OVERRIDE;
44   virtual void NetworkPropertiesUpdated(
45       const chromeos::NetworkState* network) OVERRIDE;
46
47   // Show a connection error notification. If |error_name| matches an error
48   // defined in NetworkConnectionHandler for connect, configure, or activation
49   // failed, then the associated message is shown, otherwise |shill_error|
50   // is expected to contain Service.Error (which might get cleared before
51   // GetProperties returns).
52   void ShowNetworkConnectError(const std::string& error_name,
53                                const std::string& shill_error,
54                                const std::string& service_path);
55
56  private:
57   void ConnectErrorPropertiesSucceeded(
58       const std::string& error_name,
59       const std::string& shill_error,
60       const std::string& service_path,
61       const base::DictionaryValue& shill_properties);
62   void ConnectErrorPropertiesFailed(
63       const std::string& error_name,
64       const std::string& shill_error,
65       const std::string& service_path,
66       const std::string& shill_connect_error,
67       scoped_ptr<base::DictionaryValue> shill_error_data);
68   void ShowConnectErrorNotification(
69       const std::string& error_name,
70       const std::string& shill_error,
71       const std::string& service_path,
72       const base::DictionaryValue& shill_properties);
73
74   // Returns true if the default network changed.
75   bool UpdateDefaultNetwork(const chromeos::NetworkState* network);
76
77   // Helper methods to update state and check for notifications.
78   void UpdateCellularOutOfCredits(const chromeos::NetworkState* cellular);
79   void UpdateCellularActivating(const chromeos::NetworkState* cellular);
80
81   std::string last_default_network_;
82   bool did_show_out_of_credits_;
83   base::Time out_of_credits_notify_time_;
84   std::set<std::string> cellular_activating_;
85   base::WeakPtrFactory<NetworkStateNotifier> weak_ptr_factory_;
86
87   DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier);
88 };
89
90 }  // namespace ash
91
92 #endif  // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_