diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 03:01:09 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 03:01:09 +0000 |
commit | 54e1377ea309c5d8ab318ee9691b46249d7441b6 (patch) | |
tree | 8471e44056027dff255ff5b22ba083a9482b41c3 /net/base/host_resolver_impl.cc | |
parent | 672eca0fd191acd39c28430d1ed1f327594faff8 (diff) | |
download | chromium_src-54e1377ea309c5d8ab318ee9691b46249d7441b6.zip chromium_src-54e1377ea309c5d8ab318ee9691b46249d7441b6.tar.gz chromium_src-54e1377ea309c5d8ab318ee9691b46249d7441b6.tar.bz2 |
Implement LoadLog, and hook up HostResolverImpl to LoadLog.
The functionality in load_log_util.h is currently unused, but since it motivates the implementation of LoadLog, figured it should be included with this review.
Note that I decided against defining the loggable event types as LoadStates, since I wanted more flexibility in adding crazy stuff, and they really seem too implementation specific to be in LoadStates.
BUG=http://crbug.com/14478
TEST=net_unittests
Review URL: http://codereview.chromium.org/165404
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_impl.cc')
-rw-r--r-- | net/base/host_resolver_impl.cc | 113 |
1 files changed, 83 insertions, 30 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 111e8da..20e57e5 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -24,6 +24,7 @@ #include "base/worker_pool.h" #include "net/base/address_list.h" #include "net/base/host_resolver_proc.h" +#include "net/base/load_log.h" #include "net/base/net_errors.h" #if defined(OS_WIN) @@ -54,10 +55,18 @@ static int ResolveAddrInfo(HostResolverProc* resolver_proc, class HostResolverImpl::Request { public: - Request(int id, const RequestInfo& info, CompletionCallback* callback, + Request(LoadLog* load_log, + int id, + const RequestInfo& info, + CompletionCallback* callback, AddressList* addresses) - : id_(id), info_(info), job_(NULL), callback_(callback), - addresses_(addresses) {} + : load_log_(load_log), + id_(id), + info_(info), + job_(NULL), + callback_(callback), + addresses_(addresses) { + } // Mark the request as cancelled. void MarkAsCancelled() { @@ -90,6 +99,10 @@ class HostResolverImpl::Request { return job_; } + LoadLog* load_log() const { + return load_log_; + } + int id() const { return id_; } @@ -99,6 +112,8 @@ class HostResolverImpl::Request { } private: + scoped_refptr<LoadLog> load_log_; + // Unique ID for this request. Used by observers to identify requests. int id_; @@ -300,8 +315,8 @@ int HostResolverImpl::Resolve(LoadLog* load_log, // Choose a unique ID number for observers to see. int request_id = next_request_id_++; - // Notify registered observers. - NotifyObserversStartRequest(request_id, info); + // Update the load log and notify registered observers. + OnStartRequest(load_log, request_id, info); // If we have an unexpired cache entry, use it. if (info.allow_cached_response()) { @@ -311,8 +326,8 @@ int HostResolverImpl::Resolve(LoadLog* load_log, addresses->SetFrom(cache_entry->addrlist, info.port()); int error = cache_entry->error; - // Notify registered observers. - NotifyObserversFinishRequest(request_id, info, error); + // Update the load log and notify registered observers. + OnFinishRequest(load_log, request_id, info, error); return error; } @@ -331,15 +346,15 @@ int HostResolverImpl::Resolve(LoadLog* load_log, // Write to cache. cache_.Set(info.hostname(), error, addrlist, base::TimeTicks::Now()); - // Notify registered observers. - NotifyObserversFinishRequest(request_id, info, error); + // Update the load log and notify registered observers. + OnFinishRequest(load_log, request_id, info, error); 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(request_id, info, callback, addresses); + Request* req = new Request(load_log, request_id, info, callback, addresses); if (out_req) *out_req = reinterpret_cast<RequestHandle>(req); @@ -382,7 +397,7 @@ void HostResolverImpl::CancelRequest(RequestHandle req_handle) { DCHECK(req->job()); // NULL out the fields of req, to mark it as cancelled. req->MarkAsCancelled(); - NotifyObserversCancelRequest(req->id(), req->info()); + OnCancelRequest(req->load_log(), req->id(), req->info()); } void HostResolverImpl::AddObserver(Observer* observer) { @@ -449,8 +464,8 @@ void HostResolverImpl::OnJobComplete(Job* job, if (!req->was_cancelled()) { DCHECK_EQ(job, req->job()); - // Notify registered observers. - NotifyObserversFinishRequest(req->id(), req->info(), error); + // Update the load log and notify registered observers. + OnFinishRequest(req->load_log(), req->id(), req->info(), error); req->OnComplete(error, addrlist); @@ -464,30 +479,68 @@ void HostResolverImpl::OnJobComplete(Job* job, cur_completing_job_ = NULL; } -void HostResolverImpl::NotifyObserversStartRequest(int request_id, - const RequestInfo& info) { - for (ObserversList::iterator it = observers_.begin(); - it != observers_.end(); ++it) { - (*it)->OnStartResolution(request_id, info); +void HostResolverImpl::OnStartRequest(LoadLog* load_log, + int request_id, + const RequestInfo& info) { + LoadLog::BeginEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); + + // Notify the observers of the start. + if (!observers_.empty()) { + LoadLog::BeginEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); + + for (ObserversList::iterator it = observers_.begin(); + it != observers_.end(); ++it) { + (*it)->OnStartResolution(request_id, info); + } + + LoadLog::EndEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART); } } -void HostResolverImpl::NotifyObserversFinishRequest(int request_id, - const RequestInfo& info, - int error) { - bool was_resolved = error == OK; - for (ObserversList::iterator it = observers_.begin(); - it != observers_.end(); ++it) { - (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); +void HostResolverImpl::OnFinishRequest(LoadLog* load_log, + int request_id, + const RequestInfo& info, + int error) { + // Notify the observers of the completion. + if (!observers_.empty()) { + LoadLog::BeginEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); + + bool was_resolved = error == OK; + for (ObserversList::iterator it = observers_.begin(); + it != observers_.end(); ++it) { + (*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info); + } + + LoadLog::EndEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH); } + + LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); } -void HostResolverImpl::NotifyObserversCancelRequest(int request_id, - const RequestInfo& info) { - for (ObserversList::iterator it = observers_.begin(); - it != observers_.end(); ++it) { - (*it)->OnCancelResolution(request_id, info); +void HostResolverImpl::OnCancelRequest(LoadLog* load_log, + int request_id, + const RequestInfo& info) { + LoadLog::AddEvent(load_log, LoadLog::TYPE_CANCELLED); + + // Notify the observers of the cancellation. + if (!observers_.empty()) { + LoadLog::BeginEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); + + for (ObserversList::iterator it = observers_.begin(); + it != observers_.end(); ++it) { + (*it)->OnCancelResolution(request_id, info); + } + + LoadLog::EndEvent( + load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); } + + LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); } } // namespace net |