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

Unified Diff: net/proxy/multi_threaded_proxy_resolver.cc

Issue 8985012: base::Bind: Convert net/proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more include. Created 9 years 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/multi_threaded_proxy_resolver.h ('k') | net/proxy/multi_threaded_proxy_resolver_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/multi_threaded_proxy_resolver.cc
diff --git a/net/proxy/multi_threaded_proxy_resolver.cc b/net/proxy/multi_threaded_proxy_resolver.cc
index 03c3e44a32fd78fe5e6e155f0475372e384872aa..e971f6c3645b5916455e739eada13f7b3cc3aa34 100644
--- a/net/proxy/multi_threaded_proxy_resolver.cc
+++ b/net/proxy/multi_threaded_proxy_resolver.cc
@@ -4,6 +4,7 @@
#include "net/proxy/multi_threaded_proxy_resolver.h"
+#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
@@ -100,9 +101,9 @@ class MultiThreadedProxyResolver::Job
TYPE_SET_PAC_SCRIPT_INTERNAL,
};
- Job(Type type, OldCompletionCallback* user_callback)
+ Job(Type type, const CompletionCallback& callback)
: type_(type),
- user_callback_(user_callback),
+ callback_(callback),
executor_(NULL),
was_cancelled_(false) {
}
@@ -133,8 +134,8 @@ class MultiThreadedProxyResolver::Job
// scheduled internally (for example TYPE_SET_PAC_SCRIPT_INTERNAL).
//
// Otherwise jobs that correspond with user-initiated work will
- // have a non-NULL callback up until the callback is run.
- bool has_user_callback() const { return user_callback_ != NULL; }
+ // have a non-null callback up until the callback is run.
+ bool has_user_callback() const { return !callback_.is_null(); }
// This method is called when the job is inserted into a wait queue
// because no executors were ready to accept it.
@@ -157,10 +158,10 @@ class MultiThreadedProxyResolver::Job
void RunUserCallback(int result) {
DCHECK(has_user_callback());
- OldCompletionCallback* callback = user_callback_;
- // Null the callback so has_user_callback() will now return false.
- user_callback_ = NULL;
- callback->Run(result);
+ CompletionCallback callback = callback_;
+ // Reset the callback so has_user_callback() will now return false.
+ callback_.Reset();
+ callback.Run(result);
}
friend class base::RefCountedThreadSafe<MultiThreadedProxyResolver::Job>;
@@ -169,7 +170,7 @@ class MultiThreadedProxyResolver::Job
private:
const Type type_;
- OldCompletionCallback* user_callback_;
+ CompletionCallback callback_;
Executor* executor_;
bool was_cancelled_;
};
@@ -181,8 +182,9 @@ class MultiThreadedProxyResolver::SetPacScriptJob
: public MultiThreadedProxyResolver::Job {
public:
SetPacScriptJob(const scoped_refptr<ProxyResolverScriptData>& script_data,
- OldCompletionCallback* callback)
- : Job(callback ? TYPE_SET_PAC_SCRIPT : TYPE_SET_PAC_SCRIPT_INTERNAL,
+ const CompletionCallback& callback)
+ : Job(!callback.is_null() ? TYPE_SET_PAC_SCRIPT :
+ TYPE_SET_PAC_SCRIPT_INTERNAL,
callback),
script_data_(script_data) {
}
@@ -190,12 +192,12 @@ class MultiThreadedProxyResolver::SetPacScriptJob
// Runs on the worker thread.
virtual void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) OVERRIDE {
ProxyResolver* resolver = executor()->resolver();
- int rv = resolver->SetPacScript(script_data_, NULL);
+ int rv = resolver->SetPacScript(script_data_, CompletionCallback());
DCHECK_NE(rv, ERR_IO_PENDING);
origin_loop->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &SetPacScriptJob::RequestComplete, rv));
+ base::Bind(&SetPacScriptJob::RequestComplete, this, rv));
}
private:
@@ -220,14 +222,14 @@ class MultiThreadedProxyResolver::GetProxyForURLJob
// |results| -- the structure to fill with proxy resolve results.
GetProxyForURLJob(const GURL& url,
ProxyInfo* results,
- OldCompletionCallback* callback,
+ const CompletionCallback& callback,
const BoundNetLog& net_log)
: Job(TYPE_GET_PROXY_FOR_URL, callback),
results_(results),
net_log_(net_log),
url_(url),
was_waiting_for_thread_(false) {
- DCHECK(callback);
+ DCHECK(!callback.is_null());
}
BoundNetLog* net_log() { return &net_log_; }
@@ -256,12 +258,12 @@ class MultiThreadedProxyResolver::GetProxyForURLJob
virtual void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) OVERRIDE {
ProxyResolver* resolver = executor()->resolver();
int rv = resolver->GetProxyForURL(
- url_, &results_buf_, NULL, NULL, net_log_);
+ url_, &results_buf_, CompletionCallback(), NULL, net_log_);
DCHECK_NE(rv, ERR_IO_PENDING);
origin_loop->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &GetProxyForURLJob::QueryComplete, rv));
+ base::Bind(&GetProxyForURLJob::QueryComplete, this, rv));
}
private:
@@ -320,8 +322,7 @@ void MultiThreadedProxyResolver::Executor::StartJob(Job* job) {
job->FinishedWaitingForThread();
thread_->message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(job, &Job::Run,
- base::MessageLoopProxy::current()));
+ base::Bind(&Job::Run, job, base::MessageLoopProxy::current()));
}
void MultiThreadedProxyResolver::Executor::OnJobCompleted(Job* job) {
@@ -366,7 +367,7 @@ void MultiThreadedProxyResolver::Executor::PurgeMemory() {
scoped_refptr<PurgeMemoryTask> helper(new PurgeMemoryTask(resolver_.get()));
thread_->message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(helper.get(), &PurgeMemoryTask::PurgeMemory));
+ base::Bind(&PurgeMemoryTask::PurgeMemory, helper.get()));
}
MultiThreadedProxyResolver::Executor::~Executor() {
@@ -395,13 +396,11 @@ MultiThreadedProxyResolver::~MultiThreadedProxyResolver() {
ReleaseAllExecutors();
}
-int MultiThreadedProxyResolver::GetProxyForURL(const GURL& url,
- ProxyInfo* results,
- OldCompletionCallback* callback,
- RequestHandle* request,
- const BoundNetLog& net_log) {
+int MultiThreadedProxyResolver::GetProxyForURL(
+ const GURL& url, ProxyInfo* results, const CompletionCallback& callback,
+ RequestHandle* request, const BoundNetLog& net_log) {
DCHECK(CalledOnValidThread());
- DCHECK(callback);
+ DCHECK(!callback.is_null());
DCHECK(current_script_data_.get())
<< "Resolver is un-initialized. Must call SetPacScript() first!";
@@ -431,7 +430,7 @@ int MultiThreadedProxyResolver::GetProxyForURL(const GURL& url,
if (executors_.size() < max_num_threads_) {
executor = AddNewExecutor();
executor->StartJob(
- new SetPacScriptJob(current_script_data_, NULL));
+ new SetPacScriptJob(current_script_data_, CompletionCallback()));
}
return ERR_IO_PENDING;
@@ -498,9 +497,9 @@ void MultiThreadedProxyResolver::PurgeMemory() {
int MultiThreadedProxyResolver::SetPacScript(
const scoped_refptr<ProxyResolverScriptData>& script_data,
- OldCompletionCallback* callback) {
+ const CompletionCallback&callback) {
DCHECK(CalledOnValidThread());
- DCHECK(callback);
+ DCHECK(!callback.is_null());
// Save the script details, so we can provision new executors later.
current_script_data_ = script_data;
« no previous file with comments | « net/proxy/multi_threaded_proxy_resolver.h ('k') | net/proxy/multi_threaded_proxy_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698