Update V8 to version 4.5.63.
[chromium-blink-merge.git] / chromeos / network / network_change_notifier_chromeos.h
blobd7557e5cbe4fc8150219fae4e148853a0eee00a2
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/single_thread_task_runner.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;
40 double GetCurrentMaxBandwidth() const override;
42 // PowerManagerClient::Observer overrides.
43 void SuspendDone(const base::TimeDelta& sleep_duration) override;
45 // NetworkStateHandlerObserver overrides.
46 void DefaultNetworkChanged(
47 const chromeos::NetworkState* default_network) override;
49 private:
50 FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest,
51 ConnectionTypeFromShill);
52 friend class NetworkChangeNotifierChromeosUpdateTest;
54 class DnsConfigService;
56 // Updates the notifier state based on a default network update.
57 // |connection_type_changed| is set to true if we must report a connection
58 // type change.
59 // |ip_address_changed| is set to true if we must report an IP address change.
60 // |dns_changed| is set to true if we must report a DNS config change.
61 // |max_bandwidth_changed| is set to true if we must report a max bandwidth
62 // change.
63 void UpdateState(const chromeos::NetworkState* default_network,
64 bool* connection_type_changed,
65 bool* ip_address_changed,
66 bool* dns_changed,
67 bool* max_bandwidth_changed);
69 // Proactively retrieves current network state from the network
70 // state handler and calls UpdateState with the result.
71 void PollForState();
73 // Maps the shill network type and technology to its NetworkChangeNotifier
74 // equivalent.
75 static net::NetworkChangeNotifier::ConnectionType
76 ConnectionTypeFromShill(const std::string& type,
77 const std::string& technology);
79 // Maps the shill network type and technology to its NetworkChangeNotifier
80 // subtype equivalent.
81 static net::NetworkChangeNotifier::ConnectionSubtype GetConnectionSubtype(
82 const std::string& type,
83 const std::string& technology);
85 // Calculates parameters used for network change notifier online/offline
86 // signals.
87 static net::NetworkChangeNotifier::NetworkChangeCalculatorParams
88 NetworkChangeCalculatorParamsChromeos();
90 NetworkChangeNotifier::ConnectionType connection_type_;
91 // IP address for the current default network.
92 std::string ip_address_;
93 // DNS servers for the current default network.
94 std::vector<std::string> dns_servers_;
95 // Service path for the current default network.
96 std::string service_path_;
98 // The maximum theoretical bandwidth in megabits per second for the current
99 // default network.
100 double max_bandwidth_mbps_;
102 scoped_ptr<DnsConfigService> dns_config_service_;
104 // Callback for refreshing network state.
105 base::Closure poll_callback_;
107 // For setting up network refresh polling callbacks.
108 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
109 base::WeakPtrFactory<NetworkChangeNotifierChromeos> weak_ptr_factory_;
111 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos);
114 } // namespace chromeos
116 #endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_