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

Side by Side Diff: net/dns/dns_config_service_win.cc

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 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 // 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/dns/dns_config_service_win.h" 5 #include "net/dns/dns_config_service_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 rv = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, out.get(), &len); 127 rv = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, out.get(), &len);
128 } 128 }
129 if (rv != NO_ERROR) 129 if (rv != NO_ERROR)
130 out.reset(); 130 out.reset();
131 return out.Pass(); 131 return out.Pass();
132 } 132 }
133 133
134 // Converts a base::string16 domain name to ASCII, possibly using punycode. 134 // Converts a base::string16 domain name to ASCII, possibly using punycode.
135 // Returns true if the conversion succeeds and output is not empty. In case of 135 // Returns true if the conversion succeeds and output is not empty. In case of
136 // failure, |domain| might become dirty. 136 // failure, |domain| might become dirty.
137 bool ParseDomainASCII(const base::string16& widestr, std::string* domain) { 137 bool ParseDomainASCII(base::StringPiece16 widestr, std::string* domain) {
138 DCHECK(domain); 138 DCHECK(domain);
139 if (widestr.empty()) 139 if (widestr.empty())
140 return false; 140 return false;
141 141
142 // Check if already ASCII. 142 // Check if already ASCII.
143 if (base::IsStringASCII(widestr)) { 143 if (base::IsStringASCII(widestr)) {
144 *domain = base::UTF16ToASCII(widestr); 144 domain->assign(widestr.begin(), widestr.end());
145 return true; 145 return true;
146 } 146 }
147 147
148 // Otherwise try to convert it from IDN to punycode. 148 // Otherwise try to convert it from IDN to punycode.
149 const int kInitialBufferSize = 256; 149 const int kInitialBufferSize = 256;
150 url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode; 150 url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode;
151 if (!url::IDNToASCII(widestr.data(), widestr.length(), &punycode)) 151 if (!url::IDNToASCII(widestr.data(), widestr.length(), &punycode))
152 return false; 152 return false;
153 153
154 // |punycode_output| should now be ASCII; convert it to a std::string. 154 // |punycode_output| should now be ASCII; convert it to a std::string.
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 DCHECK(output); 469 DCHECK(output);
470 if (value.empty()) 470 if (value.empty())
471 return false; 471 return false;
472 472
473 output->clear(); 473 output->clear();
474 474
475 // If the list includes an empty hostname (",," or ", ,"), it is terminated. 475 // If the list includes an empty hostname (",," or ", ,"), it is terminated.
476 // Although nslookup and network connection property tab ignore such 476 // Although nslookup and network connection property tab ignore such
477 // fragments ("a,b,,c" becomes ["a", "b", "c"]), our reference is getaddrinfo 477 // fragments ("a,b,,c" becomes ["a", "b", "c"]), our reference is getaddrinfo
478 // (which sees ["a", "b"]). WMI queries also return a matching search list. 478 // (which sees ["a", "b"]). WMI queries also return a matching search list.
479 std::vector<base::string16> woutput; 479 for (const base::StringPiece16& t : base::SplitStringPiece(
480 base::SplitString(value, ',', &woutput); 480 value, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
Ryan Sleevi 2015/07/06 08:52:02 CONSISTENCY PEDANTRY NIT: Elsewhere, you use base:
brettw 2015/07/06 16:52:34 This is pretty common in Windows files, at least i
481 for (size_t i = 0; i < woutput.size(); ++i) {
482 // Convert non-ASCII to punycode, although getaddrinfo does not properly 481 // Convert non-ASCII to punycode, although getaddrinfo does not properly
483 // handle such suffixes. 482 // handle such suffixes.
484 const base::string16& t = woutput[i];
485 std::string parsed; 483 std::string parsed;
486 if (!ParseDomainASCII(t, &parsed)) 484 if (!ParseDomainASCII(t, &parsed))
487 break; 485 break;
488 output->push_back(parsed); 486 output->push_back(parsed);
489 } 487 }
490 return !output->empty(); 488 return !output->empty();
491 } 489 }
492 490
493 ConfigParseWinResult ConvertSettingsToDnsConfig( 491 ConfigParseWinResult ConvertSettingsToDnsConfig(
494 const DnsSystemSettings& settings, 492 const DnsSystemSettings& settings,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } 777 }
780 778
781 } // namespace internal 779 } // namespace internal
782 780
783 // static 781 // static
784 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { 782 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() {
785 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServiceWin()); 783 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServiceWin());
786 } 784 }
787 785
788 } // namespace net 786 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698