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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
20 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
21 #include "net/proxy/proxy_config_service.h" | 21 #include "net/proxy/proxy_config_service.h" |
22 #include "net/proxy/proxy_service.h" | 22 #include "net/proxy/proxy_service.h" |
23 | 23 |
24 #if defined(USE_GLIB) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined
(OS_CHROMEOS) | 24 #if defined(USE_GLIB) |
25 #include <glib-object.h> | 25 #include <glib-object.h> |
26 #endif | 26 #endif |
27 | 27 |
28 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
29 #include "base/mac/scoped_nsautorelease_pool.h" | 29 #include "base/mac/scoped_nsautorelease_pool.h" |
30 #endif | 30 #endif |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Conversions from various network-related types to string. | 34 // Conversions from various network-related types to string. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
130 int main(int argc, char* argv[]) { | 130 int main(int argc, char* argv[]) { |
131 #if defined(OS_MACOSX) | 131 #if defined(OS_MACOSX) |
132 base::mac::ScopedNSAutoreleasePool pool; | 132 base::mac::ScopedNSAutoreleasePool pool; |
133 #endif | 133 #endif |
134 #if defined(USE_GLIB) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined
(OS_CHROMEOS) | 134 #if defined(USE_GLIB) |
135 // g_type_init will be deprecated in 2.36. 2.35 is the development | 135 // g_type_init will be deprecated in 2.36. 2.35 is the development |
136 // version for 2.36, hence do not call g_type_init starting 2.35. | 136 // version for 2.36, hence do not call g_type_init starting 2.35. |
137 // http://developer.gnome.org/gobject/unstable/gobject-Type-Information.html#g
-type-init | 137 // http://developer.gnome.org/gobject/unstable/gobject-Type-Information.html#g
-type-init |
138 #if !GLIB_CHECK_VERSION(2, 35, 0) | 138 #if !GLIB_CHECK_VERSION(2, 35, 0) |
139 // Needed so ProxyConfigServiceLinux can use gconf. | 139 // Needed so ProxyConfigServiceLinux can use gconf. |
140 // Normally handled by BrowserMainLoop::InitializeToolkit(). | 140 // Normally handled by BrowserMainLoop::InitializeToolkit(). |
141 g_type_init(); | 141 g_type_init(); |
142 #endif | 142 #endif |
143 #endif // defined(USE_GLIB) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && !
defined(OS_CHROMEOS) | 143 #endif // defined(USE_GLIB) |
144 base::AtExitManager exit_manager; | 144 base::AtExitManager exit_manager; |
145 CommandLine::Init(argc, argv); | 145 base::CommandLine::Init(argc, argv); |
146 logging::LoggingSettings settings; | 146 logging::LoggingSettings settings; |
147 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 147 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
148 logging::InitLogging(settings); | 148 logging::InitLogging(settings); |
149 | 149 |
150 // Just make the main message loop the network loop. | 150 // Just make the main message loop the network loop. |
151 base::MessageLoopForIO network_loop; | 151 base::MessageLoopForIO network_loop; |
152 | 152 |
153 NetWatcher net_watcher; | 153 NetWatcher net_watcher; |
154 | 154 |
155 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | 155 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |