| Index: net/base/host_resolver_impl.cc
|
| ===================================================================
|
| --- net/base/host_resolver_impl.cc (revision 23403)
|
| +++ net/base/host_resolver_impl.cc (working copy)
|
| @@ -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 @@
|
|
|
| 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 @@
|
| return job_;
|
| }
|
|
|
| + LoadLog* load_log() const {
|
| + return load_log_;
|
| + }
|
| +
|
| int id() const {
|
| return id_;
|
| }
|
| @@ -99,6 +112,8 @@
|
| }
|
|
|
| private:
|
| + scoped_refptr<LoadLog> load_log_;
|
| +
|
| // Unique ID for this request. Used by observers to identify requests.
|
| int id_;
|
|
|
| @@ -300,8 +315,8 @@
|
| // 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 @@
|
| 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 @@
|
| // 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 @@
|
| 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 @@
|
| 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 @@
|
| 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
|
|
|