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

Side by Side Diff: net/proxy/dhcp_proxy_script_adapter_fetcher_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_unittest.cc ('k') | net/proxy/dhcp_proxy_script_fetcher_win.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/proxy/dhcp_proxy_script_adapter_fetcher_win.h" 5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 wpad_params.OptionId = 252; 226 wpad_params.OptionId = 252;
227 wpad_params.IsVendor = FALSE; // Surprising, but intentional. 227 wpad_params.IsVendor = FALSE; // Surprising, but intentional.
228 228
229 DHCPCAPI_PARAMS_ARRAY request_params = { 0 }; 229 DHCPCAPI_PARAMS_ARRAY request_params = { 0 };
230 request_params.nParams = 1; 230 request_params.nParams = 1;
231 request_params.Params = &wpad_params; 231 request_params.Params = &wpad_params;
232 232
233 // The maximum message size is typically 4096 bytes on Windows per 233 // The maximum message size is typically 4096 bytes on Windows per
234 // http://support.microsoft.com/kb/321592 234 // http://support.microsoft.com/kb/321592
235 DWORD result_buffer_size = 4096; 235 DWORD result_buffer_size = 4096;
236 scoped_ptr_malloc<BYTE> result_buffer; 236 scoped_ptr<BYTE, base::FreeDeleter> result_buffer;
237 int retry_count = 0; 237 int retry_count = 0;
238 DWORD res = NO_ERROR; 238 DWORD res = NO_ERROR;
239 do { 239 do {
240 result_buffer.reset(reinterpret_cast<BYTE*>(malloc(result_buffer_size))); 240 result_buffer.reset(static_cast<BYTE*>(malloc(result_buffer_size)));
241 241
242 // Note that while the DHCPCAPI_REQUEST_SYNCHRONOUS flag seems to indicate 242 // Note that while the DHCPCAPI_REQUEST_SYNCHRONOUS flag seems to indicate
243 // there might be an asynchronous mode, there seems to be (at least in 243 // there might be an asynchronous mode, there seems to be (at least in
244 // terms of well-documented use of this API) only a synchronous mode, with 244 // terms of well-documented use of this API) only a synchronous mode, with
245 // an optional "async notifications later if the option changes" mode. 245 // an optional "async notifications later if the option changes" mode.
246 // Even IE9, which we hope to emulate as IE is the most widely deployed 246 // Even IE9, which we hope to emulate as IE is the most widely deployed
247 // previous implementation of the DHCP aspect of WPAD and the only one 247 // previous implementation of the DHCP aspect of WPAD and the only one
248 // on Windows (Konqueror is the other, on Linux), uses this API with the 248 // on Windows (Konqueror is the other, on Linux), uses this API with the
249 // synchronous flag. There seem to be several Microsoft Knowledge Base 249 // synchronous flag. There seem to be several Microsoft Knowledge Base
250 // articles about calls to this function failing when other flags are used 250 // articles about calls to this function failing when other flags are used
251 // (e.g. http://support.microsoft.com/kb/885270) so we won't take any 251 // (e.g. http://support.microsoft.com/kb/885270) so we won't take any
252 // chances on non-standard, poorly documented usage. 252 // chances on non-standard, poorly documented usage.
253 res = ::DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, 253 res = ::DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS,
254 NULL, 254 NULL,
255 const_cast<LPWSTR>(adapter_name_wide.c_str()), 255 const_cast<LPWSTR>(adapter_name_wide.c_str()),
256 NULL, 256 NULL,
257 send_params, request_params, 257 send_params, request_params,
258 result_buffer.get(), &result_buffer_size, 258 result_buffer.get(), &result_buffer_size,
259 NULL); 259 NULL);
260 ++retry_count; 260 ++retry_count;
261 } while (res == ERROR_MORE_DATA && retry_count <= 3); 261 } while (res == ERROR_MORE_DATA && retry_count <= 3);
262 262
263 if (res != NO_ERROR) { 263 if (res != NO_ERROR) {
264 LOG(INFO) << "Error fetching PAC URL from DHCP: " << res; 264 LOG(WARNING) << "Error fetching PAC URL from DHCP: " << res;
265 UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1); 265 UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1);
266 } else if (wpad_params.nBytesData) { 266 } else if (wpad_params.nBytesData) {
267 return SanitizeDhcpApiString( 267 return SanitizeDhcpApiString(
268 reinterpret_cast<const char*>(wpad_params.Data), 268 reinterpret_cast<const char*>(wpad_params.Data),
269 wpad_params.nBytesData); 269 wpad_params.nBytesData);
270 } 270 }
271 271
272 return ""; 272 return "";
273 } 273 }
274 274
(...skipping 11 matching lines...) Expand all
286 // first null in case of embedded NULLs; this is the outer 286 // first null in case of embedded NULLs; this is the outer
287 // constructor that takes the result of c_str() on the inner. If 287 // constructor that takes the result of c_str() on the inner. If
288 // the server is giving us back a buffer with embedded NULLs, 288 // the server is giving us back a buffer with embedded NULLs,
289 // something is broken anyway. Finally, trim trailing whitespace. 289 // something is broken anyway. Finally, trim trailing whitespace.
290 std::string result(std::string(data, count_bytes).c_str()); 290 std::string result(std::string(data, count_bytes).c_str());
291 TrimWhitespaceASCII(result, TRIM_TRAILING, &result); 291 TrimWhitespaceASCII(result, TRIM_TRAILING, &result);
292 return result; 292 return result;
293 } 293 }
294 294
295 } // namespace net 295 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_win_unittest.cc ('k') | net/proxy/dhcp_proxy_script_fetcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698