blob: d7557e5cbe4fc8150219fae4e148853a0eee00a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
#define CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/network/network_state_handler_observer.h"
#include "net/base/network_change_notifier.h"
namespace chromeos {
class CHROMEOS_EXPORT NetworkChangeNotifierChromeos
: public net::NetworkChangeNotifier,
public chromeos::PowerManagerClient::Observer,
public chromeos::NetworkStateHandlerObserver {
public:
NetworkChangeNotifierChromeos();
~NetworkChangeNotifierChromeos() override;
// Starts observing changes from the network state handler.
void Initialize();
// Stops observing changes from the network state handler.
void Shutdown();
// NetworkChangeNotifier overrides.
net::NetworkChangeNotifier::ConnectionType GetCurrentConnectionType()
const override;
double GetCurrentMaxBandwidth() const override;
// PowerManagerClient::Observer overrides.
void SuspendDone(const base::TimeDelta& sleep_duration) override;
// NetworkStateHandlerObserver overrides.
void DefaultNetworkChanged(
const chromeos::NetworkState* default_network) override;
private:
FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest,
ConnectionTypeFromShill);
friend class NetworkChangeNotifierChromeosUpdateTest;
class DnsConfigService;
// Updates the notifier state based on a default network update.
// |connection_type_changed| is set to true if we must report a connection
// type change.
// |ip_address_changed| is set to true if we must report an IP address change.
// |dns_changed| is set to true if we must report a DNS config change.
// |max_bandwidth_changed| is set to true if we must report a max bandwidth
// change.
void UpdateState(const chromeos::NetworkState* default_network,
bool* connection_type_changed,
bool* ip_address_changed,
bool* dns_changed,
bool* max_bandwidth_changed);
// Proactively retrieves current network state from the network
// state handler and calls UpdateState with the result.
void PollForState();
// Maps the shill network type and technology to its NetworkChangeNotifier
// equivalent.
static net::NetworkChangeNotifier::ConnectionType
ConnectionTypeFromShill(const std::string& type,
const std::string& technology);
// Maps the shill network type and technology to its NetworkChangeNotifier
// subtype equivalent.
static net::NetworkChangeNotifier::ConnectionSubtype GetConnectionSubtype(
const std::string& type,
const std::string& technology);
// Calculates parameters used for network change notifier online/offline
// signals.
static net::NetworkChangeNotifier::NetworkChangeCalculatorParams
NetworkChangeCalculatorParamsChromeos();
NetworkChangeNotifier::ConnectionType connection_type_;
// IP address for the current default network.
std::string ip_address_;
// DNS servers for the current default network.
std::vector<std::string> dns_servers_;
// Service path for the current default network.
std::string service_path_;
// The maximum theoretical bandwidth in megabits per second for the current
// default network.
double max_bandwidth_mbps_;
scoped_ptr<DnsConfigService> dns_config_service_;
// Callback for refreshing network state.
base::Closure poll_callback_;
// For setting up network refresh polling callbacks.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtrFactory<NetworkChangeNotifierChromeos> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos);
};
} // namespace chromeos
#endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_
|