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

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

Issue 169193002: Convert scoped_ptr_malloc -> scoped_ptr, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/dns_config_service_win.h ('k') | net/dns/dns_config_service_win_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/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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return (result == ERROR_FILE_NOT_FOUND); 106 return (result == ERROR_FILE_NOT_FOUND);
107 } 107 }
108 108
109 private: 109 private:
110 base::win::RegKey key_; 110 base::win::RegKey key_;
111 111
112 DISALLOW_COPY_AND_ASSIGN(RegistryReader); 112 DISALLOW_COPY_AND_ASSIGN(RegistryReader);
113 }; 113 };
114 114
115 // Wrapper for GetAdaptersAddresses. Returns NULL if failed. 115 // Wrapper for GetAdaptersAddresses. Returns NULL if failed.
116 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> ReadIpHelper(ULONG flags) { 116 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> ReadIpHelper(ULONG flags) {
117 base::ThreadRestrictions::AssertIOAllowed(); 117 base::ThreadRestrictions::AssertIOAllowed();
118 118
119 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> out; 119 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> out;
120 ULONG len = 15000; // As recommended by MSDN for GetAdaptersAddresses. 120 ULONG len = 15000; // As recommended by MSDN for GetAdaptersAddresses.
121 UINT rv = ERROR_BUFFER_OVERFLOW; 121 UINT rv = ERROR_BUFFER_OVERFLOW;
122 // Try up to three times. 122 // Try up to three times.
123 for (unsigned tries = 0; (tries < 3) && (rv == ERROR_BUFFER_OVERFLOW); 123 for (unsigned tries = 0; (tries < 3) && (rv == ERROR_BUFFER_OVERFLOW);
124 tries++) { 124 tries++) {
125 out.reset(reinterpret_cast<PIP_ADAPTER_ADDRESSES>(malloc(len))); 125 out.reset(static_cast<PIP_ADAPTER_ADDRESSES>(malloc(len)));
126 rv = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, out.get(), &len); 126 rv = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, out.get(), &len);
127 } 127 }
128 if (rv != NO_ERROR) 128 if (rv != NO_ERROR)
129 out.reset(); 129 out.reset();
130 return out.Pass(); 130 return out.Pass();
131 } 131 }
132 132
133 // Converts a base::string16 domain name to ASCII, possibly using punycode. 133 // Converts a base::string16 domain name to ASCII, possibly using punycode.
134 // Returns true if the conversion succeeds and output is not empty. In case of 134 // Returns true if the conversion succeeds and output is not empty. In case of
135 // failure, |domain| might become dirty. 135 // failure, |domain| might become dirty.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 StringToLowerASCII(&localname); 243 StringToLowerASCII(&localname);
244 244
245 bool have_ipv4 = 245 bool have_ipv4 =
246 hosts->count(DnsHostsKey(localname, ADDRESS_FAMILY_IPV4)) > 0; 246 hosts->count(DnsHostsKey(localname, ADDRESS_FAMILY_IPV4)) > 0;
247 bool have_ipv6 = 247 bool have_ipv6 =
248 hosts->count(DnsHostsKey(localname, ADDRESS_FAMILY_IPV6)) > 0; 248 hosts->count(DnsHostsKey(localname, ADDRESS_FAMILY_IPV6)) > 0;
249 249
250 if (have_ipv4 && have_ipv6) 250 if (have_ipv4 && have_ipv6)
251 return HOSTS_PARSE_WIN_OK; 251 return HOSTS_PARSE_WIN_OK;
252 252
253 scoped_ptr_malloc<IP_ADAPTER_ADDRESSES> addresses = 253 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> addresses =
254 ReadIpHelper(GAA_FLAG_SKIP_ANYCAST | 254 ReadIpHelper(GAA_FLAG_SKIP_ANYCAST |
255 GAA_FLAG_SKIP_DNS_SERVER | 255 GAA_FLAG_SKIP_DNS_SERVER |
256 GAA_FLAG_SKIP_MULTICAST | 256 GAA_FLAG_SKIP_MULTICAST |
257 GAA_FLAG_SKIP_FRIENDLY_NAME); 257 GAA_FLAG_SKIP_FRIENDLY_NAME);
258 if (!addresses.get()) 258 if (!addresses.get())
259 return HOSTS_PARSE_WIN_IPHELPER_FAILED; 259 return HOSTS_PARSE_WIN_IPHELPER_FAILED;
260 260
261 // The order of adapters is the network binding order, so stick to the 261 // The order of adapters is the network binding order, so stick to the
262 // first good adapter for each family. 262 // first good adapter for each family.
263 for (const IP_ADAPTER_ADDRESSES* adapter = addresses.get(); 263 for (const IP_ADAPTER_ADDRESSES* adapter = addresses.get();
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 758 }
759 759
760 } // namespace internal 760 } // namespace internal
761 761
762 // static 762 // static
763 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { 763 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() {
764 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServiceWin()); 764 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServiceWin());
765 } 765 }
766 766
767 } // namespace net 767 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_win.h ('k') | net/dns/dns_config_service_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698