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

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

Issue 1149763005: Change NetLog::ParametersCallback to return a scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments on ownership removed Created 5 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
« no previous file with comments | « net/dns/dns_transaction.cc ('k') | net/filter/filter.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/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 return false; 305 return false;
306 default: 306 default:
307 NOTREACHED(); 307 NOTREACHED();
308 return false; 308 return false;
309 } 309 }
310 } 310 }
311 return true; 311 return true;
312 } 312 }
313 313
314 // Creates NetLog parameters when the resolve failed. 314 // Creates NetLog parameters when the resolve failed.
315 base::Value* NetLogProcTaskFailedCallback( 315 scoped_ptr<base::Value> NetLogProcTaskFailedCallback(
316 uint32 attempt_number, 316 uint32 attempt_number,
317 int net_error, 317 int net_error,
318 int os_error, 318 int os_error,
319 NetLogCaptureMode /* capture_mode */) { 319 NetLogCaptureMode /* capture_mode */) {
320 base::DictionaryValue* dict = new base::DictionaryValue(); 320 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
321 if (attempt_number) 321 if (attempt_number)
322 dict->SetInteger("attempt_number", attempt_number); 322 dict->SetInteger("attempt_number", attempt_number);
323 323
324 dict->SetInteger("net_error", net_error); 324 dict->SetInteger("net_error", net_error);
325 325
326 if (os_error) { 326 if (os_error) {
327 dict->SetInteger("os_error", os_error); 327 dict->SetInteger("os_error", os_error);
328 #if defined(OS_POSIX) 328 #if defined(OS_POSIX)
329 dict->SetString("os_error_string", gai_strerror(os_error)); 329 dict->SetString("os_error_string", gai_strerror(os_error));
330 #elif defined(OS_WIN) 330 #elif defined(OS_WIN)
331 // Map the error code to a human-readable string. 331 // Map the error code to a human-readable string.
332 LPWSTR error_string = NULL; 332 LPWSTR error_string = NULL;
333 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 333 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
334 0, // Use the internal message table. 334 0, // Use the internal message table.
335 os_error, 335 os_error,
336 0, // Use default language. 336 0, // Use default language.
337 (LPWSTR)&error_string, 337 (LPWSTR)&error_string,
338 0, // Buffer size. 338 0, // Buffer size.
339 0); // Arguments (unused). 339 0); // Arguments (unused).
340 dict->SetString("os_error_string", base::WideToUTF8(error_string)); 340 dict->SetString("os_error_string", base::WideToUTF8(error_string));
341 LocalFree(error_string); 341 LocalFree(error_string);
342 #endif 342 #endif
343 } 343 }
344 344
345 return dict; 345 return dict.Pass();
346 } 346 }
347 347
348 // Creates NetLog parameters when the DnsTask failed. 348 // Creates NetLog parameters when the DnsTask failed.
349 base::Value* NetLogDnsTaskFailedCallback(int net_error, 349 scoped_ptr<base::Value> NetLogDnsTaskFailedCallback(
350 int dns_error, 350 int net_error,
351 NetLogCaptureMode /* capture_mode */) { 351 int dns_error,
352 base::DictionaryValue* dict = new base::DictionaryValue(); 352 NetLogCaptureMode /* capture_mode */) {
353 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
353 dict->SetInteger("net_error", net_error); 354 dict->SetInteger("net_error", net_error);
354 if (dns_error) 355 if (dns_error)
355 dict->SetInteger("dns_error", dns_error); 356 dict->SetInteger("dns_error", dns_error);
356 return dict; 357 return dict.Pass();
357 }; 358 };
358 359
359 // Creates NetLog parameters containing the information in a RequestInfo object, 360 // Creates NetLog parameters containing the information in a RequestInfo object,
360 // along with the associated NetLog::Source. 361 // along with the associated NetLog::Source.
361 base::Value* NetLogRequestInfoCallback(const HostResolver::RequestInfo* info, 362 scoped_ptr<base::Value> NetLogRequestInfoCallback(
362 NetLogCaptureMode /* capture_mode */) { 363 const HostResolver::RequestInfo* info,
363 base::DictionaryValue* dict = new base::DictionaryValue(); 364 NetLogCaptureMode /* capture_mode */) {
365 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
364 366
365 dict->SetString("host", info->host_port_pair().ToString()); 367 dict->SetString("host", info->host_port_pair().ToString());
366 dict->SetInteger("address_family", 368 dict->SetInteger("address_family",
367 static_cast<int>(info->address_family())); 369 static_cast<int>(info->address_family()));
368 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); 370 dict->SetBoolean("allow_cached_response", info->allow_cached_response());
369 dict->SetBoolean("is_speculative", info->is_speculative()); 371 dict->SetBoolean("is_speculative", info->is_speculative());
370 return dict; 372 return dict.Pass();
371 } 373 }
372 374
373 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. 375 // Creates NetLog parameters for the creation of a HostResolverImpl::Job.
374 base::Value* NetLogJobCreationCallback(const NetLog::Source& source, 376 scoped_ptr<base::Value> NetLogJobCreationCallback(
375 const std::string* host, 377 const NetLog::Source& source,
376 NetLogCaptureMode /* capture_mode */) { 378 const std::string* host,
377 base::DictionaryValue* dict = new base::DictionaryValue(); 379 NetLogCaptureMode /* capture_mode */) {
378 source.AddToEventParameters(dict); 380 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
381 source.AddToEventParameters(dict.get());
379 dict->SetString("host", *host); 382 dict->SetString("host", *host);
380 return dict; 383 return dict.Pass();
381 } 384 }
382 385
383 // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events. 386 // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events.
384 base::Value* NetLogJobAttachCallback(const NetLog::Source& source, 387 scoped_ptr<base::Value> NetLogJobAttachCallback(
385 RequestPriority priority, 388 const NetLog::Source& source,
386 NetLogCaptureMode /* capture_mode */) { 389 RequestPriority priority,
387 base::DictionaryValue* dict = new base::DictionaryValue(); 390 NetLogCaptureMode /* capture_mode */) {
388 source.AddToEventParameters(dict); 391 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
392 source.AddToEventParameters(dict.get());
389 dict->SetString("priority", RequestPriorityToString(priority)); 393 dict->SetString("priority", RequestPriorityToString(priority));
390 return dict; 394 return dict.Pass();
391 } 395 }
392 396
393 // Creates NetLog parameters for the DNS_CONFIG_CHANGED event. 397 // Creates NetLog parameters for the DNS_CONFIG_CHANGED event.
394 base::Value* NetLogDnsConfigCallback(const DnsConfig* config, 398 scoped_ptr<base::Value> NetLogDnsConfigCallback(
395 NetLogCaptureMode /* capture_mode */) { 399 const DnsConfig* config,
396 return config->ToValue(); 400 NetLogCaptureMode /* capture_mode */) {
401 return make_scoped_ptr(config->ToValue());
397 } 402 }
398 403
399 base::Value* NetLogIPv6AvailableCallback(bool ipv6_available, 404 scoped_ptr<base::Value> NetLogIPv6AvailableCallback(
400 bool cached, 405 bool ipv6_available,
401 NetLogCaptureMode /* capture_mode */) { 406 bool cached,
402 base::DictionaryValue* dict = new base::DictionaryValue(); 407 NetLogCaptureMode /* capture_mode */) {
408 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
403 dict->SetBoolean("ipv6_available", ipv6_available); 409 dict->SetBoolean("ipv6_available", ipv6_available);
404 dict->SetBoolean("cached", cached); 410 dict->SetBoolean("cached", cached);
405 return dict; 411 return dict.Pass();
406 } 412 }
407 413
408 // The logging routines are defined here because some requests are resolved 414 // The logging routines are defined here because some requests are resolved
409 // without a Request object. 415 // without a Request object.
410 416
411 // Logs when a request has just been started. 417 // Logs when a request has just been started.
412 void LogStartRequest(const BoundNetLog& source_net_log, 418 void LogStartRequest(const BoundNetLog& source_net_log,
413 const HostResolver::RequestInfo& info) { 419 const HostResolver::RequestInfo& info) {
414 source_net_log.BeginEvent( 420 source_net_log.BeginEvent(
415 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, 421 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST,
(...skipping 2002 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 dns_client_->SetConfig(dns_config); 2424 dns_client_->SetConfig(dns_config);
2419 num_dns_failures_ = 0; 2425 num_dns_failures_ = 0;
2420 if (dns_client_->GetConfig()) 2426 if (dns_client_->GetConfig())
2421 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2427 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2422 } 2428 }
2423 2429
2424 AbortDnsTasks(); 2430 AbortDnsTasks();
2425 } 2431 }
2426 2432
2427 } // namespace net 2433 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_transaction.cc ('k') | net/filter/filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698