Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: net/dns/host_resolver_impl.cc

Issue 1137433003: Encouraging ThreadTaskRunnerHandle usage in net/dns module (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/serial_worker.h » ('j') | net/dns/serial_worker.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index bd6e43198dca94319fe32227f5bc89475634f90a..0ff70422d919bb18fa52dad0d86e82dc070972c2 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -21,13 +21,14 @@
#include "base/compiler_specific.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
-#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/profiler/scoped_tracker.h"
+#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "base/time/time.h"
#include "base/values.h"
@@ -573,7 +574,7 @@ class HostResolverImpl::ProcTask
: key_(key),
params_(params),
callback_(callback),
- origin_loop_(base::MessageLoopProxy::current()),
+ task_runner_(base::ThreadTaskRunnerHandle::Get()),
attempt_number_(0),
completed_attempt_number_(0),
completed_attempt_error_(ERR_UNEXPECTED),
@@ -587,7 +588,7 @@ class HostResolverImpl::ProcTask
}
void Start() {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK);
StartLookupAttempt();
}
@@ -596,7 +597,7 @@ class HostResolverImpl::ProcTask
// attempts running on worker threads will continue running. Only once all the
// attempts complete will the final reference to this ProcTask be released.
void Cancel() {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
if (was_canceled() || was_completed())
return;
@@ -606,17 +607,17 @@ class HostResolverImpl::ProcTask
}
void set_had_non_speculative_request() {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
had_non_speculative_request_ = true;
}
bool was_canceled() const {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
return callback_.is_null();
}
bool was_completed() const {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
return completed_attempt_number_ > 0;
}
@@ -625,7 +626,7 @@ class HostResolverImpl::ProcTask
~ProcTask() {}
void StartLookupAttempt() {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
base::TimeTicks start_time = base::TimeTicks::Now();
++attempt_number_;
// Dispatch the lookup attempt to a worker thread.
@@ -638,10 +639,14 @@ class HostResolverImpl::ProcTask
// Since we could be running within Resolve() right now, we can't just
// call OnLookupComplete(). Instead we must wait until Resolve() has
// returned (IO_PENDING).
- origin_loop_->PostTask(
- FROM_HERE,
- base::Bind(&ProcTask::OnLookupComplete, this, AddressList(),
- start_time, attempt_number_, ERR_UNEXPECTED, 0));
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&ProcTask::OnLookupComplete,
+ this,
+ AddressList(),
+ start_time,
+ attempt_number_,
+ ERR_UNEXPECTED,
+ 0));
return;
}
@@ -653,7 +658,7 @@ class HostResolverImpl::ProcTask
// will start a new attempt on a different worker thread if none of our
// outstanding attempts have completed yet.
if (attempt_number_ <= params_.max_retry_attempts) {
- origin_loop_->PostDelayedTask(
+ task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&ProcTask::RetryIfNotComplete, this),
params_.unresponsive_delay);
@@ -687,15 +692,20 @@ class HostResolverImpl::ProcTask
}
}
- origin_loop_->PostTask(
- FROM_HERE,
- base::Bind(&ProcTask::OnLookupComplete, this, results, start_time,
- attempt_number, error, os_error));
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&ProcTask::OnLookupComplete,
+ this,
+ results,
+ start_time,
+ attempt_number,
+ error,
+ os_error));
}
- // Makes next attempt if DoLookup() has not finished (runs on origin thread).
+ // Makes next attempt if DoLookup() has not finished (runs on task runner
+ // thread).
void RetryIfNotComplete() {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
if (was_completed() || was_canceled())
return;
@@ -704,13 +714,13 @@ class HostResolverImpl::ProcTask
StartLookupAttempt();
}
- // Callback for when DoLookup() completes (runs on origin thread).
+ // Callback for when DoLookup() completes (runs on task runner thread).
void OnLookupComplete(const AddressList& results,
const base::TimeTicks& start_time,
const uint32 attempt_number,
int error,
const int os_error) {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
// If results are empty, we should return an error.
bool empty_list_on_ok = (error == OK && results.empty());
UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok);
@@ -777,7 +787,7 @@ class HostResolverImpl::ProcTask
void RecordPerformanceHistograms(const base::TimeTicks& start_time,
const int error,
const int os_error) const {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
enum Category { // Used in UMA_HISTOGRAM_ENUMERATION.
RESOLVE_SUCCESS,
RESOLVE_FAIL,
@@ -844,7 +854,7 @@ class HostResolverImpl::ProcTask
const uint32 attempt_number,
const int error,
const int os_error) const {
- DCHECK(origin_loop_->BelongsToCurrentThread());
+ DCHECK(task_runner_->BelongsToCurrentThread());
bool first_attempt_to_complete =
completed_attempt_number_ == attempt_number;
bool is_first_attempt = (attempt_number == 1);
@@ -891,7 +901,7 @@ class HostResolverImpl::ProcTask
DNS_HISTOGRAM("DNS.AttemptFailDuration", duration);
}
- // Set on the origin thread, read on the worker thread.
+ // Set on the task runner thread, read on the worker thread.
Key key_;
// Holds an owning reference to the HostResolverProc that we are going to use.
@@ -903,8 +913,8 @@ class HostResolverImpl::ProcTask
// The listener to the results of this ProcTask.
Callback callback_;
- // Used to post ourselves onto the origin thread.
- scoped_refptr<base::MessageLoopProxy> origin_loop_;
+ // Used to post ourselves onto the task runner thread.
asanka 2015/05/14 18:38:40 .. on to the originating thread.
anujsharma 2015/05/20 13:13:16 Done.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// Keeps track of the number of attempts we have made so far to resolve the
// host. Whenever we start an attempt to resolve the host, we increase this
@@ -966,7 +976,7 @@ class HostResolverImpl::LoopbackProbeJob {
resolver_->SetHaveOnlyLoopbackAddresses(result_);
}
- // Used/set only on origin thread.
+ // Used/set only on task runner thread.
base::WeakPtr<HostResolverImpl> resolver_;
bool result_;
« no previous file with comments | « no previous file | net/dns/serial_worker.h » ('j') | net/dns/serial_worker.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698