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" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::Create() { | 299 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::Create() { |
300 return new NetworkChangeNotifierLinux(NULL); | 300 return new NetworkChangeNotifierLinux(NULL); |
301 } | 301 } |
302 | 302 |
303 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::CreateForTest( | 303 NetworkChangeNotifierLinux* NetworkChangeNotifierLinux::CreateForTest( |
304 dbus::Bus* bus) { | 304 dbus::Bus* bus) { |
305 return new NetworkChangeNotifierLinux(bus); | 305 return new NetworkChangeNotifierLinux(bus); |
306 } | 306 } |
307 | 307 |
308 NetworkChangeNotifierLinux::NetworkChangeNotifierLinux(dbus::Bus* bus) | 308 NetworkChangeNotifierLinux::NetworkChangeNotifierLinux(dbus::Bus* bus) |
309 : notifier_thread_(new Thread(bus)) { | 309 : NetworkChangeNotifier(NetworkChangeCalculatorParamsLinux()), |
| 310 notifier_thread_(new Thread(bus)) { |
310 // We create this notifier thread because the notification implementation | 311 // We create this notifier thread because the notification implementation |
311 // needs a MessageLoopForIO, and there's no guarantee that | 312 // needs a MessageLoopForIO, and there's no guarantee that |
312 // MessageLoop::current() meets that criterion. | 313 // MessageLoop::current() meets that criterion. |
313 base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0); | 314 base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0); |
314 notifier_thread_->StartWithOptions(thread_options); | 315 notifier_thread_->StartWithOptions(thread_options); |
315 } | 316 } |
316 | 317 |
317 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { | 318 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { |
318 // Stopping from here allows us to sanity- check that the notifier | 319 // Stopping from here allows us to sanity- check that the notifier |
319 // thread shut down properly. | 320 // thread shut down properly. |
320 notifier_thread_->Stop(); | 321 notifier_thread_->Stop(); |
321 } | 322 } |
322 | 323 |
| 324 // static |
| 325 NetworkChangeNotifier::NetworkChangeCalculatorParams |
| 326 NetworkChangeNotifierLinux::NetworkChangeCalculatorParamsLinux() { |
| 327 NetworkChangeCalculatorParams params; |
| 328 // Delay values arrived at by simple experimentation and adjusted so as to |
| 329 // produce a single signal when switching between network connections. |
| 330 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(1500); |
| 331 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 332 params.connection_type_offline_delay_ = |
| 333 base::TimeDelta::FromMilliseconds(1500); |
| 334 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 335 return params; |
| 336 } |
| 337 |
323 NetworkChangeNotifier::ConnectionType | 338 NetworkChangeNotifier::ConnectionType |
324 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { | 339 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { |
325 return notifier_thread_->GetCurrentConnectionType(); | 340 return notifier_thread_->GetCurrentConnectionType(); |
326 } | 341 } |
327 | 342 |
328 const internal::AddressTrackerLinux* | 343 const internal::AddressTrackerLinux* |
329 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { | 344 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { |
330 return notifier_thread_->address_tracker(); | 345 return notifier_thread_->address_tracker(); |
331 } | 346 } |
332 | 347 |
333 } // namespace net | 348 } // namespace net |
OLD | NEW |