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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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/host_resolver_impl.h ('k') | net/dns/host_resolver_impl_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/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>
11 #endif 11 #endif
12 12
13 #include <cmath> 13 #include <cmath>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/basictypes.h"
18 #include "base/bind.h" 17 #include "base/bind.h"
19 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
20 #include "base/callback.h" 19 #include "base/callback.h"
21 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
22 #include "base/debug/debugger.h" 21 #include "base/debug/debugger.h"
23 #include "base/debug/stack_trace.h" 22 #include "base/debug/stack_trace.h"
23 #include "base/macros.h"
24 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
25 #include "base/metrics/field_trial.h" 25 #include "base/metrics/field_trial.h"
26 #include "base/metrics/histogram_macros.h" 26 #include "base/metrics/histogram_macros.h"
27 #include "base/metrics/sparse_histogram.h" 27 #include "base/metrics/sparse_histogram.h"
28 #include "base/profiler/scoped_tracker.h" 28 #include "base/profiler/scoped_tracker.h"
29 #include "base/single_thread_task_runner.h" 29 #include "base/single_thread_task_runner.h"
30 #include "base/stl_util.h" 30 #include "base/stl_util.h"
31 #include "base/strings/string_util.h" 31 #include "base/strings/string_util.h"
32 #include "base/strings/utf_string_conversions.h" 32 #include "base/strings/utf_string_conversions.h"
33 #include "base/thread_task_runner_handle.h" 33 #include "base/thread_task_runner_handle.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 return false; 210 return false;
211 IPEndPoint endpoint; 211 IPEndPoint endpoint;
212 rv = socket->GetLocalAddress(&endpoint); 212 rv = socket->GetLocalAddress(&endpoint);
213 if (rv != OK) 213 if (rv != OK)
214 return false; 214 return false;
215 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily()); 215 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily());
216 const IPAddressNumber& address = endpoint.address(); 216 const IPAddressNumber& address = endpoint.address();
217 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); 217 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80);
218 if (is_link_local) 218 if (is_link_local)
219 return false; 219 return false;
220 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; 220 const uint8_t kTeredoPrefix[] = {0x20, 0x01, 0, 0};
221 bool is_teredo = std::equal(kTeredoPrefix, 221 bool is_teredo = std::equal(kTeredoPrefix,
222 kTeredoPrefix + arraysize(kTeredoPrefix), 222 kTeredoPrefix + arraysize(kTeredoPrefix),
223 address.begin()); 223 address.begin());
224 if (is_teredo) 224 if (is_teredo)
225 return false; 225 return false;
226 return true; 226 return true;
227 } 227 }
228 228
229 // Provide a common macro to simplify code and readability. We must use a 229 // Provide a common macro to simplify code and readability. We must use a
230 // macro as the underlying HISTOGRAM macro creates static variables. 230 // macro as the underlying HISTOGRAM macro creates static variables.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 std::string group_name = base::FieldTrialList::FindFullName("AsyncDns"); 281 std::string group_name = base::FieldTrialList::FindFullName("AsyncDns");
282 if (!group_name.empty()) { 282 if (!group_name.empty()) {
283 return base::StartsWith(group_name, "AsyncDnsNoFallback", 283 return base::StartsWith(group_name, "AsyncDnsNoFallback",
284 base::CompareCase::INSENSITIVE_ASCII); 284 base::CompareCase::INSENSITIVE_ASCII);
285 } 285 }
286 return kDefault; 286 return kDefault;
287 } 287 }
288 288
289 //----------------------------------------------------------------------------- 289 //-----------------------------------------------------------------------------
290 290
291 AddressList EnsurePortOnAddressList(const AddressList& list, uint16 port) { 291 AddressList EnsurePortOnAddressList(const AddressList& list, uint16_t port) {
292 if (list.empty() || list.front().port() == port) 292 if (list.empty() || list.front().port() == port)
293 return list; 293 return list;
294 return AddressList::CopyWithPort(list, port); 294 return AddressList::CopyWithPort(list, port);
295 } 295 }
296 296
297 // Returns true if |addresses| contains only IPv4 loopback addresses. 297 // Returns true if |addresses| contains only IPv4 loopback addresses.
298 bool IsAllIPv4Loopback(const AddressList& addresses) { 298 bool IsAllIPv4Loopback(const AddressList& addresses) {
299 for (unsigned i = 0; i < addresses.size(); ++i) { 299 for (unsigned i = 0; i < addresses.size(); ++i) {
300 const IPAddressNumber& address = addresses[i].address(); 300 const IPAddressNumber& address = addresses[i].address();
301 switch (addresses[i].GetFamily()) { 301 switch (addresses[i].GetFamily()) {
302 case ADDRESS_FAMILY_IPV4: 302 case ADDRESS_FAMILY_IPV4:
303 if (address[0] != 127) 303 if (address[0] != 127)
304 return false; 304 return false;
305 break; 305 break;
306 case ADDRESS_FAMILY_IPV6: 306 case ADDRESS_FAMILY_IPV6:
307 return false; 307 return false;
308 default: 308 default:
309 NOTREACHED(); 309 NOTREACHED();
310 return false; 310 return false;
311 } 311 }
312 } 312 }
313 return true; 313 return true;
314 } 314 }
315 315
316 // Creates NetLog parameters when the resolve failed. 316 // Creates NetLog parameters when the resolve failed.
317 scoped_ptr<base::Value> NetLogProcTaskFailedCallback( 317 scoped_ptr<base::Value> NetLogProcTaskFailedCallback(
318 uint32 attempt_number, 318 uint32_t attempt_number,
319 int net_error, 319 int net_error,
320 int os_error, 320 int os_error,
321 NetLogCaptureMode /* capture_mode */) { 321 NetLogCaptureMode /* capture_mode */) {
322 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 322 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
323 if (attempt_number) 323 if (attempt_number)
324 dict->SetInteger("attempt_number", attempt_number); 324 dict->SetInteger("attempt_number", attempt_number);
325 325
326 dict->SetInteger("net_error", net_error); 326 dict->SetInteger("net_error", net_error);
327 327
328 if (os_error) { 328 if (os_error) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 params_.unresponsive_delay); 689 params_.unresponsive_delay);
690 } 690 }
691 } 691 }
692 692
693 // WARNING: This code runs inside a worker pool. The shutdown code cannot 693 // WARNING: This code runs inside a worker pool. The shutdown code cannot
694 // wait for it to finish, so we must be very careful here about using other 694 // wait for it to finish, so we must be very careful here about using other
695 // objects (like MessageLoops, Singletons, etc). During shutdown these objects 695 // objects (like MessageLoops, Singletons, etc). During shutdown these objects
696 // may no longer exist. Multiple DoLookups() could be running in parallel, so 696 // may no longer exist. Multiple DoLookups() could be running in parallel, so
697 // any state inside of |this| must not mutate . 697 // any state inside of |this| must not mutate .
698 void DoLookup(const base::TimeTicks& start_time, 698 void DoLookup(const base::TimeTicks& start_time,
699 const uint32 attempt_number) { 699 const uint32_t attempt_number) {
700 AddressList results; 700 AddressList results;
701 int os_error = 0; 701 int os_error = 0;
702 // Running on the worker thread 702 // Running on the worker thread
703 int error = params_.resolver_proc->Resolve(key_.hostname, 703 int error = params_.resolver_proc->Resolve(key_.hostname,
704 key_.address_family, 704 key_.address_family,
705 key_.host_resolver_flags, 705 key_.host_resolver_flags,
706 &results, 706 &results,
707 &os_error); 707 &os_error);
708 708
709 // Fail the resolution if the result contains 127.0.53.53. See the comment 709 // Fail the resolution if the result contains 127.0.53.53. See the comment
(...skipping 25 matching lines...) Expand all
735 if (was_completed() || was_canceled()) 735 if (was_completed() || was_canceled())
736 return; 736 return;
737 737
738 params_.unresponsive_delay *= params_.retry_factor; 738 params_.unresponsive_delay *= params_.retry_factor;
739 StartLookupAttempt(); 739 StartLookupAttempt();
740 } 740 }
741 741
742 // Callback for when DoLookup() completes (runs on task runner thread). 742 // Callback for when DoLookup() completes (runs on task runner thread).
743 void OnLookupComplete(const AddressList& results, 743 void OnLookupComplete(const AddressList& results,
744 const base::TimeTicks& start_time, 744 const base::TimeTicks& start_time,
745 const uint32 attempt_number, 745 const uint32_t attempt_number,
746 int error, 746 int error,
747 const int os_error) { 747 const int os_error) {
748 DCHECK(task_runner_->BelongsToCurrentThread()); 748 DCHECK(task_runner_->BelongsToCurrentThread());
749 // If results are empty, we should return an error. 749 // If results are empty, we should return an error.
750 bool empty_list_on_ok = (error == OK && results.empty()); 750 bool empty_list_on_ok = (error == OK && results.empty());
751 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); 751 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok);
752 if (empty_list_on_ok) 752 if (empty_list_on_ok)
753 error = ERR_NAME_NOT_RESOLVED; 753 error = ERR_NAME_NOT_RESOLVED;
754 754
755 bool was_retry_attempt = attempt_number > 1; 755 bool was_retry_attempt = attempt_number > 1;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 UMA_HISTOGRAM_CUSTOM_ENUMERATION(kOSErrorsForGetAddrinfoHistogramName, 868 UMA_HISTOGRAM_CUSTOM_ENUMERATION(kOSErrorsForGetAddrinfoHistogramName,
869 std::abs(os_error), 869 std::abs(os_error),
870 GetAllGetAddrinfoOSErrors()); 870 GetAllGetAddrinfoOSErrors());
871 } 871 }
872 DCHECK_LT(category, static_cast<int>(RESOLVE_MAX)); // Be sure it was set. 872 DCHECK_LT(category, static_cast<int>(RESOLVE_MAX)); // Be sure it was set.
873 873
874 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveCategory", category, RESOLVE_MAX); 874 UMA_HISTOGRAM_ENUMERATION("DNS.ResolveCategory", category, RESOLVE_MAX);
875 } 875 }
876 876
877 void RecordAttemptHistograms(const base::TimeTicks& start_time, 877 void RecordAttemptHistograms(const base::TimeTicks& start_time,
878 const uint32 attempt_number, 878 const uint32_t attempt_number,
879 const int error, 879 const int error,
880 const int os_error) const { 880 const int os_error) const {
881 DCHECK(task_runner_->BelongsToCurrentThread()); 881 DCHECK(task_runner_->BelongsToCurrentThread());
882 bool first_attempt_to_complete = 882 bool first_attempt_to_complete =
883 completed_attempt_number_ == attempt_number; 883 completed_attempt_number_ == attempt_number;
884 bool is_first_attempt = (attempt_number == 1); 884 bool is_first_attempt = (attempt_number == 1);
885 885
886 if (first_attempt_to_complete) { 886 if (first_attempt_to_complete) {
887 // If this was first attempt to complete, then record the resolution 887 // If this was first attempt to complete, then record the resolution
888 // status of the attempt. 888 // status of the attempt.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 936
937 // The listener to the results of this ProcTask. 937 // The listener to the results of this ProcTask.
938 Callback callback_; 938 Callback callback_;
939 939
940 // Used to post ourselves onto the task runner thread. 940 // Used to post ourselves onto the task runner thread.
941 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 941 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
942 942
943 // Keeps track of the number of attempts we have made so far to resolve the 943 // Keeps track of the number of attempts we have made so far to resolve the
944 // host. Whenever we start an attempt to resolve the host, we increase this 944 // host. Whenever we start an attempt to resolve the host, we increase this
945 // number. 945 // number.
946 uint32 attempt_number_; 946 uint32_t attempt_number_;
947 947
948 // The index of the attempt which finished first (or 0 if the job is still in 948 // The index of the attempt which finished first (or 0 if the job is still in
949 // progress). 949 // progress).
950 uint32 completed_attempt_number_; 950 uint32_t completed_attempt_number_;
951 951
952 // The result (a net error code) from the first attempt to complete. 952 // The result (a net error code) from the first attempt to complete.
953 int completed_attempt_error_; 953 int completed_attempt_error_;
954 954
955 // The time when retry attempt was finished. 955 // The time when retry attempt was finished.
956 base::TimeTicks retry_attempt_finished_time_; 956 base::TimeTicks retry_attempt_finished_time_;
957 957
958 // True if a non-speculative request was ever attached to this job 958 // True if a non-speculative request was ever attached to this job
959 // (regardless of whether or not it was later canceled. 959 // (regardless of whether or not it was later canceled.
960 // This boolean is used for histogramming the duration of jobs used to 960 // This boolean is used for histogramming the duration of jobs used to
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 dns_client_->SetConfig(dns_config); 2426 dns_client_->SetConfig(dns_config);
2427 num_dns_failures_ = 0; 2427 num_dns_failures_ = 0;
2428 if (dns_client_->GetConfig()) 2428 if (dns_client_->GetConfig())
2429 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2429 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2430 } 2430 }
2431 2431
2432 AbortDnsTasks(); 2432 AbortDnsTasks();
2433 } 2433 }
2434 2434
2435 } // namespace net 2435 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698