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

Unified Diff: net/dns/host_resolver_mojo.cc

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
Index: net/dns/host_resolver_mojo.cc
diff --git a/net/dns/host_resolver_mojo.cc b/net/dns/host_resolver_mojo.cc
index 42801461c0a6121a7cad04f7de50b36f6e80f1aa..d0ffedfd415662d0bdd0c1140c0ee896510068d1 100644
--- a/net/dns/host_resolver_mojo.cc
+++ b/net/dns/host_resolver_mojo.cc
@@ -36,6 +36,11 @@ class HostResolverMojo::Job : public interfaces::HostResolverRequestClient {
mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request,
base::WeakPtr<HostCache> host_cache);
+ void SetRequest(RequestImpl* req) {
+ DCHECK(req);
+ request_ = req;
+ }
+
private:
// interfaces::HostResolverRequestClient override.
void ReportResult(int32_t error,
@@ -49,6 +54,29 @@ class HostResolverMojo::Job : public interfaces::HostResolverRequestClient {
CompletionCallback callback_;
mojo::Binding<interfaces::HostResolverRequestClient> binding_;
base::WeakPtr<HostCache> host_cache_;
+ RequestImpl* request_;
+};
+
+class HostResolverMojo::RequestImpl : public HostResolver::Request {
+ public:
+ explicit RequestImpl(std::unique_ptr<Job> job) : job_(std::move(job)) {
+ DCHECK(job_);
+ job_->SetRequest(this);
+ }
+
+ ~RequestImpl() override {}
+
+ void ChangeRequestPriority(RequestPriority priority) override {}
+
+ void RemoveJob() {
+ if (job_)
+ job_.reset();
+ }
+
+ private:
+ std::unique_ptr<Job> job_;
+
+ DISALLOW_COPY_AND_ASSIGN(RequestImpl);
};
HostResolverMojo::HostResolverMojo(Impl* impl)
@@ -63,7 +91,7 @@ int HostResolverMojo::Resolve(const RequestInfo& info,
RequestPriority priority,
AddressList* addresses,
const CompletionCallback& callback,
- RequestHandle* request_handle,
+ std::unique_ptr<Request>* request_handle,
const BoundNetLog& source_net_log) {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "Resolve " << info.host_port_pair().ToString();
@@ -77,8 +105,11 @@ int HostResolverMojo::Resolve(const RequestInfo& info,
}
interfaces::HostResolverRequestClientPtr handle;
- *request_handle = new Job(key, addresses, callback, mojo::GetProxy(&handle),
- host_cache_weak_factory_.GetWeakPtr());
+ std::unique_ptr<Job> job(new Job(key, addresses, callback,
+ mojo::GetProxy(&handle),
+ host_cache_weak_factory_.GetWeakPtr()));
+ (*request_handle).reset(new RequestImpl(std::move(job)));
+
impl_->ResolveDns(interfaces::HostResolverRequestInfo::From(info),
std::move(handle));
return ERR_IO_PENDING;
@@ -92,18 +123,6 @@ int HostResolverMojo::ResolveFromCache(const RequestInfo& info,
return ResolveFromCacheInternal(info, CacheKeyForRequest(info), addresses);
}
-void HostResolverMojo::ChangeRequestPriority(RequestHandle req,
- RequestPriority priority) {
- // Do nothing, since Resolve() discarded the priority anyway.
-}
-
-void HostResolverMojo::CancelRequest(RequestHandle req) {
- DCHECK(thread_checker_.CalledOnValidThread());
- // Deleting the Job closes the HostResolverRequestClient connection,
- // signalling cancellation of the request.
- delete static_cast<Job*>(req);
-}
-
HostCache* HostResolverMojo::GetHostCache() {
return host_cache_.get();
}
@@ -149,8 +168,15 @@ void HostResolverMojo::Job::ReportResult(
HostCache::Entry entry(error, *addresses_, ttl);
host_cache_->Set(key_, entry, base::TimeTicks::Now(), ttl);
}
- callback_.Run(error);
- delete this;
+
+ CompletionCallback cb = callback_;
+ callback_.Reset();
+
+ DCHECK(request_);
+ request_->RemoveJob();
+
+ if (!cb.is_null())
+ cb.Run(error);
}
void HostResolverMojo::Job::OnConnectionError() {

Powered by Google App Engine
This is Rietveld 408576698