| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is a small utility that watches for and logs network changes. | 5 // This is a small utility that watches for and logs network changes. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 public net::NetworkChangeNotifier::DNSObserver, | 83 public net::NetworkChangeNotifier::DNSObserver, |
| 84 public net::NetworkChangeNotifier::NetworkChangeObserver, | 84 public net::NetworkChangeNotifier::NetworkChangeObserver, |
| 85 public net::ProxyConfigService::Observer { | 85 public net::ProxyConfigService::Observer { |
| 86 public: | 86 public: |
| 87 NetWatcher() {} | 87 NetWatcher() {} |
| 88 | 88 |
| 89 virtual ~NetWatcher() {} | 89 virtual ~NetWatcher() {} |
| 90 | 90 |
| 91 // net::NetworkChangeNotifier::IPAddressObserver implementation. | 91 // net::NetworkChangeNotifier::IPAddressObserver implementation. |
| 92 virtual void OnIPAddressChanged() OVERRIDE { | 92 virtual void OnIPAddressChanged() OVERRIDE { |
| 93 LOG(INFO) << "OnIPAddressChanged()"; | 93 VLOG(0) << "OnIPAddressChanged()"; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. | 96 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 97 virtual void OnConnectionTypeChanged( | 97 virtual void OnConnectionTypeChanged( |
| 98 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 98 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| 99 LOG(INFO) << "OnConnectionTypeChanged(" | 99 VLOG(0) << "OnConnectionTypeChanged(" |
| 100 << ConnectionTypeToString(type) << ")"; | 100 << ConnectionTypeToString(type) << ")"; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // net::NetworkChangeNotifier::DNSObserver implementation. | 103 // net::NetworkChangeNotifier::DNSObserver implementation. |
| 104 virtual void OnDNSChanged() OVERRIDE { | 104 virtual void OnDNSChanged() OVERRIDE { |
| 105 LOG(INFO) << "OnDNSChanged()"; | 105 VLOG(0) << "OnDNSChanged()"; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // net::NetworkChangeNotifier::NetworkChangeObserver implementation. | 108 // net::NetworkChangeNotifier::NetworkChangeObserver implementation. |
| 109 virtual void OnNetworkChanged( | 109 virtual void OnNetworkChanged( |
| 110 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 110 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| 111 LOG(INFO) << "OnNetworkChanged(" | 111 VLOG(0) << "OnNetworkChanged(" |
| 112 << ConnectionTypeToString(type) << ")"; | 112 << ConnectionTypeToString(type) << ")"; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // net::ProxyConfigService::Observer implementation. | 115 // net::ProxyConfigService::Observer implementation. |
| 116 virtual void OnProxyConfigChanged( | 116 virtual void OnProxyConfigChanged( |
| 117 const net::ProxyConfig& config, | 117 const net::ProxyConfig& config, |
| 118 net::ProxyConfigService::ConfigAvailability availability) OVERRIDE { | 118 net::ProxyConfigService::ConfigAvailability availability) OVERRIDE { |
| 119 LOG(INFO) << "OnProxyConfigChanged(" | 119 VLOG(0) << "OnProxyConfigChanged(" |
| 120 << ProxyConfigToString(config) << ", " | 120 << ProxyConfigToString(config) << ", " |
| 121 << ConfigAvailabilityToString(availability) << ")"; | 121 << ConfigAvailabilityToString(availability) << ")"; |
| 122 } | 122 } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(NetWatcher); | 125 DISALLOW_COPY_AND_ASSIGN(NetWatcher); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 | 129 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 network_loop.message_loop_proxy().get(), &network_loop)); | 161 network_loop.message_loop_proxy().get(), &network_loop)); |
| 162 | 162 |
| 163 // Uses |network_change_notifier|. | 163 // Uses |network_change_notifier|. |
| 164 net::NetworkChangeNotifier::AddIPAddressObserver(&net_watcher); | 164 net::NetworkChangeNotifier::AddIPAddressObserver(&net_watcher); |
| 165 net::NetworkChangeNotifier::AddConnectionTypeObserver(&net_watcher); | 165 net::NetworkChangeNotifier::AddConnectionTypeObserver(&net_watcher); |
| 166 net::NetworkChangeNotifier::AddDNSObserver(&net_watcher); | 166 net::NetworkChangeNotifier::AddDNSObserver(&net_watcher); |
| 167 net::NetworkChangeNotifier::AddNetworkChangeObserver(&net_watcher); | 167 net::NetworkChangeNotifier::AddNetworkChangeObserver(&net_watcher); |
| 168 | 168 |
| 169 proxy_config_service->AddObserver(&net_watcher); | 169 proxy_config_service->AddObserver(&net_watcher); |
| 170 | 170 |
| 171 LOG(INFO) << "Initial connection type: " | 171 VLOG(0) << "Initial connection type: " |
| 172 << ConnectionTypeToString( | 172 << ConnectionTypeToString( |
| 173 network_change_notifier->GetCurrentConnectionType()); | 173 network_change_notifier->GetCurrentConnectionType()); |
| 174 | 174 |
| 175 { | 175 { |
| 176 net::ProxyConfig config; | 176 net::ProxyConfig config; |
| 177 const net::ProxyConfigService::ConfigAvailability availability = | 177 const net::ProxyConfigService::ConfigAvailability availability = |
| 178 proxy_config_service->GetLatestProxyConfig(&config); | 178 proxy_config_service->GetLatestProxyConfig(&config); |
| 179 LOG(INFO) << "Initial proxy config: " | 179 VLOG(0) << "Initial proxy config: " |
| 180 << ProxyConfigToString(config) << ", " | 180 << ProxyConfigToString(config) << ", " |
| 181 << ConfigAvailabilityToString(availability); | 181 << ConfigAvailabilityToString(availability); |
| 182 } | 182 } |
| 183 | 183 |
| 184 LOG(INFO) << "Watching for network events..."; | 184 VLOG(0) << "Watching for network events..."; |
| 185 | 185 |
| 186 // Start watching for events. | 186 // Start watching for events. |
| 187 network_loop.Run(); | 187 network_loop.Run(); |
| 188 | 188 |
| 189 proxy_config_service->RemoveObserver(&net_watcher); | 189 proxy_config_service->RemoveObserver(&net_watcher); |
| 190 | 190 |
| 191 // Uses |network_change_notifier|. | 191 // Uses |network_change_notifier|. |
| 192 net::NetworkChangeNotifier::RemoveDNSObserver(&net_watcher); | 192 net::NetworkChangeNotifier::RemoveDNSObserver(&net_watcher); |
| 193 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(&net_watcher); | 193 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(&net_watcher); |
| 194 net::NetworkChangeNotifier::RemoveIPAddressObserver(&net_watcher); | 194 net::NetworkChangeNotifier::RemoveIPAddressObserver(&net_watcher); |
| 195 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(&net_watcher); | 195 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(&net_watcher); |
| 196 | 196 |
| 197 return 0; | 197 return 0; |
| 198 } | 198 } |
| OLD | NEW |