Chromium Code Reviews| 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 #include "net/base/network_change_notifier_linux.h" | 5 #include "net/base/network_change_notifier_linux.h" |
| 6 | 6 |
| 7 #include <unordered_set> | |
|
mmenke
2016/04/06 21:02:22
nit: Already included in the header
davidben
2016/04/07 21:30:41
Done.
| |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 11 #include "net/base/address_tracker_linux.h" | 13 #include "net/base/address_tracker_linux.h" |
| 12 #include "net/dns/dns_config_service.h" | 14 #include "net/dns/dns_config_service.h" |
| 13 | 15 |
| 14 namespace net { | 16 namespace net { |
| 15 | 17 |
| 16 class NetworkChangeNotifierLinux::Thread : public base::Thread { | 18 class NetworkChangeNotifierLinux::Thread : public base::Thread { |
| 17 public: | 19 public: |
| 18 explicit Thread(const base::hash_set<std::string>& ignored_interfaces); | 20 explicit Thread(const std::unordered_set<std::string>& ignored_interfaces); |
| 19 ~Thread() override; | 21 ~Thread() override; |
| 20 | 22 |
| 21 // Plumbing for NetworkChangeNotifier::GetCurrentConnectionType. | 23 // Plumbing for NetworkChangeNotifier::GetCurrentConnectionType. |
| 22 // Safe to call from any thread. | 24 // Safe to call from any thread. |
| 23 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() { | 25 NetworkChangeNotifier::ConnectionType GetCurrentConnectionType() { |
| 24 return address_tracker_->GetCurrentConnectionType(); | 26 return address_tracker_->GetCurrentConnectionType(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 const internal::AddressTrackerLinux* address_tracker() const { | 29 const internal::AddressTrackerLinux* address_tracker() const { |
| 28 return address_tracker_.get(); | 30 return address_tracker_.get(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 protected: | 33 protected: |
| 32 // base::Thread | 34 // base::Thread |
| 33 void Init() override; | 35 void Init() override; |
| 34 void CleanUp() override; | 36 void CleanUp() override; |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 void OnIPAddressChanged(); | 39 void OnIPAddressChanged(); |
| 38 void OnLinkChanged(); | 40 void OnLinkChanged(); |
| 39 scoped_ptr<DnsConfigService> dns_config_service_; | 41 scoped_ptr<DnsConfigService> dns_config_service_; |
| 40 // Used to detect online/offline state and IP address changes. | 42 // Used to detect online/offline state and IP address changes. |
| 41 scoped_ptr<internal::AddressTrackerLinux> address_tracker_; | 43 scoped_ptr<internal::AddressTrackerLinux> address_tracker_; |
| 42 NetworkChangeNotifier::ConnectionType last_type_; | 44 NetworkChangeNotifier::ConnectionType last_type_; |
| 43 | 45 |
| 44 DISALLOW_COPY_AND_ASSIGN(Thread); | 46 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 NetworkChangeNotifierLinux::Thread::Thread( | 49 NetworkChangeNotifierLinux::Thread::Thread( |
| 48 const base::hash_set<std::string>& ignored_interfaces) | 50 const std::unordered_set<std::string>& ignored_interfaces) |
| 49 : base::Thread("NetworkChangeNotifier"), | 51 : base::Thread("NetworkChangeNotifier"), |
| 50 address_tracker_(new internal::AddressTrackerLinux( | 52 address_tracker_(new internal::AddressTrackerLinux( |
| 51 base::Bind(&NetworkChangeNotifierLinux::Thread::OnIPAddressChanged, | 53 base::Bind(&NetworkChangeNotifierLinux::Thread::OnIPAddressChanged, |
| 52 base::Unretained(this)), | 54 base::Unretained(this)), |
| 53 base::Bind(&NetworkChangeNotifierLinux::Thread::OnLinkChanged, | 55 base::Bind(&NetworkChangeNotifierLinux::Thread::OnLinkChanged, |
| 54 base::Unretained(this)), | 56 base::Unretained(this)), |
| 55 base::Bind(base::DoNothing), | 57 base::Bind(base::DoNothing), |
| 56 ignored_interfaces)), | 58 ignored_interfaces)), |
| 57 last_type_(NetworkChangeNotifier::CONNECTION_NONE) {} | 59 last_type_(NetworkChangeNotifier::CONNECTION_NONE) {} |
| 58 | 60 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 88 last_type_ = GetCurrentConnectionType(); | 90 last_type_ = GetCurrentConnectionType(); |
| 89 double max_bandwidth_mbps = | 91 double max_bandwidth_mbps = |
| 90 NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( | 92 NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( |
| 91 last_type_ == CONNECTION_NONE ? SUBTYPE_NONE : SUBTYPE_UNKNOWN); | 93 last_type_ == CONNECTION_NONE ? SUBTYPE_NONE : SUBTYPE_UNKNOWN); |
| 92 NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( | 94 NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( |
| 93 max_bandwidth_mbps, last_type_); | 95 max_bandwidth_mbps, last_type_); |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 | 98 |
| 97 NetworkChangeNotifierLinux::NetworkChangeNotifierLinux( | 99 NetworkChangeNotifierLinux::NetworkChangeNotifierLinux( |
| 98 const base::hash_set<std::string>& ignored_interfaces) | 100 const std::unordered_set<std::string>& ignored_interfaces) |
| 99 : NetworkChangeNotifier(NetworkChangeCalculatorParamsLinux()), | 101 : NetworkChangeNotifier(NetworkChangeCalculatorParamsLinux()), |
| 100 notifier_thread_(new Thread(ignored_interfaces)) { | 102 notifier_thread_(new Thread(ignored_interfaces)) { |
| 101 // We create this notifier thread because the notification implementation | 103 // We create this notifier thread because the notification implementation |
| 102 // needs a MessageLoopForIO, and there's no guarantee that | 104 // needs a MessageLoopForIO, and there's no guarantee that |
| 103 // MessageLoop::current() meets that criterion. | 105 // MessageLoop::current() meets that criterion. |
| 104 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 106 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 105 notifier_thread_->StartWithOptions(thread_options); | 107 notifier_thread_->StartWithOptions(thread_options); |
| 106 } | 108 } |
| 107 | 109 |
| 108 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { | 110 NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 129 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { | 131 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { |
| 130 return notifier_thread_->GetCurrentConnectionType(); | 132 return notifier_thread_->GetCurrentConnectionType(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 const internal::AddressTrackerLinux* | 135 const internal::AddressTrackerLinux* |
| 134 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { | 136 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { |
| 135 return notifier_thread_->address_tracker(); | 137 return notifier_thread_->address_tracker(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 } // namespace net | 140 } // namespace net |
| OLD | NEW |