| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "net/base/net_log.h" |
| 6 | 7 |
| 7 #include <cmath> | 8 #include <cmath> |
| 8 #include <deque> | 9 #include <deque> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "base/debug_util.h" | 13 #include "base/debug_util.h" |
| 13 #include "base/lock.h" | 14 #include "base/lock.h" |
| 14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 15 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/worker_pool.h" | 19 #include "base/worker_pool.h" |
| 19 #include "net/base/address_list.h" | 20 #include "net/base/address_list.h" |
| 20 #include "net/base/host_resolver_proc.h" | 21 #include "net/base/host_resolver_proc.h" |
| 21 #include "net/base/load_log.h" | 22 #include "net/base/net_log.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" |
| 24 | 25 |
| 25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 26 #include "net/base/winsock_init.h" | 27 #include "net/base/winsock_init.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } else { | 66 } else { |
| 66 // Use the system procedure (getaddrinfo). | 67 // Use the system procedure (getaddrinfo). |
| 67 return SystemHostResolverProc(host, address_family, out); | 68 return SystemHostResolverProc(host, address_family, out); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 //----------------------------------------------------------------------------- | 72 //----------------------------------------------------------------------------- |
| 72 | 73 |
| 73 class HostResolverImpl::Request { | 74 class HostResolverImpl::Request { |
| 74 public: | 75 public: |
| 75 Request(LoadLog* load_log, | 76 Request(const BoundNetLog& net_log, |
| 76 int id, | 77 int id, |
| 77 const RequestInfo& info, | 78 const RequestInfo& info, |
| 78 CompletionCallback* callback, | 79 CompletionCallback* callback, |
| 79 AddressList* addresses) | 80 AddressList* addresses) |
| 80 : load_log_(load_log), | 81 : net_log_(net_log), |
| 81 id_(id), | 82 id_(id), |
| 82 info_(info), | 83 info_(info), |
| 83 job_(NULL), | 84 job_(NULL), |
| 84 callback_(callback), | 85 callback_(callback), |
| 85 addresses_(addresses) { | 86 addresses_(addresses) { |
| 86 } | 87 } |
| 87 | 88 |
| 88 // Mark the request as cancelled. | 89 // Mark the request as cancelled. |
| 89 void MarkAsCancelled() { | 90 void MarkAsCancelled() { |
| 90 job_ = NULL; | 91 job_ = NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 109 } | 110 } |
| 110 | 111 |
| 111 int port() const { | 112 int port() const { |
| 112 return info_.port(); | 113 return info_.port(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 Job* job() const { | 116 Job* job() const { |
| 116 return job_; | 117 return job_; |
| 117 } | 118 } |
| 118 | 119 |
| 119 LoadLog* load_log() const { | 120 const BoundNetLog& net_log() { |
| 120 return load_log_; | 121 return net_log_; |
| 121 } | 122 } |
| 122 | 123 |
| 123 int id() const { | 124 int id() const { |
| 124 return id_; | 125 return id_; |
| 125 } | 126 } |
| 126 | 127 |
| 127 const RequestInfo& info() const { | 128 const RequestInfo& info() const { |
| 128 return info_; | 129 return info_; |
| 129 } | 130 } |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 scoped_refptr<LoadLog> load_log_; | 133 BoundNetLog net_log_; |
| 133 | 134 |
| 134 // Unique ID for this request. Used by observers to identify requests. | 135 // Unique ID for this request. Used by observers to identify requests. |
| 135 int id_; | 136 int id_; |
| 136 | 137 |
| 137 // The request info that started the request. | 138 // The request info that started the request. |
| 138 RequestInfo info_; | 139 RequestInfo info_; |
| 139 | 140 |
| 140 // The resolve job (running in worker pool) that this request is dependent on. | 141 // The resolve job (running in worker pool) that this request is dependent on. |
| 141 Job* job_; | 142 Job* job_; |
| 142 | 143 |
| 143 // The user's callback to invoke when the request completes. | 144 // The user's callback to invoke when the request completes. |
| 144 CompletionCallback* callback_; | 145 CompletionCallback* callback_; |
| 145 | 146 |
| 146 // The address list to save result into. | 147 // The address list to save result into. |
| 147 AddressList* addresses_; | 148 AddressList* addresses_; |
| 148 | 149 |
| 149 DISALLOW_COPY_AND_ASSIGN(Request); | 150 DISALLOW_COPY_AND_ASSIGN(Request); |
| 150 }; | 151 }; |
| 151 | 152 |
| 152 //----------------------------------------------------------------------------- | 153 //----------------------------------------------------------------------------- |
| 153 | 154 |
| 154 // Threadsafe log. | 155 // Threadsafe log. |
| 155 class HostResolverImpl::RequestsTrace | 156 class HostResolverImpl::RequestsTrace |
| 156 : public base::RefCountedThreadSafe<HostResolverImpl::RequestsTrace> { | 157 : public base::RefCountedThreadSafe<HostResolverImpl::RequestsTrace> { |
| 157 public: | 158 public: |
| 158 RequestsTrace() : log_(new LoadLog(LoadLog::kUnbounded)) {} | 159 RequestsTrace() {} |
| 159 | 160 |
| 160 void Add(const std::string& msg) { | 161 void Add(const std::string& msg) { |
| 162 NetLog::Entry entry; |
| 163 entry.type = NetLog::Entry::TYPE_STRING; |
| 164 entry.time = base::TimeTicks::Now(); |
| 165 entry.string = msg; |
| 166 |
| 161 AutoLock l(lock_); | 167 AutoLock l(lock_); |
| 162 LoadLog::AddString(log_, msg); | 168 entries_.push_back(entry); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void Get(LoadLog* out) { | 171 void Get(std::vector<NetLog::Entry>* entries) { |
| 166 AutoLock l(lock_); | 172 AutoLock l(lock_); |
| 167 out->Append(log_); | 173 *entries = entries_; |
| 168 } | 174 } |
| 169 | 175 |
| 170 void Clear() { | 176 void Clear() { |
| 171 AutoLock l(lock_); | 177 AutoLock l(lock_); |
| 172 log_ = new LoadLog(LoadLog::kUnbounded); | 178 entries_.clear(); |
| 173 } | 179 } |
| 174 | 180 |
| 175 private: | 181 private: |
| 176 Lock lock_; | 182 Lock lock_; |
| 177 scoped_refptr<LoadLog> log_; | 183 std::vector<NetLog::Entry> entries_; |
| 178 }; | 184 }; |
| 179 | 185 |
| 180 //----------------------------------------------------------------------------- | 186 //----------------------------------------------------------------------------- |
| 181 | 187 |
| 182 // This class represents a request to the worker pool for a "getaddrinfo()" | 188 // This class represents a request to the worker pool for a "getaddrinfo()" |
| 183 // call. | 189 // call. |
| 184 class HostResolverImpl::Job | 190 class HostResolverImpl::Job |
| 185 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { | 191 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { |
| 186 public: | 192 public: |
| 187 Job(int id, HostResolverImpl* resolver, const Key& key, | 193 Job(int id, HostResolverImpl* resolver, const Key& key, |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 612 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
| 607 delete job_pools_[i]; | 613 delete job_pools_[i]; |
| 608 } | 614 } |
| 609 | 615 |
| 610 // TODO(eroman): Don't create cache entries for hostnames which are simply IP | 616 // TODO(eroman): Don't create cache entries for hostnames which are simply IP |
| 611 // address literals. | 617 // address literals. |
| 612 int HostResolverImpl::Resolve(const RequestInfo& info, | 618 int HostResolverImpl::Resolve(const RequestInfo& info, |
| 613 AddressList* addresses, | 619 AddressList* addresses, |
| 614 CompletionCallback* callback, | 620 CompletionCallback* callback, |
| 615 RequestHandle* out_req, | 621 RequestHandle* out_req, |
| 616 LoadLog* load_log) { | 622 const BoundNetLog& net_log) { |
| 617 if (shutdown_) | 623 if (shutdown_) |
| 618 return ERR_UNEXPECTED; | 624 return ERR_UNEXPECTED; |
| 619 | 625 |
| 620 // Choose a unique ID number for observers to see. | 626 // Choose a unique ID number for observers to see. |
| 621 int request_id = next_request_id_++; | 627 int request_id = next_request_id_++; |
| 622 | 628 |
| 623 // Update the load log and notify registered observers. | 629 // Update the net log and notify registered observers. |
| 624 OnStartRequest(load_log, request_id, info); | 630 OnStartRequest(net_log, request_id, info); |
| 625 | 631 |
| 626 // Build a key that identifies the request in the cache and in the | 632 // Build a key that identifies the request in the cache and in the |
| 627 // outstanding jobs map. | 633 // outstanding jobs map. |
| 628 Key key = GetEffectiveKeyForRequest(info); | 634 Key key = GetEffectiveKeyForRequest(info); |
| 629 | 635 |
| 630 // If we have an unexpired cache entry, use it. | 636 // If we have an unexpired cache entry, use it. |
| 631 if (info.allow_cached_response() && cache_.get()) { | 637 if (info.allow_cached_response() && cache_.get()) { |
| 632 const HostCache::Entry* cache_entry = cache_->Lookup( | 638 const HostCache::Entry* cache_entry = cache_->Lookup( |
| 633 key, base::TimeTicks::Now()); | 639 key, base::TimeTicks::Now()); |
| 634 if (cache_entry) { | 640 if (cache_entry) { |
| 635 int error = cache_entry->error; | 641 int error = cache_entry->error; |
| 636 if (error == OK) | 642 if (error == OK) |
| 637 addresses->SetFrom(cache_entry->addrlist, info.port()); | 643 addresses->SetFrom(cache_entry->addrlist, info.port()); |
| 638 | 644 |
| 639 // Update the load log and notify registered observers. | 645 // Update the net log and notify registered observers. |
| 640 OnFinishRequest(load_log, request_id, info, error); | 646 OnFinishRequest(net_log, request_id, info, error); |
| 641 | 647 |
| 642 return error; | 648 return error; |
| 643 } | 649 } |
| 644 } | 650 } |
| 645 | 651 |
| 646 // If no callback was specified, do a synchronous resolution. | 652 // If no callback was specified, do a synchronous resolution. |
| 647 if (!callback) { | 653 if (!callback) { |
| 648 AddressList addrlist; | 654 AddressList addrlist; |
| 649 int error = ResolveAddrInfo( | 655 int error = ResolveAddrInfo( |
| 650 effective_resolver_proc(), key.hostname, key.address_family, &addrlist); | 656 effective_resolver_proc(), key.hostname, key.address_family, &addrlist); |
| 651 if (error == OK) { | 657 if (error == OK) { |
| 652 addrlist.SetPort(info.port()); | 658 addrlist.SetPort(info.port()); |
| 653 *addresses = addrlist; | 659 *addresses = addrlist; |
| 654 } | 660 } |
| 655 | 661 |
| 656 // Write to cache. | 662 // Write to cache. |
| 657 if (cache_.get()) | 663 if (cache_.get()) |
| 658 cache_->Set(key, error, addrlist, base::TimeTicks::Now()); | 664 cache_->Set(key, error, addrlist, base::TimeTicks::Now()); |
| 659 | 665 |
| 660 // Update the load log and notify registered observers. | 666 // Update the net log and notify registered observers. |
| 661 OnFinishRequest(load_log, request_id, info, error); | 667 OnFinishRequest(net_log, request_id, info, error); |
| 662 | 668 |
| 663 return error; | 669 return error; |
| 664 } | 670 } |
| 665 | 671 |
| 666 // Create a handle for this request, and pass it back to the user if they | 672 // Create a handle for this request, and pass it back to the user if they |
| 667 // asked for it (out_req != NULL). | 673 // asked for it (out_req != NULL). |
| 668 Request* req = new Request(load_log, request_id, info, callback, addresses); | 674 Request* req = new Request(net_log, request_id, info, callback, addresses); |
| 669 if (out_req) | 675 if (out_req) |
| 670 *out_req = reinterpret_cast<RequestHandle>(req); | 676 *out_req = reinterpret_cast<RequestHandle>(req); |
| 671 | 677 |
| 672 // Next we need to attach our request to a "job". This job is responsible for | 678 // Next we need to attach our request to a "job". This job is responsible for |
| 673 // calling "getaddrinfo(hostname)" on a worker thread. | 679 // calling "getaddrinfo(hostname)" on a worker thread. |
| 674 scoped_refptr<Job> job; | 680 scoped_refptr<Job> job; |
| 675 | 681 |
| 676 // If there is already an outstanding job to resolve |key|, use | 682 // If there is already an outstanding job to resolve |key|, use |
| 677 // it. This prevents starting concurrent resolves for the same hostname. | 683 // it. This prevents starting concurrent resolves for the same hostname. |
| 678 job = FindOutstandingJob(key); | 684 job = FindOutstandingJob(key); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 // enqueued into a pool. Remove it from that pool's queue. | 718 // enqueued into a pool. Remove it from that pool's queue. |
| 713 // Otherwise if it was attached to a job, the job is responsible for | 719 // Otherwise if it was attached to a job, the job is responsible for |
| 714 // deleting it. | 720 // deleting it. |
| 715 JobPool* pool = GetPoolForRequest(req); | 721 JobPool* pool = GetPoolForRequest(req); |
| 716 pool->RemovePendingRequest(req); | 722 pool->RemovePendingRequest(req); |
| 717 request_deleter.reset(req); | 723 request_deleter.reset(req); |
| 718 } | 724 } |
| 719 | 725 |
| 720 // NULL out the fields of req, to mark it as cancelled. | 726 // NULL out the fields of req, to mark it as cancelled. |
| 721 req->MarkAsCancelled(); | 727 req->MarkAsCancelled(); |
| 722 OnCancelRequest(req->load_log(), req->id(), req->info()); | 728 OnCancelRequest(req->net_log(), req->id(), req->info()); |
| 723 } | 729 } |
| 724 | 730 |
| 725 void HostResolverImpl::AddObserver(HostResolver::Observer* observer) { | 731 void HostResolverImpl::AddObserver(HostResolver::Observer* observer) { |
| 726 observers_.push_back(observer); | 732 observers_.push_back(observer); |
| 727 } | 733 } |
| 728 | 734 |
| 729 void HostResolverImpl::RemoveObserver(HostResolver::Observer* observer) { | 735 void HostResolverImpl::RemoveObserver(HostResolver::Observer* observer) { |
| 730 ObserversList::iterator it = | 736 ObserversList::iterator it = |
| 731 std::find(observers_.begin(), observers_.end(), observer); | 737 std::find(observers_.begin(), observers_.end(), observer); |
| 732 | 738 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 803 |
| 798 requests_trace_->Add(StringPrintf( | 804 requests_trace_->Add(StringPrintf( |
| 799 "Number of queued requests: %d", static_cast<int>(total))); | 805 "Number of queued requests: %d", static_cast<int>(total))); |
| 800 } | 806 } |
| 801 } | 807 } |
| 802 | 808 |
| 803 bool HostResolverImpl::IsRequestsTracingEnabled() const { | 809 bool HostResolverImpl::IsRequestsTracingEnabled() const { |
| 804 return !!requests_trace_; // Cast to bool. | 810 return !!requests_trace_; // Cast to bool. |
| 805 } | 811 } |
| 806 | 812 |
| 807 scoped_refptr<LoadLog> HostResolverImpl::GetRequestsTrace() { | 813 bool HostResolverImpl::GetRequestsTrace(std::vector<NetLog::Entry>* entries) { |
| 808 if (!requests_trace_) | 814 if (!requests_trace_) |
| 809 return NULL; | 815 return false; |
| 810 | 816 requests_trace_->Get(entries); |
| 811 scoped_refptr<LoadLog> copy_of_log = new LoadLog(LoadLog::kUnbounded); | 817 return true; |
| 812 requests_trace_->Get(copy_of_log); | |
| 813 return copy_of_log; | |
| 814 } | 818 } |
| 815 | 819 |
| 816 void HostResolverImpl::SetPoolConstraints(JobPoolIndex pool_index, | 820 void HostResolverImpl::SetPoolConstraints(JobPoolIndex pool_index, |
| 817 size_t max_outstanding_jobs, | 821 size_t max_outstanding_jobs, |
| 818 size_t max_pending_requests) { | 822 size_t max_pending_requests) { |
| 819 CHECK_GE(pool_index, 0); | 823 CHECK_GE(pool_index, 0); |
| 820 CHECK_LT(pool_index, POOL_COUNT); | 824 CHECK_LT(pool_index, POOL_COUNT); |
| 821 CHECK(jobs_.empty()) << "Can only set constraints during setup"; | 825 CHECK(jobs_.empty()) << "Can only set constraints during setup"; |
| 822 JobPool* pool = job_pools_[pool_index]; | 826 JobPool* pool = job_pools_[pool_index]; |
| 823 pool->SetConstraints(max_outstanding_jobs, max_pending_requests); | 827 pool->SetConstraints(max_outstanding_jobs, max_pending_requests); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 // Try to start any queued requests now that a job-slot has freed up. | 870 // Try to start any queued requests now that a job-slot has freed up. |
| 867 ProcessQueuedRequests(); | 871 ProcessQueuedRequests(); |
| 868 | 872 |
| 869 // Complete all of the requests that were attached to the job. | 873 // Complete all of the requests that were attached to the job. |
| 870 for (RequestsList::const_iterator it = job->requests().begin(); | 874 for (RequestsList::const_iterator it = job->requests().begin(); |
| 871 it != job->requests().end(); ++it) { | 875 it != job->requests().end(); ++it) { |
| 872 Request* req = *it; | 876 Request* req = *it; |
| 873 if (!req->was_cancelled()) { | 877 if (!req->was_cancelled()) { |
| 874 DCHECK_EQ(job, req->job()); | 878 DCHECK_EQ(job, req->job()); |
| 875 | 879 |
| 876 // Update the load log and notify registered observers. | 880 // Update the net log and notify registered observers. |
| 877 OnFinishRequest(req->load_log(), req->id(), req->info(), error); | 881 OnFinishRequest(req->net_log(), req->id(), req->info(), error); |
| 878 | 882 |
| 879 req->OnComplete(error, addrlist); | 883 req->OnComplete(error, addrlist); |
| 880 | 884 |
| 881 // Check if the job was cancelled as a result of running the callback. | 885 // Check if the job was cancelled as a result of running the callback. |
| 882 // (Meaning that |this| was deleted). | 886 // (Meaning that |this| was deleted). |
| 883 if (job->was_cancelled()) | 887 if (job->was_cancelled()) |
| 884 return; | 888 return; |
| 885 } | 889 } |
| 886 } | 890 } |
| 887 | 891 |
| 888 cur_completing_job_ = NULL; | 892 cur_completing_job_ = NULL; |
| 889 } | 893 } |
| 890 | 894 |
| 891 void HostResolverImpl::OnStartRequest(LoadLog* load_log, | 895 void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log, |
| 892 int request_id, | 896 int request_id, |
| 893 const RequestInfo& info) { | 897 const RequestInfo& info) { |
| 894 LoadLog::BeginEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 898 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 895 | 899 |
| 896 if (requests_trace_) { | 900 if (requests_trace_) { |
| 897 requests_trace_->Add(StringPrintf( | 901 requests_trace_->Add(StringPrintf( |
| 898 "Received request r%d for {hostname='%s', port=%d, priority=%d, " | 902 "Received request r%d for {hostname='%s', port=%d, priority=%d, " |
| 899 "speculative=%d, address_family=%d, allow_cached=%d, referrer='%s'}", | 903 "speculative=%d, address_family=%d, allow_cached=%d, referrer='%s'}", |
| 900 request_id, | 904 request_id, |
| 901 info.hostname().c_str(), | 905 info.hostname().c_str(), |
| 902 info.port(), | 906 info.port(), |
| 903 static_cast<int>(info.priority()), | 907 static_cast<int>(info.priority()), |
| 904 static_cast<int>(info.is_speculative()), | 908 static_cast<int>(info.is_speculative()), |
| 905 static_cast<int>(info.address_family()), | 909 static_cast<int>(info.address_family()), |
| 906 static_cast<int>(info.allow_cached_response()), | 910 static_cast<int>(info.allow_cached_response()), |
| 907 info.referrer().spec().c_str())); | 911 info.referrer().spec().c_str())); |
| 908 } | 912 } |
| 909 | 913 |
| 910 // Notify the observers of the start. | 914 // Notify the observers of the start. |
| 911 if (!observers_.empty()) { | 915 if (!observers_.empty()) { |
| 912 LoadLog::BeginEvent( | 916 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); |
| 913 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); | |
| 914 | 917 |
| 915 for (ObserversList::iterator it = observers_.begin(); | 918 for (ObserversList::iterator it = observers_.begin(); |
| 916 it != observers_.end(); ++it) { | 919 it != observers_.end(); ++it) { |
| 917 (*it)->OnStartResolution(request_id, info); | 920 (*it)->OnStartResolution(request_id, info); |
| 918 } | 921 } |
| 919 | 922 |
| 920 LoadLog::EndEvent( | 923 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); |
| 921 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); | |
| 922 } | 924 } |
| 923 } | 925 } |
| 924 | 926 |
| 925 void HostResolverImpl::OnFinishRequest(LoadLog* load_log, | 927 void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log, |
| 926 int request_id, | 928 int request_id, |
| 927 const RequestInfo& info, | 929 const RequestInfo& info, |
| 928 int error) { | 930 int error) { |
| 929 if (requests_trace_) { | 931 if (requests_trace_) { |
| 930 requests_trace_->Add(StringPrintf( | 932 requests_trace_->Add(StringPrintf( |
| 931 "Finished request r%d with error=%d", request_id, error)); | 933 "Finished request r%d with error=%d", request_id, error)); |
| 932 } | 934 } |
| 933 | 935 |
| 934 // Notify the observers of the completion. | 936 // Notify the observers of the completion. |
| 935 if (!observers_.empty()) { | 937 if (!observers_.empty()) { |
| 936 LoadLog::BeginEvent( | 938 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); |
| 937 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); | |
| 938 | 939 |
| 939 bool was_resolved = error == OK; | 940 bool was_resolved = error == OK; |
| 940 for (ObserversList::iterator it = observers_.begin(); | 941 for (ObserversList::iterator it = observers_.begin(); |
| 941 it != observers_.end(); ++it) { | 942 it != observers_.end(); ++it) { |
| 942 (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); | 943 (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); |
| 943 } | 944 } |
| 944 | 945 |
| 945 LoadLog::EndEvent( | 946 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); |
| 946 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); | |
| 947 } | 947 } |
| 948 | 948 |
| 949 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 949 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 950 } | 950 } |
| 951 | 951 |
| 952 void HostResolverImpl::OnCancelRequest(LoadLog* load_log, | 952 void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log, |
| 953 int request_id, | 953 int request_id, |
| 954 const RequestInfo& info) { | 954 const RequestInfo& info) { |
| 955 LoadLog::AddEvent(load_log, LoadLog::TYPE_CANCELLED); | 955 net_log.AddEvent(NetLog::TYPE_CANCELLED); |
| 956 | 956 |
| 957 if (requests_trace_) | 957 if (requests_trace_) |
| 958 requests_trace_->Add(StringPrintf("Cancelled request r%d", request_id)); | 958 requests_trace_->Add(StringPrintf("Cancelled request r%d", request_id)); |
| 959 | 959 |
| 960 // Notify the observers of the cancellation. | 960 // Notify the observers of the cancellation. |
| 961 if (!observers_.empty()) { | 961 if (!observers_.empty()) { |
| 962 LoadLog::BeginEvent( | 962 net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
| 963 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | |
| 964 | 963 |
| 965 for (ObserversList::iterator it = observers_.begin(); | 964 for (ObserversList::iterator it = observers_.begin(); |
| 966 it != observers_.end(); ++it) { | 965 it != observers_.end(); ++it) { |
| 967 (*it)->OnCancelResolution(request_id, info); | 966 (*it)->OnCancelResolution(request_id, info); |
| 968 } | 967 } |
| 969 | 968 |
| 970 LoadLog::EndEvent( | 969 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
| 971 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | |
| 972 } | 970 } |
| 973 | 971 |
| 974 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 972 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 975 } | 973 } |
| 976 | 974 |
| 977 void HostResolverImpl::OnIPAddressChanged() { | 975 void HostResolverImpl::OnIPAddressChanged() { |
| 978 if (cache_.get()) | 976 if (cache_.get()) |
| 979 cache_->clear(); | 977 cache_->clear(); |
| 980 } | 978 } |
| 981 | 979 |
| 982 // static | 980 // static |
| 983 HostResolverImpl::JobPoolIndex HostResolverImpl::GetJobPoolIndexForRequest( | 981 HostResolverImpl::JobPoolIndex HostResolverImpl::GetJobPoolIndexForRequest( |
| 984 const Request* req) { | 982 const Request* req) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 pool->InsertPendingRequest(req)); | 1043 pool->InsertPendingRequest(req)); |
| 1046 | 1044 |
| 1047 // If the queue has become too large, we need to kick something out. | 1045 // If the queue has become too large, we need to kick something out. |
| 1048 if (req_evicted_from_queue.get()) { | 1046 if (req_evicted_from_queue.get()) { |
| 1049 Request* r = req_evicted_from_queue.get(); | 1047 Request* r = req_evicted_from_queue.get(); |
| 1050 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1048 int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
| 1051 | 1049 |
| 1052 if (requests_trace_) | 1050 if (requests_trace_) |
| 1053 requests_trace_->Add(StringPrintf("Evicted request r%d", r->id())); | 1051 requests_trace_->Add(StringPrintf("Evicted request r%d", r->id())); |
| 1054 | 1052 |
| 1055 OnFinishRequest(r->load_log(), r->id(), r->info(), error); | 1053 OnFinishRequest(r->net_log(), r->id(), r->info(), error); |
| 1056 | 1054 |
| 1057 if (r == req) | 1055 if (r == req) |
| 1058 return error; | 1056 return error; |
| 1059 | 1057 |
| 1060 r->OnComplete(error, AddressList()); | 1058 r->OnComplete(error, AddressList()); |
| 1061 } | 1059 } |
| 1062 | 1060 |
| 1063 return ERR_IO_PENDING; | 1061 return ERR_IO_PENDING; |
| 1064 } | 1062 } |
| 1065 | 1063 |
| 1066 } // namespace net | 1064 } // namespace net |
| OLD | NEW |