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 // It prints out the current network connection type and proxy configuration | 6 // It prints out the current network connection type and proxy configuration |
7 // upon startup and then prints out changes as they happen. | 7 // upon startup and then prints out changes as they happen. |
8 // It's useful for testing NetworkChangeNotifier and ProxyConfigService. | 8 // It's useful for testing NetworkChangeNotifier and ProxyConfigService. |
9 // The only command line option supported is --ignore-netif which is followed | 9 // The only command line option supported is --ignore-netif which is followed |
10 // by a comma seperated list of network interfaces to ignore when computing | 10 // by a comma seperated list of network interfaces to ignore when computing |
11 // connection type; this option is only supported on linux. | 11 // connection type; this option is only supported on linux. |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <string> | 14 #include <string> |
15 #include <unordered_set> | 15 #include <unordered_set> |
16 | 16 |
17 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
20 #include "base/json/json_writer.h" | 20 #include "base/json/json_writer.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/macros.h" | 22 #include "base/macros.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "base/run_loop.h" |
24 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
25 #include "base/values.h" | 26 #include "base/values.h" |
26 #include "build/build_config.h" | 27 #include "build/build_config.h" |
27 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
28 #include "net/proxy/proxy_config.h" | 29 #include "net/proxy/proxy_config.h" |
29 #include "net/proxy/proxy_config_service.h" | 30 #include "net/proxy/proxy_config_service.h" |
30 #include "net/proxy/proxy_service.h" | 31 #include "net/proxy/proxy_service.h" |
31 | 32 |
32 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 33 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
33 #include "net/base/network_change_notifier_linux.h" | 34 #include "net/base/network_change_notifier_linux.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const net::ProxyConfigService::ConfigAvailability availability = | 200 const net::ProxyConfigService::ConfigAvailability availability = |
200 proxy_config_service->GetLatestProxyConfig(&config); | 201 proxy_config_service->GetLatestProxyConfig(&config); |
201 LOG(INFO) << "Initial proxy config: " | 202 LOG(INFO) << "Initial proxy config: " |
202 << ProxyConfigToString(config) << ", " | 203 << ProxyConfigToString(config) << ", " |
203 << ConfigAvailabilityToString(availability); | 204 << ConfigAvailabilityToString(availability); |
204 } | 205 } |
205 | 206 |
206 LOG(INFO) << "Watching for network events..."; | 207 LOG(INFO) << "Watching for network events..."; |
207 | 208 |
208 // Start watching for events. | 209 // Start watching for events. |
209 network_loop.Run(); | 210 base::RunLoop().Run(); |
210 | 211 |
211 proxy_config_service->RemoveObserver(&net_watcher); | 212 proxy_config_service->RemoveObserver(&net_watcher); |
212 | 213 |
213 // Uses |network_change_notifier|. | 214 // Uses |network_change_notifier|. |
214 net::NetworkChangeNotifier::RemoveDNSObserver(&net_watcher); | 215 net::NetworkChangeNotifier::RemoveDNSObserver(&net_watcher); |
215 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(&net_watcher); | 216 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(&net_watcher); |
216 net::NetworkChangeNotifier::RemoveIPAddressObserver(&net_watcher); | 217 net::NetworkChangeNotifier::RemoveIPAddressObserver(&net_watcher); |
217 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(&net_watcher); | 218 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(&net_watcher); |
218 | 219 |
219 return 0; | 220 return 0; |
220 } | 221 } |
OLD | NEW |