diff options
author | gauravsh@chromium.org <gauravsh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 10:28:44 +0000 |
---|---|---|
committer | gauravsh@chromium.org <gauravsh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-20 10:28:44 +0000 |
commit | 2894798f1bf3bfdc550b66fa267549d5421bfe16 (patch) | |
tree | 51a2904e19780949d5cf98615542e8f47f1e05e0 /chromeos/network/network_change_notifier_chromeos.h | |
parent | d37b59df4b91d125695a98fe7a87be9a154dd76c (diff) | |
download | chromium_src-2894798f1bf3bfdc550b66fa267549d5421bfe16.zip chromium_src-2894798f1bf3bfdc550b66fa267549d5421bfe16.tar.gz chromium_src-2894798f1bf3bfdc550b66fa267549d5421bfe16.tar.bz2 |
Implement new network change notifier that uses NetworkStateHandler
This implements the new network change notifier that informs the Chrome
network stack of connectivity changes.
It's currently behind the --enable-new-network-handlers command line flag.
BUG=chromium-os:159647
TEST=unit tests, gmerged on a device and ensured offline->online and
online->offline transitions are correctly detected.
Review URL: https://chromiumcodereview.appspot.com/11469044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174127 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network/network_change_notifier_chromeos.h')
-rw-r--r-- | chromeos/network/network_change_notifier_chromeos.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/chromeos/network/network_change_notifier_chromeos.h b/chromeos/network/network_change_notifier_chromeos.h new file mode 100644 index 0000000..58ecde3 --- /dev/null +++ b/chromeos/network/network_change_notifier_chromeos.h @@ -0,0 +1,83 @@ +// 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/gtest_prod_util.h" +#include "base/memory/scoped_ptr.h" +#include "chromeos/chromeos_export.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::NetworkStateHandlerObserver { + public: + NetworkChangeNotifierChromeos(); + virtual ~NetworkChangeNotifierChromeos(); + + // 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; + + // NetworkStateHandlerObserver overrides. + void ActiveNetworkChanged( + const chromeos::NetworkState* active_network) OVERRIDE; + void ActiveNetworkStateChanged( + const chromeos::NetworkState* active_network) OVERRIDE; + + private: + FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest, + ConnectionTypeFromShill); + friend class NetworkChangeNotifierChromeosUpdateTest; + + class DnsConfigService; + + // Updates the notifier state based on an active 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. + void UpdateState(const chromeos::NetworkState* active_network, + bool* connection_type_changed, + bool* ip_address_changed, + bool* dns_changed); + + // Maps the shill network type and technology to its NetworkChangeNotifier + // equivalent. + static net::NetworkChangeNotifier::ConnectionType + ConnectionTypeFromShill(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 active network. + std::string ip_address_; + // Service path for the current active network. + std::string service_path_; + + scoped_ptr<DnsConfigService> dns_config_service_; + + DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos); +}; + +} // namespace chromeos + +#endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_ |