Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: net/base/address_tracker_linux.cc

Issue 1897033002: Reland 'Convert //net and //chromecast to std::unordered_*' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix TestDownloadRequestHandler Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/address_tracker_linux.h ('k') | net/base/address_tracker_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/address_tracker_linux.h" 5 #include "net/base/address_tracker_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <linux/if.h> 8 #include <linux/if.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <sys/ioctl.h> 10 #include <sys/ioctl.h>
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 connection_type_initialized_(false), 120 connection_type_initialized_(false),
121 connection_type_initialized_cv_(&connection_type_lock_), 121 connection_type_initialized_cv_(&connection_type_lock_),
122 current_connection_type_(NetworkChangeNotifier::CONNECTION_NONE), 122 current_connection_type_(NetworkChangeNotifier::CONNECTION_NONE),
123 tracking_(false), 123 tracking_(false),
124 threads_waiting_for_connection_type_initialization_(0) {} 124 threads_waiting_for_connection_type_initialization_(0) {}
125 125
126 AddressTrackerLinux::AddressTrackerLinux( 126 AddressTrackerLinux::AddressTrackerLinux(
127 const base::Closure& address_callback, 127 const base::Closure& address_callback,
128 const base::Closure& link_callback, 128 const base::Closure& link_callback,
129 const base::Closure& tunnel_callback, 129 const base::Closure& tunnel_callback,
130 const base::hash_set<std::string>& ignored_interfaces) 130 const std::unordered_set<std::string>& ignored_interfaces)
131 : get_interface_name_(GetInterfaceName), 131 : get_interface_name_(GetInterfaceName),
132 address_callback_(address_callback), 132 address_callback_(address_callback),
133 link_callback_(link_callback), 133 link_callback_(link_callback),
134 tunnel_callback_(tunnel_callback), 134 tunnel_callback_(tunnel_callback),
135 netlink_fd_(-1), 135 netlink_fd_(-1),
136 ignored_interfaces_(ignored_interfaces), 136 ignored_interfaces_(ignored_interfaces),
137 connection_type_initialized_(false), 137 connection_type_initialized_(false),
138 connection_type_initialized_cv_(&connection_type_lock_), 138 connection_type_initialized_cv_(&connection_type_lock_),
139 current_connection_type_(NetworkChangeNotifier::CONNECTION_NONE), 139 current_connection_type_(NetworkChangeNotifier::CONNECTION_NONE),
140 tracking_(true), 140 tracking_(true),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 current_connection_type_ = NetworkChangeNotifier::CONNECTION_UNKNOWN; 243 current_connection_type_ = NetworkChangeNotifier::CONNECTION_UNKNOWN;
244 connection_type_initialized_ = true; 244 connection_type_initialized_ = true;
245 connection_type_initialized_cv_.Broadcast(); 245 connection_type_initialized_cv_.Broadcast();
246 } 246 }
247 247
248 AddressTrackerLinux::AddressMap AddressTrackerLinux::GetAddressMap() const { 248 AddressTrackerLinux::AddressMap AddressTrackerLinux::GetAddressMap() const {
249 AddressTrackerAutoLock lock(*this, address_map_lock_); 249 AddressTrackerAutoLock lock(*this, address_map_lock_);
250 return address_map_; 250 return address_map_;
251 } 251 }
252 252
253 base::hash_set<int> AddressTrackerLinux::GetOnlineLinks() const { 253 std::unordered_set<int> AddressTrackerLinux::GetOnlineLinks() const {
254 AddressTrackerAutoLock lock(*this, online_links_lock_); 254 AddressTrackerAutoLock lock(*this, online_links_lock_);
255 return online_links_; 255 return online_links_;
256 } 256 }
257 257
258 bool AddressTrackerLinux::IsInterfaceIgnored(int interface_index) const { 258 bool AddressTrackerLinux::IsInterfaceIgnored(int interface_index) const {
259 if (ignored_interfaces_.empty()) 259 if (ignored_interfaces_.empty())
260 return false; 260 return false;
261 261
262 char buf[IFNAMSIZ] = {0}; 262 char buf[IFNAMSIZ] = {0};
263 const char* interface_name = get_interface_name_(interface_index, buf); 263 const char* interface_name = get_interface_name_(interface_index, buf);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 435 }
436 436
437 bool AddressTrackerLinux::IsTunnelInterface(int interface_index) const { 437 bool AddressTrackerLinux::IsTunnelInterface(int interface_index) const {
438 // Linux kernel drivers/net/tun.c uses "tun" name prefix. 438 // Linux kernel drivers/net/tun.c uses "tun" name prefix.
439 char buf[IFNAMSIZ] = {0}; 439 char buf[IFNAMSIZ] = {0};
440 return strncmp(get_interface_name_(interface_index, buf), "tun", 3) == 0; 440 return strncmp(get_interface_name_(interface_index, buf), "tun", 3) == 0;
441 } 441 }
442 442
443 void AddressTrackerLinux::UpdateCurrentConnectionType() { 443 void AddressTrackerLinux::UpdateCurrentConnectionType() {
444 AddressTrackerLinux::AddressMap address_map = GetAddressMap(); 444 AddressTrackerLinux::AddressMap address_map = GetAddressMap();
445 base::hash_set<int> online_links = GetOnlineLinks(); 445 std::unordered_set<int> online_links = GetOnlineLinks();
446 446
447 // Strip out tunnel interfaces from online_links 447 // Strip out tunnel interfaces from online_links
448 for (base::hash_set<int>::const_iterator it = online_links.begin(); 448 for (std::unordered_set<int>::const_iterator it = online_links.begin();
449 it != online_links.end();) { 449 it != online_links.end();) {
450 if (IsTunnelInterface(*it)) { 450 if (IsTunnelInterface(*it)) {
451 base::hash_set<int>::const_iterator tunnel_it = it; 451 std::unordered_set<int>::const_iterator tunnel_it = it;
452 ++it; 452 ++it;
453 online_links.erase(*tunnel_it); 453 online_links.erase(*tunnel_it);
454 } else { 454 } else {
455 ++it; 455 ++it;
456 } 456 }
457 } 457 }
458 458
459 NetworkInterfaceList networks; 459 NetworkInterfaceList networks;
460 NetworkChangeNotifier::ConnectionType type = 460 NetworkChangeNotifier::ConnectionType type =
461 NetworkChangeNotifier::CONNECTION_NONE; 461 NetworkChangeNotifier::CONNECTION_NONE;
(...skipping 28 matching lines...) Expand all
490 490
491 AddressTrackerLinux::AddressTrackerAutoLock::~AddressTrackerAutoLock() { 491 AddressTrackerLinux::AddressTrackerAutoLock::~AddressTrackerAutoLock() {
492 if (tracker_.tracking_) { 492 if (tracker_.tracking_) {
493 lock_.AssertAcquired(); 493 lock_.AssertAcquired();
494 lock_.Release(); 494 lock_.Release();
495 } 495 }
496 } 496 }
497 497
498 } // namespace internal 498 } // namespace internal
499 } // namespace net 499 } // namespace net
OLDNEW
« no previous file with comments | « net/base/address_tracker_linux.h ('k') | net/base/address_tracker_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698