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

Unified Diff: net/proxy/mock_proxy_resolver.cc

Issue 1439053002: Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore scoped_ptr to mock and nits Created 4 years, 10 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 | « net/proxy/mock_proxy_resolver.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/mock_proxy_resolver.cc
diff --git a/net/proxy/mock_proxy_resolver.cc b/net/proxy/mock_proxy_resolver.cc
index 21cac0026cb24a8975e01868ed8d403fccaf19bf..e2635529b2239b0b2bcc95eb7443cc9943fc7b82 100644
--- a/net/proxy/mock_proxy_resolver.cc
+++ b/net/proxy/mock_proxy_resolver.cc
@@ -11,61 +11,74 @@
namespace net {
-MockAsyncProxyResolver::Request::Request(MockAsyncProxyResolver* resolver,
- const GURL& url,
- ProxyInfo* results,
- const CompletionCallback& callback)
+MockAsyncProxyResolver::RequestImpl::RequestImpl(scoped_ptr<Job> job)
+ : job_(std::move(job)) {
+ DCHECK(job_);
+}
+
+MockAsyncProxyResolver::RequestImpl::~RequestImpl() {
+ MockAsyncProxyResolver* resolver = job_->Resolver();
+ // AddCancelledJob will check if request is already cancelled
+ resolver->AddCancelledJob(std::move(job_));
+}
+
+LoadState MockAsyncProxyResolver::RequestImpl::GetLoadState() {
+ return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
+}
+
+MockAsyncProxyResolver::Job::Job(MockAsyncProxyResolver* resolver,
+ const GURL& url,
+ ProxyInfo* results,
+ const CompletionCallback& callback)
: resolver_(resolver),
url_(url),
results_(results),
callback_(callback),
- origin_loop_(base::MessageLoop::current()) {
-}
+ origin_loop_(base::MessageLoop::current()) {}
+
+MockAsyncProxyResolver::Job::~Job() {}
-void MockAsyncProxyResolver::Request::CompleteNow(int rv) {
+void MockAsyncProxyResolver::Job::CompleteNow(int rv) {
CompletionCallback callback = callback_;
- // May delete |this|.
- resolver_->RemovePendingRequest(this);
+ resolver_->RemovePendingJob(this);
callback.Run(rv);
}
-MockAsyncProxyResolver::Request::~Request() {}
-
MockAsyncProxyResolver::~MockAsyncProxyResolver() {}
int MockAsyncProxyResolver::GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
- RequestHandle* request_handle,
+ scoped_ptr<Request>* request,
const BoundNetLog& /*net_log*/) {
- scoped_refptr<Request> request = new Request(this, url, results, callback);
- pending_requests_.push_back(request);
+ scoped_ptr<Job> job(new Job(this, url, results, callback));
- if (request_handle)
- *request_handle = reinterpret_cast<RequestHandle>(request.get());
+ pending_jobs_.push_back(job.get());
+ request->reset(new RequestImpl(std::move(job)));
- // Test code completes the request by calling request->CompleteNow().
+ // Test code completes the request by calling job->CompleteNow().
return ERR_IO_PENDING;
}
-void MockAsyncProxyResolver::CancelRequest(RequestHandle request_handle) {
- scoped_refptr<Request> request = reinterpret_cast<Request*>(request_handle);
- cancelled_requests_.push_back(request);
- RemovePendingRequest(request.get());
+void MockAsyncProxyResolver::AddCancelledJob(scoped_ptr<Job> job) {
+ std::vector<Job*>::iterator it =
+ std::find(pending_jobs_.begin(), pending_jobs_.end(), job.get());
+ // Because this is called always when RequestImpl is destructed,
+ // we need to check if it is still in pending jobs.
+ if (it != pending_jobs_.end()) {
+ cancelled_jobs_.push_back(std::move(job));
+ pending_jobs_.erase(it);
+ }
}
-LoadState MockAsyncProxyResolver::GetLoadState(
- RequestHandle request_handle) const {
- return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
-}
-
-void MockAsyncProxyResolver::RemovePendingRequest(Request* request) {
- RequestsList::iterator it = std::find(
- pending_requests_.begin(), pending_requests_.end(), request);
- DCHECK(it != pending_requests_.end());
- pending_requests_.erase(it);
+void MockAsyncProxyResolver::RemovePendingJob(Job* job) {
+ DCHECK(job);
+ std::vector<Job*>::iterator it =
+ std::find(pending_jobs_.begin(), pending_jobs_.end(), job);
+ DCHECK(it != pending_jobs_.end());
+ pending_jobs_.erase(it);
}
MockAsyncProxyResolver::MockAsyncProxyResolver() {
@@ -165,17 +178,9 @@ ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl)
int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url,
ProxyInfo* results,
const CompletionCallback& callback,
- RequestHandle* request,
+ scoped_ptr<Request>* request,
const BoundNetLog& net_log) {
return impl_->GetProxyForURL(query_url, results, callback, request, net_log);
}
-void ForwardingProxyResolver::CancelRequest(RequestHandle request) {
- impl_->CancelRequest(request);
-}
-
-LoadState ForwardingProxyResolver::GetLoadState(RequestHandle request) const {
- return impl_->GetLoadState(request);
-}
-
} // namespace net
« no previous file with comments | « net/proxy/mock_proxy_resolver.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698