| 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 implementation of NetworkChangeNotifier's offline state detection | 5 // This implementation of NetworkChangeNotifier's offline state detection |
| 6 // depends on D-Bus and NetworkManager, and is known to work on at least | 6 // depends on D-Bus and NetworkManager, and is known to work on at least |
| 7 // GNOME version 2.30. If D-Bus or NetworkManager are unavailable, this | 7 // GNOME version 2.30. If D-Bus or NetworkManager are unavailable, this |
| 8 // implementation will always behave as if it is online. | 8 // implementation will always behave as if it is online. |
| 9 | 9 |
| 10 #include "net/base/network_change_notifier_linux.h" | 10 #include "net/base/network_change_notifier_linux.h" |
| 11 | 11 |
| 12 #include <resolv.h> | 12 #include <resolv.h> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 21 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 24 #include "dbus/bus.h" | 24 #include "dbus/bus.h" |
| 25 #include "dbus/message.h" | 25 #include "dbus/message.h" |
| 26 #include "dbus/object_proxy.h" | 26 #include "dbus/object_proxy.h" |
| 27 #include "net/base/address_tracker_linux.h" | 27 #include "net/base/address_tracker_linux.h" |
| 28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 29 #include "net/dns/dns_config_watcher.h" | 29 #include "net/dns/dns_config_service.h" |
| 30 | 30 |
| 31 namespace net { | 31 namespace net { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kNetworkManagerServiceName[] = "org.freedesktop.NetworkManager"; | 35 const char kNetworkManagerServiceName[] = "org.freedesktop.NetworkManager"; |
| 36 const char kNetworkManagerPath[] = "/org/freedesktop/NetworkManager"; | 36 const char kNetworkManagerPath[] = "/org/freedesktop/NetworkManager"; |
| 37 const char kNetworkManagerInterface[] = "org.freedesktop.NetworkManager"; | 37 const char kNetworkManagerInterface[] = "org.freedesktop.NetworkManager"; |
| 38 | 38 |
| 39 // http://projects.gnome.org/NetworkManager/developers/spec-08.html#type-NM_STAT
E | 39 // http://projects.gnome.org/NetworkManager/developers/spec-08.html#type-NM_STAT
E |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 protected: | 256 protected: |
| 257 // base::Thread | 257 // base::Thread |
| 258 virtual void Init() OVERRIDE; | 258 virtual void Init() OVERRIDE; |
| 259 virtual void CleanUp() OVERRIDE; | 259 virtual void CleanUp() OVERRIDE; |
| 260 | 260 |
| 261 private: | 261 private: |
| 262 // Used to detect online/offline state changes. | 262 // Used to detect online/offline state changes. |
| 263 NetworkManagerApi network_manager_api_; | 263 NetworkManagerApi network_manager_api_; |
| 264 | 264 |
| 265 internal::DnsConfigWatcher dns_watcher_; | 265 scoped_ptr<DnsConfigService> dns_config_service_; |
| 266 internal::AddressTrackerLinux address_tracker_; | 266 internal::AddressTrackerLinux address_tracker_; |
| 267 | 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(Thread); | 268 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 NetworkChangeNotifierLinux::Thread::Thread(dbus::Bus* bus) | 271 NetworkChangeNotifierLinux::Thread::Thread(dbus::Bus* bus) |
| 272 : base::Thread("NetworkChangeNotifier"), | 272 : base::Thread("NetworkChangeNotifier"), |
| 273 network_manager_api_( | 273 network_manager_api_( |
| 274 base::Bind(&NetworkChangeNotifier:: | 274 base::Bind(&NetworkChangeNotifier:: |
| 275 NotifyObserversOfConnectionTypeChange), | 275 NotifyObserversOfConnectionTypeChange), |
| 276 bus), | 276 bus), |
| 277 address_tracker_( | 277 address_tracker_( |
| 278 base::Bind(&NetworkChangeNotifier:: | 278 base::Bind(&NetworkChangeNotifier:: |
| 279 NotifyObserversOfIPAddressChange)) { | 279 NotifyObserversOfIPAddressChange)) { |
| 280 } | 280 } |
| 281 | 281 |
| 282 NetworkChangeNotifierLinux::Thread::~Thread() { | 282 NetworkChangeNotifierLinux::Thread::~Thread() { |
| 283 DCHECK(!Thread::IsRunning()); | 283 DCHECK(!Thread::IsRunning()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void NetworkChangeNotifierLinux::Thread::Init() { | 286 void NetworkChangeNotifierLinux::Thread::Init() { |
| 287 network_manager_api_.Init(); | 287 network_manager_api_.Init(); |
| 288 dns_watcher_.Init(); | 288 dns_config_service_ = DnsConfigService::CreateSystemService(); |
| 289 dns_config_service_->WatchConfig( |
| 290 base::Bind(&NetworkChangeNotifier::SetDnsConfig)); |
| 289 address_tracker_.Init(); | 291 address_tracker_.Init(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 void NetworkChangeNotifierLinux::Thread::CleanUp() { | 294 void NetworkChangeNotifierLinux::Thread::CleanUp() { |
| 293 network_manager_api_.CleanUp(); | 295 network_manager_api_.CleanUp(); |
| 294 dns_watcher_.CleanUp(); | 296 dns_config_service_.reset(); |
| 295 } | 297 } |
| 296 | 298 |
| 297 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::Create() { | 299 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::Create() { |
| 298 return new NetworkChangeNotifierLinux(NULL); | 300 return new NetworkChangeNotifierLinux(NULL); |
| 299 } | 301 } |
| 300 | 302 |
| 301 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::CreateForTest( | 303 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::CreateForTest( |
| 302 dbus::Bus* bus) { | 304 dbus::Bus* bus) { |
| 303 return new NetworkChangeNotifierLinux(bus); | 305 return new NetworkChangeNotifierLinux(bus); |
| 304 } | 306 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 322 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { | 324 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { |
| 323 return notifier_thread_->GetCurrentConnectionType(); | 325 return notifier_thread_->GetCurrentConnectionType(); |
| 324 } | 326 } |
| 325 | 327 |
| 326 const internal::AddressTrackerLinux* | 328 const internal::AddressTrackerLinux* |
| 327 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { | 329 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { |
| 328 return notifier_thread_->address_tracker(); | 330 return notifier_thread_->address_tracker(); |
| 329 } | 331 } |
| 330 | 332 |
| 331 } // namespace net | 333 } // namespace net |
| OLD | NEW |