Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chromeos / network / network_change_notifier_chromeos.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 CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
6 #define CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/power_manager_client.h"
15 #include "chromeos/network/network_state_handler_observer.h"
16 #include "net/base/network_change_notifier.h"
17
18 namespace chromeos {
19
20 class CHROMEOS_EXPORT NetworkChangeNotifierChromeos
21     : public net::NetworkChangeNotifier,
22       public chromeos::PowerManagerClient::Observer,
23       public chromeos::NetworkStateHandlerObserver {
24  public:
25   NetworkChangeNotifierChromeos();
26   virtual ~NetworkChangeNotifierChromeos();
27
28   // Starts observing changes from the network state handler.
29   void Initialize();
30
31   // Stops observing changes from the network state handler.
32   void Shutdown();
33
34   // NetworkChangeNotifier overrides.
35   virtual net::NetworkChangeNotifier::ConnectionType
36       GetCurrentConnectionType() const override;
37
38   // PowerManagerClient::Observer overrides.
39   virtual void SuspendDone(const base::TimeDelta& sleep_duration) override;
40
41   // NetworkStateHandlerObserver overrides.
42   virtual void DefaultNetworkChanged(
43       const chromeos::NetworkState* default_network) override;
44
45  private:
46   FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest,
47                            ConnectionTypeFromShill);
48   friend class NetworkChangeNotifierChromeosUpdateTest;
49
50   class DnsConfigService;
51
52   // Updates the notifier state based on a default network update.
53   // |connection_type_changed| is set to true if we must report a connection
54   // type change.
55   // |ip_address_changed| is set to true if we must report an IP address change.
56   // |dns_changed| is set to true if we must report a DNS config change.
57   void UpdateState(const chromeos::NetworkState* default_network,
58                    bool* connection_type_changed,
59                    bool* ip_address_changed,
60                    bool* dns_changed);
61
62   // Maps the shill network type and technology to its NetworkChangeNotifier
63   // equivalent.
64   static net::NetworkChangeNotifier::ConnectionType
65       ConnectionTypeFromShill(const std::string& type,
66                               const std::string& technology);
67
68   // Calculates parameters used for network change notifier online/offline
69   // signals.
70   static net::NetworkChangeNotifier::NetworkChangeCalculatorParams
71       NetworkChangeCalculatorParamsChromeos();
72
73   NetworkChangeNotifier::ConnectionType connection_type_;
74   // IP address for the current default network.
75   std::string ip_address_;
76   // DNS servers for the current default network.
77   std::vector<std::string> dns_servers_;
78   // Service path for the current default network.
79   std::string service_path_;
80
81   scoped_ptr<DnsConfigService> dns_config_service_;
82
83   DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos);
84 };
85
86 }  // namespace chromeos
87
88 #endif  // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_