| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <cmath> | 7 #include <cmath> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 CompletionCallback* callback_; | 148 CompletionCallback* callback_; |
| 149 | 149 |
| 150 // The address list to save result into. | 150 // The address list to save result into. |
| 151 AddressList* addresses_; | 151 AddressList* addresses_; |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(Request); | 153 DISALLOW_COPY_AND_ASSIGN(Request); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 //----------------------------------------------------------------------------- | 156 //----------------------------------------------------------------------------- |
| 157 | 157 |
| 158 // Threadsafe log. | |
| 159 class HostResolverImpl::RequestsTrace | |
| 160 : public base::RefCountedThreadSafe<HostResolverImpl::RequestsTrace> { | |
| 161 public: | |
| 162 RequestsTrace() {} | |
| 163 | |
| 164 void Add(const std::string& msg) { | |
| 165 CapturingNetLog::Entry entry(NetLog::TYPE_TODO_STRING, | |
| 166 base::TimeTicks::Now(), | |
| 167 NetLog::Source(), | |
| 168 NetLog::PHASE_NONE, | |
| 169 new NetLogStringParameter("todo", msg)); | |
| 170 AutoLock l(lock_); | |
| 171 entries_.push_back(entry); | |
| 172 } | |
| 173 | |
| 174 void Get(CapturingNetLog::EntryList* entries) { | |
| 175 AutoLock l(lock_); | |
| 176 *entries = entries_; | |
| 177 } | |
| 178 | |
| 179 void Clear() { | |
| 180 AutoLock l(lock_); | |
| 181 entries_.clear(); | |
| 182 } | |
| 183 | |
| 184 private: | |
| 185 Lock lock_; | |
| 186 CapturingNetLog::EntryList entries_; | |
| 187 }; | |
| 188 | |
| 189 //----------------------------------------------------------------------------- | |
| 190 | |
| 191 // This class represents a request to the worker pool for a "getaddrinfo()" | 158 // This class represents a request to the worker pool for a "getaddrinfo()" |
| 192 // call. | 159 // call. |
| 193 class HostResolverImpl::Job | 160 class HostResolverImpl::Job |
| 194 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { | 161 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { |
| 195 public: | 162 public: |
| 196 Job(int id, HostResolverImpl* resolver, const Key& key, | 163 Job(int id, HostResolverImpl* resolver, const Key& key) |
| 197 RequestsTrace* requests_trace) | |
| 198 : id_(id), | 164 : id_(id), |
| 199 key_(key), | 165 key_(key), |
| 200 resolver_(resolver), | 166 resolver_(resolver), |
| 201 origin_loop_(MessageLoop::current()), | 167 origin_loop_(MessageLoop::current()), |
| 202 resolver_proc_(resolver->effective_resolver_proc()), | 168 resolver_proc_(resolver->effective_resolver_proc()), |
| 203 requests_trace_(requests_trace), | |
| 204 error_(OK), | 169 error_(OK), |
| 205 had_non_speculative_request_(false) { | 170 had_non_speculative_request_(false) { |
| 206 if (requests_trace_) { | |
| 207 requests_trace_->Add(StringPrintf( | |
| 208 "Created job j%d for {hostname='%s', address_family=%d}", | |
| 209 id_, key.hostname.c_str(), | |
| 210 static_cast<int>(key.address_family))); | |
| 211 } | |
| 212 } | 171 } |
| 213 | 172 |
| 214 // Attaches a request to this job. The job takes ownership of |req| and will | 173 // Attaches a request to this job. The job takes ownership of |req| and will |
| 215 // take care to delete it. | 174 // take care to delete it. |
| 216 void AddRequest(Request* req) { | 175 void AddRequest(Request* req) { |
| 217 if (requests_trace_) { | |
| 218 requests_trace_->Add(StringPrintf( | |
| 219 "Attached request r%d to job j%d", req->id(), id_)); | |
| 220 } | |
| 221 | |
| 222 req->set_job(this); | 176 req->set_job(this); |
| 223 requests_.push_back(req); | 177 requests_.push_back(req); |
| 224 | 178 |
| 225 if (!req->info().is_speculative()) | 179 if (!req->info().is_speculative()) |
| 226 had_non_speculative_request_ = true; | 180 had_non_speculative_request_ = true; |
| 227 } | 181 } |
| 228 | 182 |
| 229 // Called from origin loop. | 183 // Called from origin loop. |
| 230 void Start() { | 184 void Start() { |
| 231 if (requests_trace_) | |
| 232 requests_trace_->Add(StringPrintf("Starting job j%d", id_)); | |
| 233 | |
| 234 start_time_ = base::TimeTicks::Now(); | 185 start_time_ = base::TimeTicks::Now(); |
| 235 | 186 |
| 236 // Dispatch the job to a worker thread. | 187 // Dispatch the job to a worker thread. |
| 237 if (!WorkerPool::PostTask(FROM_HERE, | 188 if (!WorkerPool::PostTask(FROM_HERE, |
| 238 NewRunnableMethod(this, &Job::DoLookup), true)) { | 189 NewRunnableMethod(this, &Job::DoLookup), true)) { |
| 239 NOTREACHED(); | 190 NOTREACHED(); |
| 240 | 191 |
| 241 // Since we could be running within Resolve() right now, we can't just | 192 // Since we could be running within Resolve() right now, we can't just |
| 242 // call OnLookupComplete(). Instead we must wait until Resolve() has | 193 // call OnLookupComplete(). Instead we must wait until Resolve() has |
| 243 // returned (IO_PENDING). | 194 // returned (IO_PENDING). |
| 244 error_ = ERR_UNEXPECTED; | 195 error_ = ERR_UNEXPECTED; |
| 245 MessageLoop::current()->PostTask( | 196 MessageLoop::current()->PostTask( |
| 246 FROM_HERE, NewRunnableMethod(this, &Job::OnLookupComplete)); | 197 FROM_HERE, NewRunnableMethod(this, &Job::OnLookupComplete)); |
| 247 } | 198 } |
| 248 } | 199 } |
| 249 | 200 |
| 250 // Cancels the current job. Callable from origin thread. | 201 // Cancels the current job. Callable from origin thread. |
| 251 void Cancel() { | 202 void Cancel() { |
| 252 HostResolver* resolver = resolver_; | 203 HostResolver* resolver = resolver_; |
| 253 resolver_ = NULL; | 204 resolver_ = NULL; |
| 254 | 205 |
| 255 if (requests_trace_) | |
| 256 requests_trace_->Add(StringPrintf("Cancelled job j%d", id_)); | |
| 257 | |
| 258 // Mark the job as cancelled, so when worker thread completes it will | 206 // Mark the job as cancelled, so when worker thread completes it will |
| 259 // not try to post completion to origin loop. | 207 // not try to post completion to origin loop. |
| 260 { | 208 { |
| 261 AutoLock locked(origin_loop_lock_); | 209 AutoLock locked(origin_loop_lock_); |
| 262 origin_loop_ = NULL; | 210 origin_loop_ = NULL; |
| 263 } | 211 } |
| 264 | 212 |
| 265 // We will call HostResolverImpl::CancelRequest(Request*) on each one | 213 // We will call HostResolverImpl::CancelRequest(Request*) on each one |
| 266 // in order to notify any observers. | 214 // in order to notify any observers. |
| 267 for (RequestsList::const_iterator it = requests_.begin(); | 215 for (RequestsList::const_iterator it = requests_.begin(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 ~Job() { | 261 ~Job() { |
| 314 // Free the requests attached to this job. | 262 // Free the requests attached to this job. |
| 315 STLDeleteElements(&requests_); | 263 STLDeleteElements(&requests_); |
| 316 } | 264 } |
| 317 | 265 |
| 318 // WARNING: This code runs inside a worker pool. The shutdown code cannot | 266 // WARNING: This code runs inside a worker pool. The shutdown code cannot |
| 319 // wait for it to finish, so we must be very careful here about using other | 267 // wait for it to finish, so we must be very careful here about using other |
| 320 // objects (like MessageLoops, Singletons, etc). During shutdown these objects | 268 // objects (like MessageLoops, Singletons, etc). During shutdown these objects |
| 321 // may no longer exist. | 269 // may no longer exist. |
| 322 void DoLookup() { | 270 void DoLookup() { |
| 323 if (requests_trace_) { | |
| 324 requests_trace_->Add(StringPrintf( | |
| 325 "[resolver thread] Running job j%d", id_)); | |
| 326 } | |
| 327 | |
| 328 // Running on the worker thread | 271 // Running on the worker thread |
| 329 error_ = ResolveAddrInfo(resolver_proc_, | 272 error_ = ResolveAddrInfo(resolver_proc_, |
| 330 key_.hostname, | 273 key_.hostname, |
| 331 key_.address_family, | 274 key_.address_family, |
| 332 key_.host_resolver_flags, | 275 key_.host_resolver_flags, |
| 333 &results_); | 276 &results_); |
| 334 | 277 |
| 335 if (requests_trace_) { | |
| 336 requests_trace_->Add(StringPrintf( | |
| 337 "[resolver thread] Completed job j%d", id_)); | |
| 338 } | |
| 339 | |
| 340 // The origin loop could go away while we are trying to post to it, so we | 278 // The origin loop could go away while we are trying to post to it, so we |
| 341 // need to call its PostTask method inside a lock. See ~HostResolver. | 279 // need to call its PostTask method inside a lock. See ~HostResolver. |
| 342 { | 280 { |
| 343 AutoLock locked(origin_loop_lock_); | 281 AutoLock locked(origin_loop_lock_); |
| 344 if (origin_loop_) { | 282 if (origin_loop_) { |
| 345 origin_loop_->PostTask(FROM_HERE, | 283 origin_loop_->PostTask(FROM_HERE, |
| 346 NewRunnableMethod(this, &Job::OnLookupComplete)); | 284 NewRunnableMethod(this, &Job::OnLookupComplete)); |
| 347 } | 285 } |
| 348 } | 286 } |
| 349 } | 287 } |
| 350 | 288 |
| 351 // Callback for when DoLookup() completes (runs on origin thread). | 289 // Callback for when DoLookup() completes (runs on origin thread). |
| 352 void OnLookupComplete() { | 290 void OnLookupComplete() { |
| 353 // Should be running on origin loop. | 291 // Should be running on origin loop. |
| 354 // TODO(eroman): this is being hit by URLRequestTest.CancelTest*, | 292 // TODO(eroman): this is being hit by URLRequestTest.CancelTest*, |
| 355 // because MessageLoop::current() == NULL. | 293 // because MessageLoop::current() == NULL. |
| 356 //DCHECK_EQ(origin_loop_, MessageLoop::current()); | 294 //DCHECK_EQ(origin_loop_, MessageLoop::current()); |
| 357 DCHECK(error_ || results_.head()); | 295 DCHECK(error_ || results_.head()); |
| 358 | 296 |
| 359 base::TimeDelta job_duration = base::TimeTicks::Now() - start_time_; | 297 base::TimeDelta job_duration = base::TimeTicks::Now() - start_time_; |
| 360 | 298 |
| 361 if (requests_trace_) { | |
| 362 requests_trace_->Add(StringPrintf( | |
| 363 "Completing job j%d (took %d milliseconds)", | |
| 364 id_, | |
| 365 static_cast<int>(job_duration.InMilliseconds()))); | |
| 366 } | |
| 367 | |
| 368 if (had_non_speculative_request_) { | 299 if (had_non_speculative_request_) { |
| 369 // TODO(eroman): Add histogram for job times of non-speculative | 300 // TODO(eroman): Add histogram for job times of non-speculative |
| 370 // requests. | 301 // requests. |
| 371 } | 302 } |
| 372 | 303 |
| 373 | 304 |
| 374 if (was_cancelled()) | 305 if (was_cancelled()) |
| 375 return; | 306 return; |
| 376 | 307 |
| 377 DCHECK(!requests_.empty()); | 308 DCHECK(!requests_.empty()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 396 // Used to post ourselves onto the origin thread. | 327 // Used to post ourselves onto the origin thread. |
| 397 Lock origin_loop_lock_; | 328 Lock origin_loop_lock_; |
| 398 MessageLoop* origin_loop_; | 329 MessageLoop* origin_loop_; |
| 399 | 330 |
| 400 // Hold an owning reference to the HostResolverProc that we are going to use. | 331 // Hold an owning reference to the HostResolverProc that we are going to use. |
| 401 // This may not be the current resolver procedure by the time we call | 332 // This may not be the current resolver procedure by the time we call |
| 402 // ResolveAddrInfo, but that's OK... we'll use it anyways, and the owning | 333 // ResolveAddrInfo, but that's OK... we'll use it anyways, and the owning |
| 403 // reference ensures that it remains valid until we are done. | 334 // reference ensures that it remains valid until we are done. |
| 404 scoped_refptr<HostResolverProc> resolver_proc_; | 335 scoped_refptr<HostResolverProc> resolver_proc_; |
| 405 | 336 |
| 406 // Thread safe log to write details into, or NULL. | |
| 407 scoped_refptr<RequestsTrace> requests_trace_; | |
| 408 | |
| 409 // Assigned on the worker thread, read on the origin thread. | 337 // Assigned on the worker thread, read on the origin thread. |
| 410 int error_; | 338 int error_; |
| 411 | 339 |
| 412 // True if a non-speculative request was ever attached to this job | 340 // True if a non-speculative request was ever attached to this job |
| 413 // (regardless of whether or not it was later cancelled. | 341 // (regardless of whether or not it was later cancelled. |
| 414 // This boolean is used for histogramming the duration of jobs used to | 342 // This boolean is used for histogramming the duration of jobs used to |
| 415 // service non-speculative requests. | 343 // service non-speculative requests. |
| 416 bool had_non_speculative_request_; | 344 bool had_non_speculative_request_; |
| 417 | 345 |
| 418 AddressList results_; | 346 AddressList results_; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 void HostResolverImpl::Shutdown() { | 789 void HostResolverImpl::Shutdown() { |
| 862 shutdown_ = true; | 790 shutdown_ = true; |
| 863 | 791 |
| 864 // Cancel the outstanding jobs. | 792 // Cancel the outstanding jobs. |
| 865 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 793 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 866 it->second->Cancel(); | 794 it->second->Cancel(); |
| 867 jobs_.clear(); | 795 jobs_.clear(); |
| 868 DiscardIPv6ProbeJob(); | 796 DiscardIPv6ProbeJob(); |
| 869 } | 797 } |
| 870 | 798 |
| 871 void HostResolverImpl::ClearRequestsTrace() { | |
| 872 if (requests_trace_) | |
| 873 requests_trace_->Clear(); | |
| 874 } | |
| 875 | |
| 876 void HostResolverImpl::EnableRequestsTracing(bool enable) { | |
| 877 requests_trace_ = enable ? new RequestsTrace : NULL; | |
| 878 if (enable) { | |
| 879 // Print the state of the world when logging was started. | |
| 880 requests_trace_->Add("Enabled tracing"); | |
| 881 requests_trace_->Add(StringPrintf( | |
| 882 "Current num outstanding jobs: %d", | |
| 883 static_cast<int>(jobs_.size()))); | |
| 884 | |
| 885 // Dump all of the outstanding jobs. | |
| 886 if (!jobs_.empty()) { | |
| 887 for (JobMap::iterator job_it = jobs_.begin(); | |
| 888 job_it != jobs_.end(); ++job_it) { | |
| 889 Job* job = job_it->second; | |
| 890 | |
| 891 requests_trace_->Add(StringPrintf( | |
| 892 "Outstanding job j%d for {host='%s', address_family=%d}, " | |
| 893 "which was started at t=%d", | |
| 894 job->id(), | |
| 895 job->key().hostname.c_str(), | |
| 896 static_cast<int>(job->key().address_family), | |
| 897 static_cast<int>((job->start_time() - base::TimeTicks()) | |
| 898 .InMilliseconds()))); | |
| 899 | |
| 900 // Dump all of the requests attached to this job. | |
| 901 for (RequestsList::const_iterator req_it = job->requests().begin(); | |
| 902 req_it != job->requests().end(); ++req_it) { | |
| 903 Request* req = *req_it; | |
| 904 requests_trace_->Add(StringPrintf( | |
| 905 " %sOutstanding request r%d is attached to job j%d " | |
| 906 "{priority=%d, speculative=%d, referrer='%s'}", | |
| 907 req->was_cancelled() ? "[CANCELLED] " : "", | |
| 908 req->id(), | |
| 909 job->id(), | |
| 910 static_cast<int>(req->info().priority()), | |
| 911 static_cast<int>(req->info().is_speculative()), | |
| 912 req->info().referrer().spec().c_str())); | |
| 913 } | |
| 914 } | |
| 915 } | |
| 916 | |
| 917 size_t total = 0u; | |
| 918 for (size_t i = 0; i < arraysize(job_pools_); ++i) | |
| 919 total += job_pools_[i]->GetNumPendingRequests(); | |
| 920 | |
| 921 requests_trace_->Add(StringPrintf( | |
| 922 "Number of queued requests: %d", static_cast<int>(total))); | |
| 923 } | |
| 924 } | |
| 925 | |
| 926 bool HostResolverImpl::IsRequestsTracingEnabled() const { | |
| 927 return !!requests_trace_; // Cast to bool. | |
| 928 } | |
| 929 | |
| 930 bool HostResolverImpl::GetRequestsTrace(CapturingNetLog::EntryList* entries) { | |
| 931 if (!requests_trace_) | |
| 932 return false; | |
| 933 requests_trace_->Get(entries); | |
| 934 return true; | |
| 935 } | |
| 936 | |
| 937 void HostResolverImpl::SetPoolConstraints(JobPoolIndex pool_index, | 799 void HostResolverImpl::SetPoolConstraints(JobPoolIndex pool_index, |
| 938 size_t max_outstanding_jobs, | 800 size_t max_outstanding_jobs, |
| 939 size_t max_pending_requests) { | 801 size_t max_pending_requests) { |
| 940 CHECK_GE(pool_index, 0); | 802 CHECK_GE(pool_index, 0); |
| 941 CHECK_LT(pool_index, POOL_COUNT); | 803 CHECK_LT(pool_index, POOL_COUNT); |
| 942 CHECK(jobs_.empty()) << "Can only set constraints during setup"; | 804 CHECK(jobs_.empty()) << "Can only set constraints during setup"; |
| 943 JobPool* pool = job_pools_[pool_index]; | 805 JobPool* pool = job_pools_[pool_index]; |
| 944 pool->SetConstraints(max_outstanding_jobs, max_pending_requests); | 806 pool->SetConstraints(max_outstanding_jobs, max_pending_requests); |
| 945 } | 807 } |
| 946 | 808 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 } | 869 } |
| 1008 | 870 |
| 1009 cur_completing_job_ = NULL; | 871 cur_completing_job_ = NULL; |
| 1010 } | 872 } |
| 1011 | 873 |
| 1012 void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log, | 874 void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log, |
| 1013 int request_id, | 875 int request_id, |
| 1014 const RequestInfo& info) { | 876 const RequestInfo& info) { |
| 1015 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | 877 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); |
| 1016 | 878 |
| 1017 if (requests_trace_) { | |
| 1018 requests_trace_->Add(StringPrintf( | |
| 1019 "Received request r%d for {hostname='%s', port=%d, priority=%d, " | |
| 1020 "speculative=%d, address_family=%d, allow_cached=%d, referrer='%s'}", | |
| 1021 request_id, | |
| 1022 info.hostname().c_str(), | |
| 1023 info.port(), | |
| 1024 static_cast<int>(info.priority()), | |
| 1025 static_cast<int>(info.is_speculative()), | |
| 1026 static_cast<int>(info.address_family()), | |
| 1027 static_cast<int>(info.allow_cached_response()), | |
| 1028 info.referrer().spec().c_str())); | |
| 1029 } | |
| 1030 | |
| 1031 // Notify the observers of the start. | 879 // Notify the observers of the start. |
| 1032 if (!observers_.empty()) { | 880 if (!observers_.empty()) { |
| 1033 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL); | 881 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL); |
| 1034 | 882 |
| 1035 for (ObserversList::iterator it = observers_.begin(); | 883 for (ObserversList::iterator it = observers_.begin(); |
| 1036 it != observers_.end(); ++it) { | 884 it != observers_.end(); ++it) { |
| 1037 (*it)->OnStartResolution(request_id, info); | 885 (*it)->OnStartResolution(request_id, info); |
| 1038 } | 886 } |
| 1039 | 887 |
| 1040 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL); | 888 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL); |
| 1041 } | 889 } |
| 1042 } | 890 } |
| 1043 | 891 |
| 1044 void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log, | 892 void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log, |
| 1045 int request_id, | 893 int request_id, |
| 1046 const RequestInfo& info, | 894 const RequestInfo& info, |
| 1047 int error) { | 895 int error) { |
| 1048 if (requests_trace_) { | |
| 1049 requests_trace_->Add(StringPrintf( | |
| 1050 "Finished request r%d with error=%d", request_id, error)); | |
| 1051 } | |
| 1052 | |
| 1053 // Notify the observers of the completion. | 896 // Notify the observers of the completion. |
| 1054 if (!observers_.empty()) { | 897 if (!observers_.empty()) { |
| 1055 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL); | 898 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL); |
| 1056 | 899 |
| 1057 bool was_resolved = error == OK; | 900 bool was_resolved = error == OK; |
| 1058 for (ObserversList::iterator it = observers_.begin(); | 901 for (ObserversList::iterator it = observers_.begin(); |
| 1059 it != observers_.end(); ++it) { | 902 it != observers_.end(); ++it) { |
| 1060 (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); | 903 (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); |
| 1061 } | 904 } |
| 1062 | 905 |
| 1063 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL); | 906 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL); |
| 1064 } | 907 } |
| 1065 | 908 |
| 1066 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | 909 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); |
| 1067 } | 910 } |
| 1068 | 911 |
| 1069 void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log, | 912 void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log, |
| 1070 int request_id, | 913 int request_id, |
| 1071 const RequestInfo& info) { | 914 const RequestInfo& info) { |
| 1072 net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); | 915 net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 1073 | 916 |
| 1074 if (requests_trace_) | |
| 1075 requests_trace_->Add(StringPrintf("Cancelled request r%d", request_id)); | |
| 1076 | |
| 1077 // Notify the observers of the cancellation. | 917 // Notify the observers of the cancellation. |
| 1078 if (!observers_.empty()) { | 918 if (!observers_.empty()) { |
| 1079 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL); | 919 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL); |
| 1080 | 920 |
| 1081 for (ObserversList::iterator it = observers_.begin(); | 921 for (ObserversList::iterator it = observers_.begin(); |
| 1082 it != observers_.end(); ++it) { | 922 it != observers_.end(); ++it) { |
| 1083 (*it)->OnCancelResolution(request_id, info); | 923 (*it)->OnCancelResolution(request_id, info); |
| 1084 } | 924 } |
| 1085 | 925 |
| 1086 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL); | 926 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 AddressFamily effective_address_family = info.address_family(); | 1009 AddressFamily effective_address_family = info.address_family(); |
| 1170 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) | 1010 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) |
| 1171 effective_address_family = default_address_family_; | 1011 effective_address_family = default_address_family_; |
| 1172 return Key(info.hostname(), effective_address_family, | 1012 return Key(info.hostname(), effective_address_family, |
| 1173 info.host_resolver_flags()); | 1013 info.host_resolver_flags()); |
| 1174 } | 1014 } |
| 1175 | 1015 |
| 1176 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { | 1016 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { |
| 1177 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); | 1017 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); |
| 1178 Key key = GetEffectiveKeyForRequest(req->info()); | 1018 Key key = GetEffectiveKeyForRequest(req->info()); |
| 1179 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_); | 1019 scoped_refptr<Job> job = new Job(next_job_id_++, this, key); |
| 1180 job->AddRequest(req); | 1020 job->AddRequest(req); |
| 1181 AddOutstandingJob(job); | 1021 AddOutstandingJob(job); |
| 1182 job->Start(); | 1022 job->Start(); |
| 1183 return job.get(); | 1023 return job.get(); |
| 1184 } | 1024 } |
| 1185 | 1025 |
| 1186 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { | 1026 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { |
| 1187 if (requests_trace_) | |
| 1188 requests_trace_->Add(StringPrintf("Queued request r%d", req->id())); | |
| 1189 | |
| 1190 scoped_ptr<Request> req_evicted_from_queue( | 1027 scoped_ptr<Request> req_evicted_from_queue( |
| 1191 pool->InsertPendingRequest(req)); | 1028 pool->InsertPendingRequest(req)); |
| 1192 | 1029 |
| 1193 // If the queue has become too large, we need to kick something out. | 1030 // If the queue has become too large, we need to kick something out. |
| 1194 if (req_evicted_from_queue.get()) { | 1031 if (req_evicted_from_queue.get()) { |
| 1195 Request* r = req_evicted_from_queue.get(); | 1032 Request* r = req_evicted_from_queue.get(); |
| 1196 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1033 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
| 1197 | 1034 |
| 1198 if (requests_trace_) | |
| 1199 requests_trace_->Add(StringPrintf("Evicted request r%d", r->id())); | |
| 1200 | |
| 1201 OnFinishRequest(r->net_log(), r->id(), r->info(), error); | 1035 OnFinishRequest(r->net_log(), r->id(), r->info(), error); |
| 1202 | 1036 |
| 1203 if (r == req) | 1037 if (r == req) |
| 1204 return error; | 1038 return error; |
| 1205 | 1039 |
| 1206 r->OnComplete(error, AddressList()); | 1040 r->OnComplete(error, AddressList()); |
| 1207 } | 1041 } |
| 1208 | 1042 |
| 1209 return ERR_IO_PENDING; | 1043 return ERR_IO_PENDING; |
| 1210 } | 1044 } |
| 1211 | 1045 |
| 1212 } // namespace net | 1046 } // namespace net |
| OLD | NEW |