network_change_notifier_chromeos.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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. 4 5#ifndef CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_ 6#define CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/gtest_prod_util.h" 12#include "base/memory/scoped_ptr.h" 13#include "chromeos/chromeos_export.h" 14#include "chromeos/network/network_state_handler_observer.h" 15#include "net/base/network_change_notifier.h" 16 17namespace chromeos { 18 19class CHROMEOS_EXPORT NetworkChangeNotifierChromeos 20 : public net::NetworkChangeNotifier, 21 public chromeos::NetworkStateHandlerObserver { 22 public: 23 NetworkChangeNotifierChromeos(); 24 virtual ~NetworkChangeNotifierChromeos(); 25 26 // Starts observing changes from the network state handler. 27 void Initialize(); 28 29 // Stops observing changes from the network state handler. 30 void Shutdown(); 31 32 // NetworkChangeNotifier overrides. 33 virtual net::NetworkChangeNotifier::ConnectionType 34 GetCurrentConnectionType() const OVERRIDE; 35 36 // NetworkStateHandlerObserver overrides. 37 virtual void DefaultNetworkChanged( 38 const chromeos::NetworkState* default_network) OVERRIDE; 39 40 private: 41 FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierChromeosTest, 42 ConnectionTypeFromShill); 43 friend class NetworkChangeNotifierChromeosUpdateTest; 44 45 class DnsConfigService; 46 47 // Updates the notifier state based on a default network update. 48 // |connection_type_changed| is set to true if we must report a connection 49 // type change. 50 // |ip_address_changed| is set to true if we must report an IP address change. 51 // |dns_changed| is set to true if we must report a DNS config change. 52 void UpdateState(const chromeos::NetworkState* default_network, 53 bool* connection_type_changed, 54 bool* ip_address_changed, 55 bool* dns_changed); 56 57 // Maps the shill network type and technology to its NetworkChangeNotifier 58 // equivalent. 59 static net::NetworkChangeNotifier::ConnectionType 60 ConnectionTypeFromShill(const std::string& type, 61 const std::string& technology); 62 63 // Calculates parameters used for network change notifier online/offline 64 // signals. 65 static net::NetworkChangeNotifier::NetworkChangeCalculatorParams 66 NetworkChangeCalculatorParamsChromeos(); 67 68 NetworkChangeNotifier::ConnectionType connection_type_; 69 // IP address for the current default network. 70 std::string ip_address_; 71 // Service path for the current default network. 72 std::string service_path_; 73 74 scoped_ptr<DnsConfigService> dns_config_service_; 75 76 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierChromeos); 77}; 78 79} // namespace chromeos 80 81#endif // CHROMEOS_NETWORK_NETWORK_CHANGE_NOTIFIER_CHROMEOS_H_ 82