[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / chromeos / network / network_change_notifier_chromeos.h
blobd5e84139ab70553ac5339abd39d5b9ccb0da69d7
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 CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
6 #define CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h"
16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/dbus/power_manager_client.h"
18 #include "chromeos/network/network_state_handler_observer.h"
19 #include "net/base/network_change_notifier.h"
21 namespace chromeos {
23 class CHROMEOS_EXPORT NetworkChangeNotifierChromeos
24 : public net::NetworkChangeNotifier,
25 public chromeos::PowerManagerClient::Observer,
26 public chromeos::NetworkStateHandlerObserver {
27 public:
28 NetworkChangeNotifierChromeos();
29 ~NetworkChangeNotifierChromeos() override;
31 // Starts observing changes from the network state handler.
32 void Initialize();
34 // Stops observing changes from the network state handler.
35 void Shutdown();
37 // NetworkChangeNotifier overrides.
38 net::NetworkChangeNotifier::ConnectionType GetCurrentConnectionType()
39 const override;
41 // PowerManagerClient::Observer overrides.
42 void SuspendDone(const base::TimeDelta& sleep_duration) override;
44 // NetworkStateHandlerObserver overrides.
45 void DefaultNetworkChanged(
46 const chromeos::NetworkState* default_network) override;
48 private:
49 FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest,
50 ConnectionTypeFromShill);
51 friend class NetworkChangeNotifierChromeosUpdateTest;
53 class DnsConfigService;
55 // Updates the notifier state based on a default network update.
56 // |connection_type_changed| is set to true if we must report a connection
57 // type change.
58 // |ip_address_changed| is set to true if we must report an IP address change.
59 // |dns_changed| is set to true if we must report a DNS config change.
60 void UpdateState(const chromeos::NetworkState* default_network,
61 bool* connection_type_changed,
62 bool* ip_address_changed,
63 bool* dns_changed);
65 // Proactively retrieves current network state from the network
66 // state handler and calls UpdateState with the result.
67 void PollForState();
69 // Maps the shill network type and technology to its NetworkChangeNotifier
70 // equivalent.
71 static net::NetworkChangeNotifier::ConnectionType
72 ConnectionTypeFromShill(const std::string& type,
73 const std::string& technology);
75 // Calculates parameters used for network change notifier online/offline
76 // signals.
77 static net::NetworkChangeNotifier::NetworkChangeCalculatorParams
78 NetworkChangeCalculatorParamsChromeos();
80 NetworkChangeNotifier::ConnectionType connection_type_;
81 // IP address for the current default network.
82 std::string ip_address_;
83 // DNS servers for the current default network.
84 std::vector<std::string> dns_servers_;
85 // Service path for the current default network.
86 std::string service_path_;
88 scoped_ptr<DnsConfigService> dns_config_service_;
90 // Callback for refreshing network state.
91 base::Closure poll_callback_;
93 // For setting up network refresh polling callbacks.
94 scoped_refptr<base::MessageLoopProxy> message_loop_;
95 base::WeakPtrFactory<NetworkChangeNotifierChromeos> weak_ptr_factory_;
97 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos);
100 } // namespace chromeos
102 #endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_