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_
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"
23 class CHROMEOS_EXPORT NetworkChangeNotifierChromeos
24 : public net::NetworkChangeNotifier
,
25 public chromeos::PowerManagerClient::Observer
,
26 public chromeos::NetworkStateHandlerObserver
{
28 NetworkChangeNotifierChromeos();
29 ~NetworkChangeNotifierChromeos() override
;
31 // Starts observing changes from the network state handler.
34 // Stops observing changes from the network state handler.
37 // NetworkChangeNotifier overrides.
38 net::NetworkChangeNotifier::ConnectionType
GetCurrentConnectionType()
40 void GetCurrentMaxBandwidthAndConnectionType(
41 double* max_bandwidth_mbps
,
42 ConnectionType
* connection_type
) const override
;
44 // PowerManagerClient::Observer overrides.
45 void SuspendDone(const base::TimeDelta
& sleep_duration
) override
;
47 // NetworkStateHandlerObserver overrides.
48 void DefaultNetworkChanged(
49 const chromeos::NetworkState
* default_network
) override
;
52 FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest
,
53 ConnectionTypeFromShill
);
54 friend class NetworkChangeNotifierChromeosUpdateTest
;
56 class DnsConfigService
;
58 // Updates the notifier state based on a default network update.
59 // |connection_type_changed| is set to true if we must report a connection
61 // |ip_address_changed| is set to true if we must report an IP address change.
62 // |dns_changed| is set to true if we must report a DNS config change.
63 // |max_bandwidth_changed| is set to true if we must report a max bandwidth
65 void UpdateState(const chromeos::NetworkState
* default_network
,
66 bool* connection_type_changed
,
67 bool* ip_address_changed
,
69 bool* max_bandwidth_changed
);
71 // Proactively retrieves current network state from the network
72 // state handler and calls UpdateState with the result.
75 // Maps the shill network type and technology to its NetworkChangeNotifier
77 static net::NetworkChangeNotifier::ConnectionType
78 ConnectionTypeFromShill(const std::string
& type
,
79 const std::string
& technology
);
81 // Maps the shill network type and technology to its NetworkChangeNotifier
82 // subtype equivalent.
83 static net::NetworkChangeNotifier::ConnectionSubtype
GetConnectionSubtype(
84 const std::string
& type
,
85 const std::string
& technology
);
87 // Calculates parameters used for network change notifier online/offline
89 static net::NetworkChangeNotifier::NetworkChangeCalculatorParams
90 NetworkChangeCalculatorParamsChromeos();
92 NetworkChangeNotifier::ConnectionType connection_type_
;
93 // IP address for the current default network.
94 std::string ip_address_
;
95 // DNS servers for the current default network.
96 std::vector
<std::string
> dns_servers_
;
97 // Service path for the current default network.
98 std::string service_path_
;
100 // The maximum theoretical bandwidth in megabits per second for the current
102 double max_bandwidth_mbps_
;
104 scoped_ptr
<DnsConfigService
> dns_config_service_
;
106 // Callback for refreshing network state.
107 base::Closure poll_callback_
;
109 // For setting up network refresh polling callbacks.
110 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
111 base::WeakPtrFactory
<NetworkChangeNotifierChromeos
> weak_ptr_factory_
;
113 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos
);
116 } // namespace chromeos
118 #endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_