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 "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 base::hash_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_; | 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 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 base::hash_set<std::string>& ignored_interfaces) |
| 49 : base::Thread("NetworkChangeNotifier"), | 49 : base::Thread("NetworkChangeNotifier"), |
| 50 address_tracker_( | 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 } |
| 59 | 59 |
| 60 NetworkChangeNotifierLinux::Thread::~Thread() { | 60 NetworkChangeNotifierLinux::Thread::~Thread() { |
| 61 DCHECK(!Thread::IsRunning()); | 61 DCHECK(!Thread::IsRunning()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void NetworkChangeNotifierLinux::Thread::Init() { | 64 void NetworkChangeNotifierLinux::Thread::Init() { |
| 65 address_tracker_.Init(); | 65 address_tracker_->Init(); |
| 66 dns_config_service_ = DnsConfigService::CreateSystemService(); | 66 dns_config_service_ = DnsConfigService::CreateSystemService(); |
| 67 dns_config_service_->WatchConfig( | 67 dns_config_service_->WatchConfig( |
| 68 base::Bind(&NetworkChangeNotifier::SetDnsConfig)); | 68 base::Bind(&NetworkChangeNotifier::SetDnsConfig)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void NetworkChangeNotifierLinux::Thread::CleanUp() { | 71 void NetworkChangeNotifierLinux::Thread::CleanUp() { |
| 72 address_tracker_.reset(); | |
|
pauljensen
2016/03/18 18:27:49
Can you add a comment like:
// Delete AddressTrack
| |
| 72 dns_config_service_.reset(); | 73 dns_config_service_.reset(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void NetworkChangeNotifierLinux::Thread::OnIPAddressChanged() { | 76 void NetworkChangeNotifierLinux::Thread::OnIPAddressChanged() { |
| 76 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 77 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 77 // When the IP address of a network interface is added/deleted, the | 78 // When the IP address of a network interface is added/deleted, the |
| 78 // connection type may have changed. | 79 // connection type may have changed. |
| 79 OnLinkChanged(); | 80 OnLinkChanged(); |
| 80 } | 81 } |
| 81 | 82 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { | 127 NetworkChangeNotifierLinux::GetCurrentConnectionType() const { |
| 127 return notifier_thread_->GetCurrentConnectionType(); | 128 return notifier_thread_->GetCurrentConnectionType(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 const internal::AddressTrackerLinux* | 131 const internal::AddressTrackerLinux* |
| 131 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { | 132 NetworkChangeNotifierLinux::GetAddressTrackerInternal() const { |
| 132 return notifier_thread_->address_tracker(); | 133 return notifier_thread_->address_tracker(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace net | 136 } // namespace net |
| OLD | NEW |