diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 18:01:15 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 18:01:15 +0000 |
commit | 2bb044402ba016977b58014a22b0631ab7ed605d (patch) | |
tree | 6e85bb65048d4b262b6bb4e1d6d0e418957b857d /net/base | |
parent | 8748bdf9fe94b62e76e7adf7fac9af7dfd9c0ca3 (diff) | |
download | chromium_src-2bb044402ba016977b58014a22b0631ab7ed605d.zip chromium_src-2bb044402ba016977b58014a22b0631ab7ed605d.tar.gz chromium_src-2bb044402ba016977b58014a22b0631ab7ed605d.tar.bz2 |
Revert 56539 - Added HostResolveImpl Requests and Jobs to log.
ConnectJobs point to the requests, Requests point back to ConnectJobs and to the DNS lookup they were attached to, if any.
Also CONNECT_JOBs are now identified by their host/port on the Requests list.
BUG= 46844
TEST= Look at the net-internals screen.
Review URL: http://codereview.chromium.org/3080034
TBR=eroman@chromium.org
Review URL: http://codereview.chromium.org/3137022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56556 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/host_resolver.h | 4 | ||||
-rw-r--r-- | net/base/host_resolver_impl.cc | 234 | ||||
-rw-r--r-- | net/base/host_resolver_impl.h | 19 | ||||
-rw-r--r-- | net/base/host_resolver_impl_unittest.cc | 54 | ||||
-rw-r--r-- | net/base/mock_host_resolver.cc | 2 | ||||
-rw-r--r-- | net/base/net_log.cc | 13 | ||||
-rw-r--r-- | net/base/net_log.h | 3 | ||||
-rw-r--r-- | net/base/net_log_event_type_list.h | 84 | ||||
-rw-r--r-- | net/base/net_log_source_type_list.h | 4 | ||||
-rw-r--r-- | net/base/net_log_unittest.h | 21 |
10 files changed, 86 insertions, 352 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 71afc8a..ff0ce24 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -22,7 +22,6 @@ class AddressList; class BoundNetLog; class HostCache; class HostResolverImpl; -class NetLog; // This class represents the task of resolving hostnames (or IP address // literal) to an AddressList object. @@ -248,8 +247,7 @@ class SingleRequestHostResolver { // |max_concurrent_resolves| is how many resolve requests will be allowed to // run in parallel. Pass HostResolver::kDefaultParallelism to choose a // default value. -HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, - NetLog* net_log); +HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves); } // namespace net diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 23ac17f..aa1ed9c 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -27,10 +27,9 @@ #include "base/values.h" #include "base/worker_pool.h" #include "net/base/address_list.h" -#include "net/base/address_list_net_log_param.h" #include "net/base/host_resolver_proc.h" -#include "net/base/net_errors.h" #include "net/base/net_log.h" +#include "net/base/net_errors.h" #include "net/base/net_util.h" #if defined(OS_WIN) @@ -54,8 +53,7 @@ HostCache* CreateDefaultCache() { } // anonymous namespace -HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, - NetLog* net_log) { +HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves) { // Maximum of 50 concurrent threads. // TODO(eroman): Adjust this, do some A/B experiments. static const size_t kDefaultMaxJobs = 50u; @@ -65,7 +63,7 @@ HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, HostResolverImpl* resolver = new HostResolverImpl(NULL, CreateDefaultCache(), - max_concurrent_resolves, net_log); + max_concurrent_resolves); return resolver; } @@ -90,14 +88,16 @@ static int ResolveAddrInfo(HostResolverProc* resolver_proc, // Extra parameters to attach to the NetLog when the resolve failed. class HostResolveFailedParams : public NetLog::EventParameters { public: - HostResolveFailedParams(int net_error, int os_error) + HostResolveFailedParams(int net_error, int os_error, bool was_from_cache) : net_error_(net_error), - os_error_(os_error) { + os_error_(os_error), + was_from_cache_(was_from_cache) { } virtual Value* ToValue() const { DictionaryValue* dict = new DictionaryValue(); dict->SetInteger("net_error", net_error_); + dict->SetBoolean("was_from_cache", was_from_cache_); if (os_error_) { dict->SetInteger("os_error", os_error_); @@ -125,54 +125,7 @@ class HostResolveFailedParams : public NetLog::EventParameters { private: const int net_error_; const int os_error_; -}; - -// Parameters representing the information in a RequestInfo object, along with -// the associated NetLog::Source. -class RequestInfoParameters : public NetLog::EventParameters { - public: - RequestInfoParameters(const HostResolver::RequestInfo& info, - const NetLog::Source& source) - : info_(info), source_(source) {} - - virtual Value* ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->SetString("host", StringPrintf("%s:%i", - info_.hostname().c_str(), - info_.port())); - dict->SetInteger("address_family", - static_cast<int>(info_.address_family())); - dict->SetInteger("allow_cached_response", info_.allow_cached_response()); - dict->SetInteger("is_speculative", info_.is_speculative()); - dict->SetInteger("priority", info_.priority()); - - if (source_.is_valid()) - dict->Set("source_dependency", source_.ToValue()); - - return dict; - } - - private: - const HostResolver::RequestInfo info_; - const NetLog::Source source_; -}; - -// Parameters associated with the creation of a HostResolveImpl::Job. -class JobCreationParameters : public NetLog::EventParameters { - public: - JobCreationParameters(const std::string& host, const NetLog::Source& source) - : host_(host), source_(source) {} - - virtual Value* ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->SetString("host", host_); - dict->Set("source_dependency", source_.ToValue()); - return dict; - } - - private: - const std::string host_; - const NetLog::Source source_; + const bool was_from_cache_; }; // Gets a list of the likely error codes that getaddrinfo() can return @@ -223,14 +176,12 @@ std::vector<int> GetAllGetAddrinfoOSErrors() { class HostResolverImpl::Request { public: - Request(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, + Request(const BoundNetLog& net_log, int id, const RequestInfo& info, CompletionCallback* callback, AddressList* addresses) - : source_net_log_(source_net_log), - request_net_log_(request_net_log), + : net_log_(net_log), id_(id), info_(info), job_(NULL), @@ -269,12 +220,8 @@ class HostResolverImpl::Request { return job_; } - const BoundNetLog& source_net_log() { - return source_net_log_; - } - - const BoundNetLog& request_net_log() { - return request_net_log_; + const BoundNetLog& net_log() { + return net_log_; } int id() const { @@ -286,8 +233,7 @@ class HostResolverImpl::Request { } private: - BoundNetLog source_net_log_; - BoundNetLog request_net_log_; + BoundNetLog net_log_; // Unique ID for this request. Used by observers to identify requests. int id_; @@ -314,33 +260,20 @@ class HostResolverImpl::Request { class HostResolverImpl::Job : public base::RefCountedThreadSafe<HostResolverImpl::Job> { public: - Job(int id, - HostResolverImpl* resolver, - const Key& key, - const BoundNetLog& source_net_log, - NetLog* net_log) - : id_(id), - key_(key), - resolver_(resolver), - origin_loop_(MessageLoop::current()), - resolver_proc_(resolver->effective_resolver_proc()), - error_(OK), - os_error_(0), - had_non_speculative_request_(false), - net_log_(BoundNetLog::Make(net_log, - NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { - net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, - new JobCreationParameters(key.hostname, - source_net_log.source())); + Job(int id, HostResolverImpl* resolver, const Key& key) + : id_(id), + key_(key), + resolver_(resolver), + origin_loop_(MessageLoop::current()), + resolver_proc_(resolver->effective_resolver_proc()), + error_(OK), + os_error_(0), + had_non_speculative_request_(false) { } // Attaches a request to this job. The job takes ownership of |req| and will // take care to delete it. void AddRequest(Request* req) { - req->request_net_log().BeginEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, - new NetLogSourceParameter("source_dependency", net_log_.source())); - req->set_job(this); requests_.push_back(req); @@ -351,7 +284,6 @@ class HostResolverImpl::Job // Called from origin loop. void Start() { start_time_ = base::TimeTicks::Now(); - net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_RESOLVE, NULL); // Dispatch the job to a worker thread. if (!WorkerPool::PostTask(FROM_HERE, @@ -369,9 +301,6 @@ class HostResolverImpl::Job // Cancels the current job. Callable from origin thread. void Cancel() { - net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); - net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_RESOLVE, NULL); - HostResolver* resolver = resolver_; resolver_ = NULL; @@ -390,10 +319,6 @@ class HostResolverImpl::Job if (!req->was_cancelled()) resolver->CancelRequest(req); } - - net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, NULL); - // Prevent issues when a Job outlives the HostResolver that spawned it. - net_log_ = BoundNetLog(); } // Called from origin thread. @@ -435,9 +360,6 @@ class HostResolverImpl::Job friend class base::RefCountedThreadSafe<HostResolverImpl::Job>; ~Job() { - // If the request was cancelled, |net_log_| is actually empty, and no - // redundant entry is made. - net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, NULL); // Free the requests attached to this job. STLDeleteElements(&requests_); } @@ -490,15 +412,6 @@ class HostResolverImpl::Job if (was_cancelled()) return; - scoped_refptr<NetLog::EventParameters> params; - if (error_ != OK) { - params = new HostResolveFailedParams(error_, os_error_); - } else { - params = new AddressListNetLogParam(results_); - } - - net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_RESOLVE, params); - DCHECK(!requests_.empty()); // Use the port number of the first request. @@ -543,8 +456,6 @@ class HostResolverImpl::Job // The time when the job was started. base::TimeTicks start_time_; - BoundNetLog net_log_; - DISALLOW_COPY_AND_ASSIGN(Job); }; @@ -697,10 +608,6 @@ class HostResolverImpl::JobPool { // evicted from the queue, and returned. Otherwise returns NULL. The caller // is responsible for freeing the evicted request. Request* InsertPendingRequest(Request* req) { - req->request_net_log().BeginEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_POOL_QUEUE, - NULL); - PendingRequestsQueue& q = pending_requests_[req->info().priority()]; q.push_back(req); @@ -713,10 +620,6 @@ class HostResolverImpl::JobPool { if (!q.empty()) { Request* req = q.front(); q.pop_front(); - req->request_net_log().AddEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_POOL_QUEUE_EVICTED, NULL); - req->request_net_log().EndEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_POOL_QUEUE, NULL); return req; } } @@ -732,8 +635,6 @@ class HostResolverImpl::JobPool { PendingRequestsQueue::iterator it = std::find(q.begin(), q.end(), req); DCHECK(it != q.end()); q.erase(it); - req->request_net_log().EndEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_POOL_QUEUE, NULL); } // Removes and returns the highest priority pending request. @@ -745,8 +646,6 @@ class HostResolverImpl::JobPool { if (!q.empty()) { Request* req = q.front(); q.pop_front(); - req->request_net_log().EndEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_POOL_QUEUE, NULL); return req; } } @@ -810,8 +709,7 @@ class HostResolverImpl::JobPool { HostResolverImpl::HostResolverImpl( HostResolverProc* resolver_proc, HostCache* cache, - size_t max_jobs, - NetLog* net_log) + size_t max_jobs) : cache_(cache), max_jobs_(max_jobs), next_request_id_(0), @@ -820,8 +718,7 @@ HostResolverImpl::HostResolverImpl( default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), shutdown_(false), ipv6_probe_monitoring_(false), - additional_resolver_flags_(0), - net_log_(net_log) { + additional_resolver_flags_(0) { DCHECK_GT(max_jobs, 0u); // It is cumbersome to expose all of the constraints in the constructor, @@ -863,7 +760,7 @@ int HostResolverImpl::Resolve(const RequestInfo& info, AddressList* addresses, CompletionCallback* callback, RequestHandle* out_req, - const BoundNetLog& source_net_log) { + const BoundNetLog& net_log) { DCHECK(CalledOnValidThread()); if (shutdown_) @@ -872,12 +769,8 @@ int HostResolverImpl::Resolve(const RequestInfo& info, // Choose a unique ID number for observers to see. int request_id = next_request_id_++; - // Make a log item for the request. - BoundNetLog request_net_log = BoundNetLog::Make(net_log_, - NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); - // Update the net log and notify registered observers. - OnStartRequest(source_net_log, request_net_log, request_id, info); + OnStartRequest(net_log, request_id, info); // Build a key that identifies the request in the cache and in the // outstanding jobs map. @@ -888,15 +781,14 @@ int HostResolverImpl::Resolve(const RequestInfo& info, const HostCache::Entry* cache_entry = cache_->Lookup( key, base::TimeTicks::Now()); if (cache_entry) { - request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT, NULL); int net_error = cache_entry->error; if (net_error == OK) addresses->SetFrom(cache_entry->addrlist, info.port()); // Update the net log and notify registered observers. - OnFinishRequest(source_net_log, request_net_log, request_id, info, - net_error, - 0 /* os_error (unknown since from cache) */); + OnFinishRequest(net_log, request_id, info, net_error, + 0, /* os_error (unknown since from cache) */ + true /* was_from_cache */); return net_error; } @@ -919,16 +811,15 @@ int HostResolverImpl::Resolve(const RequestInfo& info, cache_->Set(key, error, addrlist, base::TimeTicks::Now()); // Update the net log and notify registered observers. - OnFinishRequest(source_net_log, request_net_log, request_id, info, error, - os_error); + OnFinishRequest(net_log, request_id, info, error, os_error, + false /* was_from_cache */); return error; } // Create a handle for this request, and pass it back to the user if they // asked for it (out_req != NULL). - Request* req = new Request(source_net_log, request_net_log, request_id, info, - callback, addresses); + Request* req = new Request(net_log, request_id, info, callback, addresses); if (out_req) *out_req = reinterpret_cast<RequestHandle>(req); @@ -979,15 +870,11 @@ void HostResolverImpl::CancelRequest(RequestHandle req_handle) { JobPool* pool = GetPoolForRequest(req); pool->RemovePendingRequest(req); request_deleter.reset(req); - } else { - req->request_net_log().EndEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); } // NULL out the fields of req, to mark it as cancelled. req->MarkAsCancelled(); - OnCancelRequest(req->source_net_log(), req->request_net_log(), req->id(), - req->info()); + OnCancelRequest(req->net_log(), req->id(), req->info()); } void HostResolverImpl::AddObserver(HostResolver::Observer* observer) { @@ -1093,12 +980,10 @@ void HostResolverImpl::OnJobComplete(Job* job, Request* req = *it; if (!req->was_cancelled()) { DCHECK_EQ(job, req->job()); - req->request_net_log().EndEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, NULL); // Update the net log and notify registered observers. - OnFinishRequest(req->source_net_log(), req->request_net_log(), req->id(), - req->info(), net_error, os_error); + OnFinishRequest(req->net_log(), req->id(), req->info(), net_error, + os_error, false /* was_from_cache */); req->OnComplete(net_error, addrlist); @@ -1112,17 +997,10 @@ void HostResolverImpl::OnJobComplete(Job* job, cur_completing_job_ = NULL; } -void HostResolverImpl::OnStartRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, +void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info) { - source_net_log.BeginEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL, - new NetLogSourceParameter("source_dependency", request_net_log.source())); - - request_net_log.BeginEvent( - NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, - new RequestInfoParameters(info, source_net_log.source())); + net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); // Notify the observers of the start. if (!observers_.empty()) { @@ -1133,12 +1011,12 @@ void HostResolverImpl::OnStartRequest(const BoundNetLog& source_net_log, } } -void HostResolverImpl::OnFinishRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, +void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info, int net_error, - int os_error) { + int os_error, + bool was_from_cache) { bool was_resolved = net_error == OK; // Notify the observers of the completion. @@ -1149,21 +1027,18 @@ void HostResolverImpl::OnFinishRequest(const BoundNetLog& source_net_log, } } - // Log some extra parameters on failure for synchronous requests. + // Log some extra parameters on failure. scoped_refptr<NetLog::EventParameters> params; - if (!was_resolved) { - params = new HostResolveFailedParams(net_error, os_error); - } + if (!was_resolved) + params = new HostResolveFailedParams(net_error, os_error, was_from_cache); - request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, params); - source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); + net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, params); } -void HostResolverImpl::OnCancelRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, +void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info) { - request_net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); + net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL); // Notify the observers of the cancellation. if (!observers_.empty()) { @@ -1173,8 +1048,7 @@ void HostResolverImpl::OnCancelRequest(const BoundNetLog& source_net_log, } } - request_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, NULL); - source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); + net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); } void HostResolverImpl::OnIPAddressChanged() { @@ -1271,16 +1145,10 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); Key key = GetEffectiveKeyForRequest(req->info()); - - req->request_net_log().AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, - NULL); - - scoped_refptr<Job> job = new Job(next_job_id_++, this, key, - req->request_net_log(), net_log_); + scoped_refptr<Job> job = new Job(next_job_id_++, this, key); job->AddRequest(req); AddOutstandingJob(job); job->Start(); - return job.get(); } @@ -1293,9 +1161,9 @@ int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { Request* r = req_evicted_from_queue.get(); int error = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; - OnFinishRequest(r->source_net_log(), r->request_net_log(), r->id(), - r->info(), error, - 0 /* os_error (not applicable) */); + OnFinishRequest(r->net_log(), r->id(), r->info(), error, + 0, /* os_error (not applicable) */ + false /* was_from_cache */); if (r == req) return error; diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index d2c327b..5206536 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -78,15 +78,14 @@ class HostResolverImpl : public HostResolver, // will use. Use SetPoolConstraints() to specify finer-grain settings. HostResolverImpl(HostResolverProc* resolver_proc, HostCache* cache, - size_t max_jobs, - NetLog* net_log_); + size_t max_jobs); // HostResolver methods: virtual int Resolve(const RequestInfo& info, AddressList* addresses, CompletionCallback* callback, RequestHandle* out_req, - const BoundNetLog& source_net_log); + const BoundNetLog& net_log); virtual void CancelRequest(RequestHandle req); virtual void AddObserver(HostResolver::Observer* observer); virtual void RemoveObserver(HostResolver::Observer* observer); @@ -156,22 +155,20 @@ class HostResolverImpl : public HostResolver, const AddressList& addrlist); // Called when a request has just been started. - void OnStartRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, + void OnStartRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info); // Called when a request has just completed (before its callback is run). - void OnFinishRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, + void OnFinishRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info, int net_error, - int os_error); + int os_error, + bool was_from_cache); // Called when a request has been cancelled. - void OnCancelRequest(const BoundNetLog& source_net_log, - const BoundNetLog& request_net_log, + void OnCancelRequest(const BoundNetLog& net_log, int request_id, const RequestInfo& info); @@ -259,8 +256,6 @@ class HostResolverImpl : public HostResolver, // Any resolver flags that should be added to a request by default. HostResolverFlags additional_resolver_flags_; - NetLog* net_log_; - DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); }; diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index d820121..be0e2cb 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -38,8 +38,7 @@ HostCache* CreateDefaultCache() { static const size_t kMaxJobs = 10u; HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { - return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, - NULL); + return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs); } // Helper to create a HostResolver::RequestInfo. @@ -330,14 +329,10 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { scoped_refptr<WaitingHostResolverProc> resolver_proc = new WaitingHostResolverProc(NULL); - CapturingNetLog net_log(CapturingNetLog::kUnbounded); CapturingBoundNetLog log(CapturingNetLog::kUnbounded); { scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, - CreateDefaultCache(), - kMaxJobs, - &net_log)); + CreateHostResolverImpl(resolver_proc)); AddressList adrlist; const int kPortnum = 80; @@ -355,32 +350,13 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { resolver_proc->Signal(); - EXPECT_EQ(2u, log.entries().size()); + EXPECT_EQ(3u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 1, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); - - int pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), 0, - net::NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, - net::NetLog::PHASE_BEGIN); - pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, - net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, - net::NetLog::PHASE_BEGIN); - // Both Job and Request need to be cancelled. - pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, - net::NetLog::TYPE_CANCELLED, - net::NetLog::PHASE_NONE); - pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, - net::NetLog::TYPE_CANCELLED, - net::NetLog::PHASE_NONE); - // Don't care about which ends first. - net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, - net::NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, - net::NetLog::PHASE_END); - net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, - net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, - net::NetLog::PHASE_END); + log.entries(), 2, NetLog::TYPE_HOST_RESOLVER_IMPL)); EXPECT_FALSE(callback_called_); } @@ -782,7 +758,7 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { // Turn off caching for this host resolver. scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); + new HostResolverImpl(resolver_proc, NULL, kMaxJobs)); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -1079,7 +1055,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { // Test that IP address changes flush the cache. TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); + new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs)); AddressList addrlist; @@ -1116,8 +1092,7 @@ TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. size_t kMaxJobs = 1u; scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, - NULL)); + new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); CapturingObserver observer; host_resolver->AddObserver(&observer); @@ -1201,8 +1176,7 @@ TEST_F(HostResolverImplTest, CancelPendingRequest) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxJobs = 1u; scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, - NULL)); + new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); // Note that at this point the CapturingHostResolverProc is blocked, so any // requests we make will not complete. @@ -1264,7 +1238,7 @@ TEST_F(HostResolverImplTest, QueueOverflow) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( - resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); // Only allow up to 3 requests to be enqueued at a time. const size_t kMaxPendingRequests = 3u; @@ -1342,7 +1316,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( - resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); @@ -1410,7 +1384,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( - resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); @@ -1476,7 +1450,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { const size_t kMaxOutstandingJobs = 10u; scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( - resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index 86c2db4..8d1fd89 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -98,7 +98,7 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { base::TimeDelta::FromSeconds(0)); } - impl_ = new HostResolverImpl(proc, cache, 50u, NULL); + impl_ = new HostResolverImpl(proc, cache, 50u); } //----------------------------------------------------------------------------- diff --git a/net/base/net_log.cc b/net/base/net_log.cc index c91306c..adf8381 100644 --- a/net/base/net_log.cc +++ b/net/base/net_log.cc @@ -11,13 +11,6 @@ namespace net { -Value* NetLog::Source::ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger("type", static_cast<int>(type)); - dict->SetInteger("id", static_cast<int>(id)); - return dict; -} - // static const char* NetLog::EventTypeToString(EventType event) { switch (event) { @@ -176,7 +169,11 @@ Value* NetLogStringParameter::ToValue() const { Value* NetLogSourceParameter::ToValue() const { DictionaryValue* dict = new DictionaryValue(); - dict->Set(name_, value_.ToValue()); + DictionaryValue* source_dict = new DictionaryValue(); + source_dict->SetInteger("type", static_cast<int>(value_.type)); + source_dict->SetInteger("id", static_cast<int>(value_.id)); + + dict->Set(name_, source_dict); return dict; } diff --git a/net/base/net_log.h b/net/base/net_log.h index 603f081..b6492cd 100644 --- a/net/base/net_log.h +++ b/net/base/net_log.h @@ -70,8 +70,7 @@ class NetLog { Source() : type(SOURCE_NONE), id(kInvalidId) {} Source(SourceType type, uint32 id) : type(type), id(id) {} - bool is_valid() const { return id != kInvalidId; } - Value* ToValue() const; + bool is_valid() { return id != kInvalidId; } SourceType type; uint32 id; diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index d8f3fe9..f729c2d 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -20,90 +20,14 @@ EVENT_TYPE(REQUEST_ALIVE) // HostResolverImpl // ------------------------------------------------------------------------ -// The start/end of waiting on a host resolve (DNS) request. -// The BEGIN phase contains the following parameters: -// -// { -// "source_dependency": <Source id of the request being waited on> -// } -EVENT_TYPE(HOST_RESOLVER_IMPL) - -// The start/end of a host resolve (DNS) request. Note that these events are -// logged for all DNS requests, though not all requests result in the creation -// of a HostResolvedImpl::Request object. -// -// The BEGIN phase contains the following parameters: -// -// { -// "host": <Hostname associated with the request> -// "source_dependency": <Source id, if any, of what created the request> -// } -// -// If an error occurred, the END phase will contain these parameters: -// { -// "net_error": <The net error code integer for the failure>, -// "os_error": <The exact error code integer that getaddrinfo() returned>, -// } - -EVENT_TYPE(HOST_RESOLVER_IMPL_REQUEST) - -// This event is logged when a request is handled by a cache entry. -EVENT_TYPE(HOST_RESOLVER_IMPL_CACHE_HIT) - -// This event means a request was queued/dequeued for subsequent job creation, -// because there are already too many active HostResolverImpl::Jobs. -// -// The BEGIN phase contains the following parameters: -// -// { -// "priority": <Priority of the queued request> -// } -EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_POOL_QUEUE) - -// This event is created when a new HostResolverImpl::Request is evicted from -// JobPool without a Job being created, because the limit on number of queued -// Requests was reached. -EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_POOL_QUEUE_EVICTED) - -// This event is created when a new HostResolverImpl::Job is about to be created -// for a request. -EVENT_TYPE(HOST_RESOLVER_IMPL_CREATE_JOB) - -// This is logged for a request when it's attached to a -// HostResolverImpl::Job. When this occurs without a preceding -// HOST_RESOLVER_IMPL_CREATE_JOB entry, it means the request was attached to an -// existing HostResolverImpl::Job. -// -// If the BoundNetLog used to create the event has a valid source id, the BEGIN -// phase contains the following parameters: -// -// { -// "source_dependency": <Source identifier for the attached Job> -// } -EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_ATTACH) - -// The creation/destruction of a host resolve (DNS) job. -// The BEGIN phase contains the following parameters: -// -// { -// "host": <Hostname associated with the request> -// "source_dependency": <Source id, if any, of what created the request> -// } -EVENT_TYPE(HOST_RESOLVER_IMPL_JOB) - -// The start/end of the actual DNS query. -// -// On success, the END phase has these parameters: -// { -// "address_list": <The host name being resolved>, -// } -// If an error occurred, the END phase will contain these parameters: +// The start/end of a host resolve (DNS) request. +// If an error occurred, the end phase will contain these parameters: // { // "net_error": <The net error code integer for the failure>, // "os_error": <The exact error code integer that getaddrinfo() returned>, +// "was_from_cache": <True if the response was gotten from the cache> // } -EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_RESOLVE) - +EVENT_TYPE(HOST_RESOLVER_IMPL) // ------------------------------------------------------------------------ // InitProxyResolver diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h index 231ecd2..d416f3f 100644 --- a/net/base/net_log_source_type_list.h +++ b/net/base/net_log_source_type_list.h @@ -13,7 +13,5 @@ SOURCE_TYPE(INIT_PROXY_RESOLVER, 3) SOURCE_TYPE(CONNECT_JOB, 4) SOURCE_TYPE(SOCKET, 5) SOURCE_TYPE(SPDY_SESSION, 6) -SOURCE_TYPE(HOST_RESOLVER_IMPL_REQUEST, 7) -SOURCE_TYPE(HOST_RESOLVER_IMPL_JOB, 8) -SOURCE_TYPE(COUNT, 9) // Always keep this as the last entry. +SOURCE_TYPE(COUNT, 7) // Always keep this as the last entry. diff --git a/net/base/net_log_unittest.h b/net/base/net_log_unittest.h index 9c7a42d..a013f23 100644 --- a/net/base/net_log_unittest.h +++ b/net/base/net_log_unittest.h @@ -106,7 +106,7 @@ inline ::testing::AssertionResult LogContainsEntryWithType( // Expect that the log contains an event, but don't care about where -// as long as the first index where it is found is at least |min_index|. +// as long as the index where it is found is greater than min_index. // Returns the position where the event was found. inline size_t ExpectLogContainsSomewhere( const CapturingNetLog::EntryList& entries, @@ -125,25 +125,6 @@ inline size_t ExpectLogContainsSomewhere( return i; } -// Expect that the log contains an event, but don't care about where -// as long as one index where it is found is at least |min_index|. -// Returns the first such position where the event was found. -inline size_t ExpectLogContainsSomewhereAfter( - const CapturingNetLog::EntryList& entries, - size_t min_index, - NetLog::EventType expected_event, - NetLog::EventPhase expected_phase) { - size_t i = min_index; - for (; i < entries.size(); ++i) { - const CapturingNetLog::Entry& entry = entries[i]; - if (entry.type == expected_event && - entry.phase == expected_phase) - break; - } - EXPECT_LT(i, entries.size()); - return i; -} - } // namespace net #endif // NET_BASE_NET_LOG_UNITTEST_H_ |