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

Side by Side Diff: webrtc/base/network.cc

Issue 1920043002: Replace scoped_ptr with unique_ptr in webrtc/base/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixes for compile errors. Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 14 matching lines...) Expand all
25 #if defined(WEBRTC_WIN) 25 #if defined(WEBRTC_WIN)
26 #include "webrtc/base/win32.h" 26 #include "webrtc/base/win32.h"
27 #include <Iphlpapi.h> 27 #include <Iphlpapi.h>
28 #elif !defined(__native_client__) 28 #elif !defined(__native_client__)
29 #include "webrtc/base/ifaddrs_converter.h" 29 #include "webrtc/base/ifaddrs_converter.h"
30 #endif 30 #endif
31 31
32 #include <stdio.h> 32 #include <stdio.h>
33 33
34 #include <algorithm> 34 #include <algorithm>
35 #include <memory>
35 36
36 #include "webrtc/base/logging.h" 37 #include "webrtc/base/logging.h"
37 #include "webrtc/base/networkmonitor.h" 38 #include "webrtc/base/networkmonitor.h"
38 #include "webrtc/base/scoped_ptr.h"
39 #include "webrtc/base/socket.h" // includes something that makes windows happy 39 #include "webrtc/base/socket.h" // includes something that makes windows happy
40 #include "webrtc/base/stream.h" 40 #include "webrtc/base/stream.h"
41 #include "webrtc/base/stringencode.h" 41 #include "webrtc/base/stringencode.h"
42 #include "webrtc/base/thread.h" 42 #include "webrtc/base/thread.h"
43 43
44 namespace rtc { 44 namespace rtc {
45 namespace { 45 namespace {
46 46
47 // Turning on IPv6 could make many IPv6 interfaces available for connectivity 47 // Turning on IPv6 could make many IPv6 interfaces available for connectivity
48 // check and delay the call setup time. kMaxIPv6Networks is the default upper 48 // check and delay the call setup time. kMaxIPv6Networks is the default upper
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } else if (network_monitor_) { 464 } else if (network_monitor_) {
465 adapter_type = network_monitor_->GetAdapterType(cursor->ifa_name); 465 adapter_type = network_monitor_->GetAdapterType(cursor->ifa_name);
466 } 466 }
467 #if defined(WEBRTC_IOS) 467 #if defined(WEBRTC_IOS)
468 // Cell networks are pdp_ipN on iOS. 468 // Cell networks are pdp_ipN on iOS.
469 if (strncmp(cursor->ifa_name, "pdp_ip", 6) == 0) { 469 if (strncmp(cursor->ifa_name, "pdp_ip", 6) == 0) {
470 adapter_type = ADAPTER_TYPE_CELLULAR; 470 adapter_type = ADAPTER_TYPE_CELLULAR;
471 } 471 }
472 #endif 472 #endif
473 // TODO(phoglund): Need to recognize other types as well. 473 // TODO(phoglund): Need to recognize other types as well.
474 scoped_ptr<Network> network(new Network(cursor->ifa_name, 474 std::unique_ptr<Network> network(new Network(cursor->ifa_name,
475 cursor->ifa_name, prefix, 475 cursor->ifa_name,
476 prefix_length, adapter_type)); 476 prefix,
477 prefix_length,
478 adapter_type));
477 network->set_default_local_address_provider(this); 479 network->set_default_local_address_provider(this);
478 network->set_scope_id(scope_id); 480 network->set_scope_id(scope_id);
479 network->AddIP(ip); 481 network->AddIP(ip);
480 network->set_ignored(IsIgnoredNetwork(*network)); 482 network->set_ignored(IsIgnoredNetwork(*network));
481 if (include_ignored || !network->ignored()) { 483 if (include_ignored || !network->ignored()) {
482 current_networks[key] = network.get(); 484 current_networks[key] = network.get();
483 networks->push_back(network.release()); 485 networks->push_back(network.release());
484 } 486 }
485 } else { 487 } else {
486 (*existing_network).second->AddIP(ip); 488 (*existing_network).second->AddIP(ip);
487 } 489 }
488 } 490 }
489 } 491 }
490 492
491 bool BasicNetworkManager::CreateNetworks(bool include_ignored, 493 bool BasicNetworkManager::CreateNetworks(bool include_ignored,
492 NetworkList* networks) const { 494 NetworkList* networks) const {
493 struct ifaddrs* interfaces; 495 struct ifaddrs* interfaces;
494 int error = getifaddrs(&interfaces); 496 int error = getifaddrs(&interfaces);
495 if (error != 0) { 497 if (error != 0) {
496 LOG_ERR(LERROR) << "getifaddrs failed to gather interface data: " << error; 498 LOG_ERR(LERROR) << "getifaddrs failed to gather interface data: " << error;
497 return false; 499 return false;
498 } 500 }
499 501
500 rtc::scoped_ptr<IfAddrsConverter> ifaddrs_converter(CreateIfAddrsConverter()); 502 std::unique_ptr<IfAddrsConverter> ifaddrs_converter(CreateIfAddrsConverter());
501 ConvertIfAddrs(interfaces, ifaddrs_converter.get(), include_ignored, 503 ConvertIfAddrs(interfaces, ifaddrs_converter.get(), include_ignored,
502 networks); 504 networks);
503 505
504 freeifaddrs(interfaces); 506 freeifaddrs(interfaces);
505 return true; 507 return true;
506 } 508 }
507 509
508 #elif defined(WEBRTC_WIN) 510 #elif defined(WEBRTC_WIN)
509 511
510 unsigned int GetPrefix(PIP_ADAPTER_PREFIX prefixlist, 512 unsigned int GetPrefix(PIP_ADAPTER_PREFIX prefixlist,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 548 }
547 *prefix = best_prefix; 549 *prefix = best_prefix;
548 return best_length; 550 return best_length;
549 } 551 }
550 552
551 bool BasicNetworkManager::CreateNetworks(bool include_ignored, 553 bool BasicNetworkManager::CreateNetworks(bool include_ignored,
552 NetworkList* networks) const { 554 NetworkList* networks) const {
553 NetworkMap current_networks; 555 NetworkMap current_networks;
554 // MSDN recommends a 15KB buffer for the first try at GetAdaptersAddresses. 556 // MSDN recommends a 15KB buffer for the first try at GetAdaptersAddresses.
555 size_t buffer_size = 16384; 557 size_t buffer_size = 16384;
556 scoped_ptr<char[]> adapter_info(new char[buffer_size]); 558 std::unique_ptr<char[]> adapter_info(new char[buffer_size]);
557 PIP_ADAPTER_ADDRESSES adapter_addrs = 559 PIP_ADAPTER_ADDRESSES adapter_addrs =
558 reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get()); 560 reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get());
559 int adapter_flags = (GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_ANYCAST | 561 int adapter_flags = (GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_ANYCAST |
560 GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_INCLUDE_PREFIX); 562 GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_INCLUDE_PREFIX);
561 int ret = 0; 563 int ret = 0;
562 do { 564 do {
563 adapter_info.reset(new char[buffer_size]); 565 adapter_info.reset(new char[buffer_size]);
564 adapter_addrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get()); 566 adapter_addrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(adapter_info.get());
565 ret = GetAdaptersAddresses(AF_UNSPEC, adapter_flags, 567 ret = GetAdaptersAddresses(AF_UNSPEC, adapter_flags,
566 0, adapter_addrs, 568 0, adapter_addrs,
(...skipping 15 matching lines...) Expand all
582 #endif 584 #endif
583 description = ToUtf8(adapter_addrs->Description, 585 description = ToUtf8(adapter_addrs->Description,
584 wcslen(adapter_addrs->Description)); 586 wcslen(adapter_addrs->Description));
585 for (; address; address = address->Next) { 587 for (; address; address = address->Next) {
586 #if defined(NDEBUG) 588 #if defined(NDEBUG)
587 name = rtc::ToString(count); 589 name = rtc::ToString(count);
588 #endif 590 #endif
589 591
590 IPAddress ip; 592 IPAddress ip;
591 int scope_id = 0; 593 int scope_id = 0;
592 scoped_ptr<Network> network; 594 std::unique_ptr<Network> network;
593 switch (address->Address.lpSockaddr->sa_family) { 595 switch (address->Address.lpSockaddr->sa_family) {
594 case AF_INET: { 596 case AF_INET: {
595 sockaddr_in* v4_addr = 597 sockaddr_in* v4_addr =
596 reinterpret_cast<sockaddr_in*>(address->Address.lpSockaddr); 598 reinterpret_cast<sockaddr_in*>(address->Address.lpSockaddr);
597 ip = IPAddress(v4_addr->sin_addr); 599 ip = IPAddress(v4_addr->sin_addr);
598 break; 600 break;
599 } 601 }
600 case AF_INET6: { 602 case AF_INET6: {
601 if (ipv6_enabled()) { 603 if (ipv6_enabled()) {
602 sockaddr_in6* v6_addr = 604 sockaddr_in6* v6_addr =
(...skipping 18 matching lines...) Expand all
621 IPAddress prefix; 623 IPAddress prefix;
622 int prefix_length = GetPrefix(prefixlist, ip, &prefix); 624 int prefix_length = GetPrefix(prefixlist, ip, &prefix);
623 std::string key = MakeNetworkKey(name, prefix, prefix_length); 625 std::string key = MakeNetworkKey(name, prefix, prefix_length);
624 auto existing_network = current_networks.find(key); 626 auto existing_network = current_networks.find(key);
625 if (existing_network == current_networks.end()) { 627 if (existing_network == current_networks.end()) {
626 AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN; 628 AdapterType adapter_type = ADAPTER_TYPE_UNKNOWN;
627 if (adapter_addrs->IfType == IF_TYPE_SOFTWARE_LOOPBACK) { 629 if (adapter_addrs->IfType == IF_TYPE_SOFTWARE_LOOPBACK) {
628 // TODO(phoglund): Need to recognize other types as well. 630 // TODO(phoglund): Need to recognize other types as well.
629 adapter_type = ADAPTER_TYPE_LOOPBACK; 631 adapter_type = ADAPTER_TYPE_LOOPBACK;
630 } 632 }
631 scoped_ptr<Network> network(new Network(name, description, prefix, 633 std::unique_ptr<Network> network(new Network(name, description,
632 prefix_length, adapter_type)); 634 prefix, prefix_length,
635 adapter_type));
633 network->set_default_local_address_provider(this); 636 network->set_default_local_address_provider(this);
634 network->set_scope_id(scope_id); 637 network->set_scope_id(scope_id);
635 network->AddIP(ip); 638 network->AddIP(ip);
636 bool ignored = IsIgnoredNetwork(*network); 639 bool ignored = IsIgnoredNetwork(*network);
637 network->set_ignored(ignored); 640 network->set_ignored(ignored);
638 if (include_ignored || !network->ignored()) { 641 if (include_ignored || !network->ignored()) {
639 current_networks[key] = network.get(); 642 current_networks[key] = network.get();
640 networks->push_back(network.release()); 643 networks->push_back(network.release());
641 } 644 }
642 } else { 645 } else {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 default: 788 default:
786 ASSERT(false); 789 ASSERT(false);
787 } 790 }
788 } 791 }
789 792
790 IPAddress BasicNetworkManager::QueryDefaultLocalAddress(int family) const { 793 IPAddress BasicNetworkManager::QueryDefaultLocalAddress(int family) const {
791 ASSERT(thread_ == Thread::Current()); 794 ASSERT(thread_ == Thread::Current());
792 ASSERT(thread_->socketserver() != nullptr); 795 ASSERT(thread_->socketserver() != nullptr);
793 ASSERT(family == AF_INET || family == AF_INET6); 796 ASSERT(family == AF_INET || family == AF_INET6);
794 797
795 scoped_ptr<AsyncSocket> socket( 798 std::unique_ptr<AsyncSocket> socket(
796 thread_->socketserver()->CreateAsyncSocket(family, SOCK_DGRAM)); 799 thread_->socketserver()->CreateAsyncSocket(family, SOCK_DGRAM));
797 if (!socket) { 800 if (!socket) {
798 LOG_ERR(LERROR) << "Socket creation failed"; 801 LOG_ERR(LERROR) << "Socket creation failed";
799 return IPAddress(); 802 return IPAddress();
800 } 803 }
801 804
802 if (socket->Connect(SocketAddress( 805 if (socket->Connect(SocketAddress(
803 family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host, kPublicPort)) < 806 family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host, kPublicPort)) <
804 0) { 807 0) {
805 LOG(LS_INFO) << "Connect failed with " << socket->GetError(); 808 LOG(LS_INFO) << "Connect failed with " << socket->GetError();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 std::stringstream ss; 941 std::stringstream ss;
939 // Print out the first space-terminated token of the network desc, plus 942 // Print out the first space-terminated token of the network desc, plus
940 // the IP address. 943 // the IP address.
941 ss << "Net[" << description_.substr(0, description_.find(' ')) 944 ss << "Net[" << description_.substr(0, description_.find(' '))
942 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ 945 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_
943 << ":" << AdapterTypeToString(type_) << "]"; 946 << ":" << AdapterTypeToString(type_) << "]";
944 return ss.str(); 947 return ss.str();
945 } 948 }
946 949
947 } // namespace rtc 950 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698