OLD | NEW |
---|---|
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/base/host_resolver_impl.h" | 5 #include "net/base/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 14 matching lines...) Expand all Loading... | |
25 #include "base/metrics/field_trial.h" | 25 #include "base/metrics/field_trial.h" |
26 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
27 #include "base/stl_util.h" | 27 #include "base/stl_util.h" |
28 #include "base/string_util.h" | 28 #include "base/string_util.h" |
29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
30 #include "base/time.h" | 30 #include "base/time.h" |
31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
32 #include "base/values.h" | 32 #include "base/values.h" |
33 #include "net/base/address_family.h" | 33 #include "net/base/address_family.h" |
34 #include "net/base/address_list.h" | 34 #include "net/base/address_list.h" |
35 #include "net/base/address_list_net_log_param.h" | |
36 #include "net/base/dns_reloader.h" | 35 #include "net/base/dns_reloader.h" |
37 #include "net/base/host_port_pair.h" | 36 #include "net/base/host_port_pair.h" |
38 #include "net/base/host_resolver_proc.h" | 37 #include "net/base/host_resolver_proc.h" |
39 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
40 #include "net/base/net_log.h" | 39 #include "net/base/net_log.h" |
41 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
42 #include "net/dns/dns_client.h" | 41 #include "net/dns/dns_client.h" |
43 #include "net/dns/dns_config_service.h" | 42 #include "net/dns/dns_config_service.h" |
44 #include "net/dns/dns_protocol.h" | 43 #include "net/dns/dns_protocol.h" |
45 #include "net/dns/dns_response.h" | 44 #include "net/dns/dns_response.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 virtual ~CallSystemHostResolverProc() {} | 169 virtual ~CallSystemHostResolverProc() {} |
171 }; | 170 }; |
172 | 171 |
173 void EnsurePortOnAddressList(uint16 port, AddressList* list) { | 172 void EnsurePortOnAddressList(uint16 port, AddressList* list) { |
174 DCHECK(list); | 173 DCHECK(list); |
175 if (list->empty() || list->front().port() == port) | 174 if (list->empty() || list->front().port() == port) |
176 return; | 175 return; |
177 SetPortOnAddressList(port, list); | 176 SetPortOnAddressList(port, list); |
178 } | 177 } |
179 | 178 |
180 // Extra parameters to attach to the NetLog when the resolve failed. | 179 // Creates NetLog parameters when the resolve failed. |
181 class ProcTaskFailedParams : public NetLog::EventParameters { | 180 base::Value* NetLogProcTaskFailedCallback(uint32 attempt_number, |
182 public: | 181 int net_error, |
183 ProcTaskFailedParams(uint32 attempt_number, int net_error, int os_error) | 182 int os_error, |
184 : attempt_number_(attempt_number), | 183 NetLog::LogLevel /* log_level */) { |
185 net_error_(net_error), | 184 DictionaryValue* dict = new DictionaryValue(); |
186 os_error_(os_error) { | 185 if (attempt_number) |
186 dict->SetInteger("attempt_number", attempt_number); | |
187 | |
188 dict->SetInteger("net_error", net_error); | |
189 | |
190 if (os_error) { | |
191 dict->SetInteger("os_error", os_error); | |
192 #if defined(OS_POSIX) | |
193 dict->SetString("os_error_string", gai_strerror(os_error)); | |
194 #elif defined(OS_WIN) | |
195 // Map the error code to a human-readable string. | |
196 LPWSTR error_string = NULL; | |
197 int size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
198 FORMAT_MESSAGE_FROM_SYSTEM, | |
199 0, // Use the internal message table. | |
200 os_error, | |
201 0, // Use default language. | |
202 (LPWSTR)&error_string, | |
203 0, // Buffer size. | |
204 0); // Arguments (unused). | |
205 dict->SetString("os_error_string", WideToUTF8(error_string)); | |
206 LocalFree(error_string); | |
207 #endif | |
187 } | 208 } |
188 | 209 |
189 virtual Value* ToValue() const OVERRIDE { | 210 return dict; |
190 DictionaryValue* dict = new DictionaryValue(); | 211 } |
191 if (attempt_number_) | |
192 dict->SetInteger("attempt_number", attempt_number_); | |
193 | 212 |
194 dict->SetInteger("net_error", net_error_); | 213 // Creates NetLog parameters when the DnsTask failed. |
195 | 214 base::Value* NetLogDnsTaskFailedCallback(int net_error, |
196 if (os_error_) { | 215 int dns_error, |
197 dict->SetInteger("os_error", os_error_); | 216 NetLog::LogLevel /* log_level */) { |
198 #if defined(OS_POSIX) | 217 DictionaryValue* dict = new DictionaryValue(); |
199 dict->SetString("os_error_string", gai_strerror(os_error_)); | 218 dict->SetInteger("net_error", net_error); |
200 #elif defined(OS_WIN) | 219 if (dns_error) |
201 // Map the error code to a human-readable string. | 220 dict->SetInteger("dns_error", dns_error); |
202 LPWSTR error_string = NULL; | 221 return dict; |
203 int size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
204 FORMAT_MESSAGE_FROM_SYSTEM, | |
205 0, // Use the internal message table. | |
206 os_error_, | |
207 0, // Use default language. | |
208 (LPWSTR)&error_string, | |
209 0, // Buffer size. | |
210 0); // Arguments (unused). | |
211 dict->SetString("os_error_string", WideToUTF8(error_string)); | |
212 LocalFree(error_string); | |
213 #endif | |
214 } | |
215 | |
216 return dict; | |
217 } | |
218 | |
219 protected: | |
220 virtual ~ProcTaskFailedParams() {} | |
221 | |
222 private: | |
223 const uint32 attempt_number_; | |
224 const int net_error_; | |
225 const int os_error_; | |
226 }; | 222 }; |
227 | 223 |
228 // Extra parameters to attach to the NetLog when the DnsTask failed. | 224 // Creates NetLog parameters containing the information in a RequestInfo object, |
229 class DnsTaskFailedParams : public NetLog::EventParameters { | 225 // along with the associated NetLog::Source. |
230 public: | 226 base::Value* NetLogRequestInfoCallback(const NetLog::Source& source, |
231 DnsTaskFailedParams(int net_error, int dns_error) | 227 const HostResolver::RequestInfo* info, |
232 : net_error_(net_error), dns_error_(dns_error) { | 228 NetLog::LogLevel /* log_level */) { |
233 } | 229 DictionaryValue* dict = new DictionaryValue(); |
230 source.AddToEventParameters(dict); | |
234 | 231 |
235 virtual Value* ToValue() const OVERRIDE { | 232 dict->SetString("host", info->host_port_pair().ToString()); |
236 DictionaryValue* dict = new DictionaryValue(); | 233 dict->SetInteger("address_family", |
237 dict->SetInteger("net_error", net_error_); | 234 static_cast<int>(info->address_family())); |
238 if (dns_error_) | 235 dict->SetBoolean("allow_cached_response", info->allow_cached_response()); |
239 dict->SetInteger("dns_error", dns_error_); | 236 dict->SetBoolean("is_speculative", info->is_speculative()); |
240 return dict; | 237 dict->SetInteger("priority", info->priority()); |
241 } | 238 return dict; |
239 } | |
242 | 240 |
243 protected: | 241 // Creates NetLog parameters for the creation of a HostResolverImpl::Job. |
244 virtual ~DnsTaskFailedParams() {} | 242 base::Value* NetLogJobCreationCallback(const NetLog::Source& source, |
243 const std::string* host, | |
244 NetLog::LogLevel /* log_level */) { | |
245 DictionaryValue* dict = new DictionaryValue(); | |
246 source.AddToEventParameters(dict); | |
247 dict->SetString("host", *host); | |
248 return dict; | |
249 } | |
245 | 250 |
246 private: | 251 // Creates NetLog parameters for HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH events. |
247 const int net_error_; | 252 base::Value* NetLogJobAttachCallback(const NetLog::Source& source, |
248 const int dns_error_; | 253 RequestPriority priority, |
249 }; | 254 NetLog::LogLevel /* log_level */) { |
255 DictionaryValue* dict = new DictionaryValue(); | |
256 source.AddToEventParameters(dict); | |
257 dict->SetInteger("priority", priority); | |
258 return dict; | |
259 } | |
250 | 260 |
251 // Parameters representing the information in a RequestInfo object, along with | 261 // Creates NetLog parameters for the DNS_CONFIG_CHANGED event. |
252 // the associated NetLog::Source. | 262 base::Value* NetLogDnsConfigCallback(const DnsConfig* config, |
253 class RequestInfoParameters : public NetLog::EventParameters { | 263 NetLog::LogLevel /* log_level */) { |
254 public: | 264 return config->ToValue(); |
eroman
2012/06/11 23:42:25
I didn't look in detail, but the original also set
mmenke
2012/06/12 00:42:19
In the original, we made a copy of the config, exc
| |
255 RequestInfoParameters(const HostResolver::RequestInfo& info, | 265 } |
256 const NetLog::Source& source) | |
257 : info_(info), source_(source) {} | |
258 | |
259 virtual Value* ToValue() const OVERRIDE { | |
260 DictionaryValue* dict = new DictionaryValue(); | |
261 dict->SetString("host", info_.host_port_pair().ToString()); | |
262 dict->SetInteger("address_family", | |
263 static_cast<int>(info_.address_family())); | |
264 dict->SetBoolean("allow_cached_response", info_.allow_cached_response()); | |
265 dict->SetBoolean("is_speculative", info_.is_speculative()); | |
266 dict->SetInteger("priority", info_.priority()); | |
267 | |
268 if (source_.is_valid()) | |
269 dict->Set("source_dependency", source_.ToValue()); | |
270 | |
271 return dict; | |
272 } | |
273 | |
274 protected: | |
275 virtual ~RequestInfoParameters() {} | |
276 | |
277 private: | |
278 const HostResolver::RequestInfo info_; | |
279 const NetLog::Source source_; | |
280 }; | |
281 | |
282 // Parameters associated with the creation of a HostResolverImpl::Job. | |
283 class JobCreationParameters : public NetLog::EventParameters { | |
284 public: | |
285 JobCreationParameters(const std::string& host, | |
286 const NetLog::Source& source) | |
287 : host_(host), source_(source) {} | |
288 | |
289 virtual Value* ToValue() const OVERRIDE { | |
290 DictionaryValue* dict = new DictionaryValue(); | |
291 dict->SetString("host", host_); | |
292 dict->Set("source_dependency", source_.ToValue()); | |
293 return dict; | |
294 } | |
295 | |
296 protected: | |
297 virtual ~JobCreationParameters() {} | |
298 | |
299 private: | |
300 const std::string host_; | |
301 const NetLog::Source source_; | |
302 }; | |
303 | |
304 // Parameters of the HOST_RESOLVER_IMPL_JOB_ATTACH/DETACH event. | |
305 class JobAttachParameters : public NetLog::EventParameters { | |
306 public: | |
307 JobAttachParameters(const NetLog::Source& source, | |
308 RequestPriority priority) | |
309 : source_(source), priority_(priority) {} | |
310 | |
311 virtual Value* ToValue() const OVERRIDE { | |
312 DictionaryValue* dict = new DictionaryValue(); | |
313 dict->Set("source_dependency", source_.ToValue()); | |
314 dict->SetInteger("priority", priority_); | |
315 return dict; | |
316 } | |
317 | |
318 protected: | |
319 virtual ~JobAttachParameters() {} | |
320 | |
321 private: | |
322 const NetLog::Source source_; | |
323 const RequestPriority priority_; | |
324 }; | |
325 | |
326 // Parameters of the DNS_CONFIG_CHANGED event. | |
327 class DnsConfigParameters : public NetLog::EventParameters { | |
328 public: | |
329 explicit DnsConfigParameters(const DnsConfig& config) | |
330 : num_hosts_(config.hosts.size()) { | |
331 config_.CopyIgnoreHosts(config); | |
332 } | |
333 | |
334 virtual Value* ToValue() const OVERRIDE { | |
335 Value* value = config_.ToValue(); | |
336 if (!value) | |
337 return NULL; | |
338 DictionaryValue* dict; | |
339 if (value->GetAsDictionary(&dict)) | |
340 dict->SetInteger("num_hosts", num_hosts_); | |
341 return value; | |
342 } | |
343 | |
344 protected: | |
345 virtual ~DnsConfigParameters() {} | |
346 | |
347 private: | |
348 DnsConfig config_; // Does not include DnsHosts to save memory and work. | |
349 const size_t num_hosts_; | |
350 }; | |
351 | 266 |
352 // The logging routines are defined here because some requests are resolved | 267 // The logging routines are defined here because some requests are resolved |
353 // without a Request object. | 268 // without a Request object. |
354 | 269 |
355 // Logs when a request has just been started. | 270 // Logs when a request has just been started. |
356 void LogStartRequest(const BoundNetLog& source_net_log, | 271 void LogStartRequest(const BoundNetLog& source_net_log, |
357 const BoundNetLog& request_net_log, | 272 const BoundNetLog& request_net_log, |
358 const HostResolver::RequestInfo& info) { | 273 const HostResolver::RequestInfo& info) { |
359 source_net_log.BeginEvent( | 274 source_net_log.BeginEvent( |
360 NetLog::TYPE_HOST_RESOLVER_IMPL, | 275 NetLog::TYPE_HOST_RESOLVER_IMPL, |
361 make_scoped_refptr(new NetLogSourceParameter( | 276 request_net_log.source().ToEventParametersCallback()); |
362 "source_dependency", request_net_log.source()))); | |
363 | 277 |
364 request_net_log.BeginEvent( | 278 request_net_log.BeginEvent( |
365 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 279 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
366 make_scoped_refptr(new RequestInfoParameters( | 280 base::Bind(&NetLogRequestInfoCallback, source_net_log.source(), &info)); |
367 info, source_net_log.source()))); | |
368 } | 281 } |
369 | 282 |
370 // Logs when a request has just completed (before its callback is run). | 283 // Logs when a request has just completed (before its callback is run). |
371 void LogFinishRequest(const BoundNetLog& source_net_log, | 284 void LogFinishRequest(const BoundNetLog& source_net_log, |
372 const BoundNetLog& request_net_log, | 285 const BoundNetLog& request_net_log, |
373 const HostResolver::RequestInfo& info, | 286 const HostResolver::RequestInfo& info, |
374 int net_error) { | 287 int net_error) { |
375 request_net_log.EndEventWithNetErrorCode( | 288 request_net_log.EndEventWithNetErrorCode( |
376 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, net_error); | 289 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, net_error); |
377 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | 290 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 // returned (IO_PENDING). | 590 // returned (IO_PENDING). |
678 origin_loop_->PostTask( | 591 origin_loop_->PostTask( |
679 FROM_HERE, | 592 FROM_HERE, |
680 base::Bind(&ProcTask::OnLookupComplete, this, AddressList(), | 593 base::Bind(&ProcTask::OnLookupComplete, this, AddressList(), |
681 start_time, attempt_number_, ERR_UNEXPECTED, 0)); | 594 start_time, attempt_number_, ERR_UNEXPECTED, 0)); |
682 return; | 595 return; |
683 } | 596 } |
684 | 597 |
685 net_log_.AddEvent( | 598 net_log_.AddEvent( |
686 NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_STARTED, | 599 NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_STARTED, |
687 make_scoped_refptr(new NetLogIntegerParameter( | 600 NetLog::IntegerCallback("attempt_number", attempt_number_)); |
688 "attempt_number", attempt_number_))); | |
689 | 601 |
690 // If we don't get the results within a given time, RetryIfNotComplete | 602 // If we don't get the results within a given time, RetryIfNotComplete |
691 // will start a new attempt on a different worker thread if none of our | 603 // will start a new attempt on a different worker thread if none of our |
692 // outstanding attempts have completed yet. | 604 // outstanding attempts have completed yet. |
693 if (attempt_number_ <= params_.max_retry_attempts) { | 605 if (attempt_number_ <= params_.max_retry_attempts) { |
694 origin_loop_->PostDelayedTask( | 606 origin_loop_->PostDelayedTask( |
695 FROM_HERE, | 607 FROM_HERE, |
696 base::Bind(&ProcTask::RetryIfNotComplete, this), | 608 base::Bind(&ProcTask::RetryIfNotComplete, this), |
697 params_.unresponsive_delay); | 609 params_.unresponsive_delay); |
698 } | 610 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 // If this is the first attempt that is finishing later, then record data | 663 // If this is the first attempt that is finishing later, then record data |
752 // for the first attempt. Won't contaminate with retry attempt's data. | 664 // for the first attempt. Won't contaminate with retry attempt's data. |
753 if (!was_retry_attempt) | 665 if (!was_retry_attempt) |
754 RecordPerformanceHistograms(start_time, error, os_error); | 666 RecordPerformanceHistograms(start_time, error, os_error); |
755 | 667 |
756 RecordAttemptHistograms(start_time, attempt_number, error, os_error); | 668 RecordAttemptHistograms(start_time, attempt_number, error, os_error); |
757 | 669 |
758 if (was_canceled()) | 670 if (was_canceled()) |
759 return; | 671 return; |
760 | 672 |
761 scoped_refptr<NetLog::EventParameters> params; | 673 NetLog::ParametersCallback callback; |
eroman
2012/06/11 23:42:25
optional nit: I suggest calling this "netlog_callb
mmenke
2012/06/12 00:42:19
Done.
| |
762 if (error != OK) { | 674 if (error != OK) { |
763 params = new ProcTaskFailedParams(attempt_number, error, os_error); | 675 callback = base::Bind(&NetLogProcTaskFailedCallback, |
676 attempt_number, | |
677 error, | |
678 os_error); | |
764 } else { | 679 } else { |
765 params = new NetLogIntegerParameter("attempt_number", attempt_number); | 680 callback = NetLog::IntegerCallback("attempt_number", attempt_number); |
766 } | 681 } |
767 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_FINISHED, params); | 682 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_FINISHED, |
683 callback); | |
768 | 684 |
769 if (was_completed()) | 685 if (was_completed()) |
770 return; | 686 return; |
771 | 687 |
772 // Copy the results from the first worker thread that resolves the host. | 688 // Copy the results from the first worker thread that resolves the host. |
773 results_ = results; | 689 results_ = results; |
774 completed_attempt_number_ = attempt_number; | 690 completed_attempt_number_ = attempt_number; |
775 completed_attempt_error_ = error; | 691 completed_attempt_error_ = error; |
776 | 692 |
777 if (was_retry_attempt) { | 693 if (was_retry_attempt) { |
778 // If retry attempt finishes before 1st attempt, then get stats on how | 694 // If retry attempt finishes before 1st attempt, then get stats on how |
779 // much time is saved by having spawned an extra attempt. | 695 // much time is saved by having spawned an extra attempt. |
780 retry_attempt_finished_time_ = base::TimeTicks::Now(); | 696 retry_attempt_finished_time_ = base::TimeTicks::Now(); |
781 } | 697 } |
782 | 698 |
783 if (error != OK) { | 699 if (error != OK) { |
784 params = new ProcTaskFailedParams(0, error, os_error); | 700 callback = base::Bind(&NetLogProcTaskFailedCallback, 0, error, os_error); |
785 } else { | 701 } else { |
786 params = new AddressListNetLogParam(results_); | 702 callback = base::Bind(&AddressList::NetLogCallback, |
703 base::Unretained(&results_)); | |
787 } | 704 } |
788 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, params); | 705 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, callback); |
789 | 706 |
790 callback_.Run(error, results_); | 707 callback_.Run(error, results_); |
791 } | 708 } |
792 | 709 |
793 void RecordPerformanceHistograms(const base::TimeTicks& start_time, | 710 void RecordPerformanceHistograms(const base::TimeTicks& start_time, |
794 const int error, | 711 const int error, |
795 const int os_error) const { | 712 const int os_error) const { |
796 DCHECK(origin_loop_->BelongsToCurrentThread()); | 713 DCHECK(origin_loop_->BelongsToCurrentThread()); |
797 enum Category { // Used in HISTOGRAM_ENUMERATION. | 714 enum Category { // Used in HISTOGRAM_ENUMERATION. |
798 RESOLVE_SUCCESS, | 715 RESOLVE_SUCCESS, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 CHECK(response); | 1008 CHECK(response); |
1092 DNS_HISTOGRAM("AsyncDNS.TransactionSuccess", | 1009 DNS_HISTOGRAM("AsyncDNS.TransactionSuccess", |
1093 base::TimeTicks::Now() - start_time); | 1010 base::TimeTicks::Now() - start_time); |
1094 AddressList addr_list; | 1011 AddressList addr_list; |
1095 base::TimeDelta ttl; | 1012 base::TimeDelta ttl; |
1096 result = response->ParseToAddressList(&addr_list, &ttl); | 1013 result = response->ParseToAddressList(&addr_list, &ttl); |
1097 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ParseToAddressList", | 1014 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ParseToAddressList", |
1098 result, | 1015 result, |
1099 DnsResponse::DNS_PARSE_RESULT_MAX); | 1016 DnsResponse::DNS_PARSE_RESULT_MAX); |
1100 if (result == DnsResponse::DNS_SUCCESS) { | 1017 if (result == DnsResponse::DNS_SUCCESS) { |
1101 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, | 1018 net_log_.EndEvent( |
1102 new AddressListNetLogParam(addr_list)); | 1019 NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, |
1020 base::Bind(&AddressList::NetLogCallback, | |
1021 base::Unretained(&addr_list))); | |
1103 callback_.Run(net_error, addr_list, ttl); | 1022 callback_.Run(net_error, addr_list, ttl); |
1104 return; | 1023 return; |
1105 } | 1024 } |
1106 net_error = ERR_DNS_MALFORMED_RESPONSE; | 1025 net_error = ERR_DNS_MALFORMED_RESPONSE; |
1107 } else { | 1026 } else { |
1108 DNS_HISTOGRAM("AsyncDNS.TransactionFailure", | 1027 DNS_HISTOGRAM("AsyncDNS.TransactionFailure", |
1109 base::TimeTicks::Now() - start_time); | 1028 base::TimeTicks::Now() - start_time); |
1110 } | 1029 } |
1111 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, | 1030 net_log_.EndEvent( |
1112 new DnsTaskFailedParams(net_error, result)); | 1031 NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, |
1032 base::Bind(&NetLogDnsTaskFailedCallback, net_error, result)); | |
1113 callback_.Run(net_error, AddressList(), base::TimeDelta()); | 1033 callback_.Run(net_error, AddressList(), base::TimeDelta()); |
1114 } | 1034 } |
1115 | 1035 |
1116 private: | 1036 private: |
1117 // The listener to the results of this DnsTask. | 1037 // The listener to the results of this DnsTask. |
1118 Callback callback_; | 1038 Callback callback_; |
1119 | 1039 |
1120 const BoundNetLog net_log_; | 1040 const BoundNetLog net_log_; |
1121 | 1041 |
1122 scoped_ptr<DnsTransaction> transaction_; | 1042 scoped_ptr<DnsTransaction> transaction_; |
(...skipping 12 matching lines...) Expand all Loading... | |
1135 : resolver_(resolver->AsWeakPtr()), | 1055 : resolver_(resolver->AsWeakPtr()), |
1136 key_(key), | 1056 key_(key), |
1137 had_non_speculative_request_(false), | 1057 had_non_speculative_request_(false), |
1138 had_dns_config_(false), | 1058 had_dns_config_(false), |
1139 net_log_(BoundNetLog::Make(request_net_log.net_log(), | 1059 net_log_(BoundNetLog::Make(request_net_log.net_log(), |
1140 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { | 1060 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { |
1141 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, NULL); | 1061 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, NULL); |
1142 | 1062 |
1143 net_log_.BeginEvent( | 1063 net_log_.BeginEvent( |
1144 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1064 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
1145 make_scoped_refptr(new JobCreationParameters( | 1065 base::Bind(&NetLogJobCreationCallback, |
1146 key_.hostname, request_net_log.source()))); | 1066 request_net_log.source(), |
1067 &key_.hostname)); | |
1147 } | 1068 } |
1148 | 1069 |
1149 virtual ~Job() { | 1070 virtual ~Job() { |
1150 if (is_running()) { | 1071 if (is_running()) { |
1151 // |resolver_| was destroyed with this Job still in flight. | 1072 // |resolver_| was destroyed with this Job still in flight. |
1152 // Clean-up, record in the log, but don't run any callbacks. | 1073 // Clean-up, record in the log, but don't run any callbacks. |
1153 if (is_proc_running()) { | 1074 if (is_proc_running()) { |
1154 proc_task_->Cancel(); | 1075 proc_task_->Cancel(); |
1155 proc_task_ = NULL; | 1076 proc_task_ = NULL; |
1156 } | 1077 } |
(...skipping 27 matching lines...) Expand all Loading... | |
1184 } | 1105 } |
1185 | 1106 |
1186 void AddRequest(scoped_ptr<Request> req) { | 1107 void AddRequest(scoped_ptr<Request> req) { |
1187 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1108 DCHECK_EQ(key_.hostname, req->info().hostname()); |
1188 | 1109 |
1189 req->set_job(this); | 1110 req->set_job(this); |
1190 priority_tracker_.Add(req->info().priority()); | 1111 priority_tracker_.Add(req->info().priority()); |
1191 | 1112 |
1192 req->request_net_log().AddEvent( | 1113 req->request_net_log().AddEvent( |
1193 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, | 1114 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, |
1194 make_scoped_refptr(new NetLogSourceParameter( | 1115 net_log_.source().ToEventParametersCallback()); |
1195 "source_dependency", net_log_.source()))); | |
1196 | 1116 |
1197 net_log_.AddEvent( | 1117 net_log_.AddEvent( |
1198 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, | 1118 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, |
1199 make_scoped_refptr(new JobAttachParameters( | 1119 base::Bind(&NetLogJobAttachCallback, |
1200 req->request_net_log().source(), priority()))); | 1120 req->request_net_log().source(), |
1121 priority())); | |
1201 | 1122 |
1202 // TODO(szym): Check if this is still needed. | 1123 // TODO(szym): Check if this is still needed. |
1203 if (!req->info().is_speculative()) { | 1124 if (!req->info().is_speculative()) { |
1204 had_non_speculative_request_ = true; | 1125 had_non_speculative_request_ = true; |
1205 if (proc_task_) | 1126 if (proc_task_) |
1206 proc_task_->set_had_non_speculative_request(); | 1127 proc_task_->set_had_non_speculative_request(); |
1207 } | 1128 } |
1208 | 1129 |
1209 requests_.push_back(req.release()); | 1130 requests_.push_back(req.release()); |
1210 | 1131 |
1211 if (is_queued()) | 1132 if (is_queued()) |
1212 handle_ = resolver_->dispatcher_.ChangePriority(handle_, priority()); | 1133 handle_ = resolver_->dispatcher_.ChangePriority(handle_, priority()); |
1213 } | 1134 } |
1214 | 1135 |
1215 // Marks |req| as cancelled. If it was the last active Request, also finishes | 1136 // Marks |req| as cancelled. If it was the last active Request, also finishes |
1216 // this Job marking it either as aborted or cancelled, and deletes it. | 1137 // this Job marking it either as aborted or cancelled, and deletes it. |
1217 void CancelRequest(Request* req) { | 1138 void CancelRequest(Request* req) { |
1218 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1139 DCHECK_EQ(key_.hostname, req->info().hostname()); |
1219 DCHECK(!req->was_canceled()); | 1140 DCHECK(!req->was_canceled()); |
1220 | 1141 |
1221 // Don't remove it from |requests_| just mark it canceled. | 1142 // Don't remove it from |requests_| just mark it canceled. |
1222 req->MarkAsCanceled(); | 1143 req->MarkAsCanceled(); |
1223 LogCancelRequest(req->source_net_log(), req->request_net_log(), | 1144 LogCancelRequest(req->source_net_log(), req->request_net_log(), |
1224 req->info()); | 1145 req->info()); |
1225 | 1146 |
1226 priority_tracker_.Remove(req->info().priority()); | 1147 priority_tracker_.Remove(req->info().priority()); |
1227 net_log_.AddEvent( | 1148 net_log_.AddEvent( |
1228 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, | 1149 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, |
1229 make_scoped_refptr(new JobAttachParameters( | 1150 base::Bind(&NetLogJobAttachCallback, |
1230 req->request_net_log().source(), priority()))); | 1151 req->request_net_log().source(), |
1152 priority())); | |
1231 | 1153 |
1232 if (num_active_requests() > 0) { | 1154 if (num_active_requests() > 0) { |
1233 if (is_queued()) | 1155 if (is_queued()) |
1234 handle_ = resolver_->dispatcher_.ChangePriority(handle_, priority()); | 1156 handle_ = resolver_->dispatcher_.ChangePriority(handle_, priority()); |
1235 } else { | 1157 } else { |
1236 // If we were called from a Request's callback within CompleteRequests, | 1158 // If we were called from a Request's callback within CompleteRequests, |
1237 // that Request could not have been cancelled, so num_active_requests() | 1159 // that Request could not have been cancelled, so num_active_requests() |
1238 // could not be 0. Therefore, we are not in CompleteRequests(). | 1160 // could not be 0. Therefore, we are not in CompleteRequests(). |
1239 CompleteRequests(OK, AddressList(), base::TimeDelta()); | 1161 CompleteRequests(OK, AddressList(), base::TimeDelta()); |
1240 } | 1162 } |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1955 // Existing jobs will have been sent to the original server so they need to | 1877 // Existing jobs will have been sent to the original server so they need to |
1956 // be aborted. | 1878 // be aborted. |
1957 AbortAllInProgressJobs(); | 1879 AbortAllInProgressJobs(); |
1958 // |this| may be deleted inside AbortAllInProgressJobs(). | 1880 // |this| may be deleted inside AbortAllInProgressJobs(). |
1959 } | 1881 } |
1960 | 1882 |
1961 void HostResolverImpl::OnDnsConfigChanged(const DnsConfig& dns_config) { | 1883 void HostResolverImpl::OnDnsConfigChanged(const DnsConfig& dns_config) { |
1962 if (net_log_) { | 1884 if (net_log_) { |
1963 net_log_->AddGlobalEntry( | 1885 net_log_->AddGlobalEntry( |
1964 NetLog::TYPE_DNS_CONFIG_CHANGED, | 1886 NetLog::TYPE_DNS_CONFIG_CHANGED, |
1965 make_scoped_refptr(new DnsConfigParameters(dns_config))); | 1887 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
1966 } | 1888 } |
1967 | 1889 |
1968 // TODO(szym): Remove once http://crbug.com/125599 is resolved. | 1890 // TODO(szym): Remove once http://crbug.com/125599 is resolved. |
1969 received_dns_config_ = dns_config.IsValid(); | 1891 received_dns_config_ = dns_config.IsValid(); |
1970 | 1892 |
1971 // Life check to bail once |this| is deleted. | 1893 // Life check to bail once |this| is deleted. |
1972 base::WeakPtr<HostResolverImpl> self = AsWeakPtr(); | 1894 base::WeakPtr<HostResolverImpl> self = AsWeakPtr(); |
1973 | 1895 |
1974 if (dns_client_.get()) { | 1896 if (dns_client_.get()) { |
1975 // We want a new factory in place, before we Abort running Jobs, so that the | 1897 // We want a new factory in place, before we Abort running Jobs, so that the |
1976 // newly started jobs use the new factory. | 1898 // newly started jobs use the new factory. |
1977 dns_client_->SetConfig(dns_config); | 1899 dns_client_->SetConfig(dns_config); |
1978 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_SETTINGS); | 1900 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_SETTINGS); |
1979 // |this| may be deleted inside OnDNSChanged(). | 1901 // |this| may be deleted inside OnDNSChanged(). |
1980 if (self) | 1902 if (self) |
1981 TryServingAllJobsFromHosts(); | 1903 TryServingAllJobsFromHosts(); |
1982 } | 1904 } |
1983 } | 1905 } |
1984 | 1906 |
1985 bool HostResolverImpl::HaveDnsConfig() const { | 1907 bool HostResolverImpl::HaveDnsConfig() const { |
1986 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 1908 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
1987 } | 1909 } |
1988 | 1910 |
1989 } // namespace net | 1911 } // namespace net |
OLD | NEW |