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