OLD | NEW |
(Empty) | |
| 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_CONNECTION_CHANGE_NOTIFIER_H_ |
| 6 #define CHROMEOS_NETWORK_CONNECTION_CHANGE_NOTIFIER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chromeos/chromeos_export.h" |
| 13 #include "chromeos/network/network_state_handler_observer.h" |
| 14 #include "net/base/network_change_notifier.h" |
| 15 #include "net/dns/dns_config_service_posix.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 class CHROMEOS_EXPORT ConnectionChangeNotifier |
| 20 : public net::NetworkChangeNotifier, |
| 21 public chromeos::NetworkStateHandlerObserver { |
| 22 public: |
| 23 ConnectionChangeNotifier(); |
| 24 virtual ~ConnectionChangeNotifier(); |
| 25 |
| 26 // Initialize the connection change notifier. Start observing |
| 27 // changes from the network state handler. |
| 28 void Initialize(); |
| 29 |
| 30 // Shutdown the connection change notifier. Stop observing |
| 31 // changes from the network state handler. |
| 32 void Shutdown(); |
| 33 |
| 34 // NetworkChangeNotifier overrides. |
| 35 net::NetworkChangeNotifier::ConnectionType |
| 36 GetCurrentConnectionType() const OVERRIDE; |
| 37 |
| 38 // NetworkStateHandlerObserver overrides. |
| 39 void ActiveNetworkChanged( |
| 40 const chromeos::NetworkState* active_network) OVERRIDE; |
| 41 void ActiveNetworkStateChanged( |
| 42 const chromeos::NetworkState* active_network) OVERRIDE; |
| 43 |
| 44 private: |
| 45 friend class ConnectionChangeNotifierUpdateTest; |
| 46 |
| 47 class DnsConfigServiceChromeos : public net::internal::DnsConfigServicePosix { |
| 48 public: |
| 49 DnsConfigServiceChromeos(); |
| 50 virtual ~DnsConfigServiceChromeos(); |
| 51 |
| 52 // net::Internal::DnsConfigService() overrides. |
| 53 virtual bool StartWatching() OVERRIDE; |
| 54 |
| 55 virtual void OnNetworkChange(); |
| 56 }; |
| 57 |
| 58 // Maps the shill network type and technology to its NetworkChangeNotifier |
| 59 // equivalent. |
| 60 static net::NetworkChangeNotifier::ConnectionType |
| 61 ConnectionTypeFromShill(const std::string& type, |
| 62 const std::string& technology); |
| 63 |
| 64 // Updates the state based on an active network update. |
| 65 // |connection_type_changed| is set to true if we must report a connection |
| 66 // type change. |
| 67 // |ip_address_changed| is set to true if we must report an IP address change. |
| 68 // |dns_changed| is set to true if we must report a DNS config change. |
| 69 void UpdateActiveNetwork(const chromeos::NetworkState* active_network, |
| 70 bool* connection_type_changed, |
| 71 bool* ip_address_changed, |
| 72 bool* dns_changed); |
| 73 |
| 74 // Notify observers of NetworkChangeNotifier that the type of connection |
| 75 // changed. |
| 76 void ReportConnectionTypeChanged(); |
| 77 // Notify observers of NetworkChangeNotifier that the IP address changed. |
| 78 void ReportIPAddressChanged(); |
| 79 |
| 80 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 81 // IP address for the current active network. |
| 82 std::string ip_address_; |
| 83 // Service path for the current active network. |
| 84 std::string service_path_; |
| 85 |
| 86 scoped_ptr<DnsConfigServiceChromeos> dns_config_service_; |
| 87 |
| 88 FRIEND_TEST_ALL_PREFIXES(ConnectionChangeNotifierTest, |
| 89 ConnectionTypeFromShill); |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(ConnectionChangeNotifier); |
| 92 }; |
| 93 |
| 94 } // namespace chromeos |
| 95 |
| 96 #endif // CHROMEOS_CONNECTION_CHANGE_NOTIFIER_H_ |
OLD | NEW |