Commit 7f4ad940 authored by jhawkins@chromium.org's avatar jhawkins@chromium.org

base::Bind: Make use of partial currying to get rid of a helper class.

BUG=none
TEST=none
R=ajwong

Review URL: http://codereview.chromium.org/8919016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114122 0039d316-1c4b-4281-b951-d872f2087c98
parent 9fc206d7
......@@ -124,7 +124,7 @@
// There are three main components to the system:
// 1) The Callback classes.
// 2) The Bind() functions.
// 3) The arguments wrappers (eg., Unretained() and ConstRef()).
// 3) The arguments wrappers (e.g., Unretained() and ConstRef()).
//
// The Callback classes represent a generic function pointer. Internally,
// it stores a refcounted piece of state that represents the target function
......@@ -160,7 +160,7 @@
// to refcount a target object if the function being bound is a class method.
//
// To change this behavior, we introduce a set of argument wrappers
// (eg. Unretained(), and ConstRef()). These are simple container templates
// (e.g., Unretained(), and ConstRef()). These are simple container templates
// that are passed by value, and wrap a pointer to argument. See the
// file-level comment in base/bind_helpers.h for more info.
//
......@@ -197,7 +197,7 @@
// Lastly, tr1::function and tr1::bind has a more general and flexible API.
// This includes things like argument reordering by use of
// tr1::bind::placeholder, support for non-const reference parameters, and some
// limited amount of subtyping of the tr1::function object (eg.,
// limited amount of subtyping of the tr1::function object (e.g.,
// tr1::function<int(int)> is convertible to tr1::function<void(int)>).
//
// These are not features that are required in Chromium. Some of them, such as
......
......@@ -129,7 +129,7 @@ $var MAX_ARITY = 7
// There are three main components to the system:
// 1) The Callback classes.
// 2) The Bind() functions.
// 3) The arguments wrappers (eg., Unretained() and ConstRef()).
// 3) The arguments wrappers (e.g., Unretained() and ConstRef()).
//
// The Callback classes represent a generic function pointer. Internally,
// it stores a refcounted piece of state that represents the target function
......@@ -165,7 +165,7 @@ $var MAX_ARITY = 7
// to refcount a target object if the function being bound is a class method.
//
// To change this behavior, we introduce a set of argument wrappers
// (eg. Unretained(), and ConstRef()). These are simple container templates
// (e.g., Unretained(), and ConstRef()). These are simple container templates
// that are passed by value, and wrap a pointer to argument. See the
// file-level comment in base/bind_helpers.h for more info.
//
......@@ -202,7 +202,7 @@ $var MAX_ARITY = 7
// Lastly, tr1::function and tr1::bind has a more general and flexible API.
// This includes things like argument reordering by use of
// tr1::bind::placeholder, support for non-const reference parameters, and some
// limited amount of subtyping of the tr1::function object (eg.,
// limited amount of subtyping of the tr1::function object (e.g.,
// tr1::function<int(int)> is convertible to tr1::function<void(int)>).
//
// These are not features that are required in Chromium. Some of them, such as
......
......@@ -22,23 +22,12 @@
namespace {
class ClearCacheHelper {
public:
ClearCacheHelper(ChromeBenchmarkingMessageFilter* filter,
IPC::Message* reply_msg)
: filter_(filter),
reply_msg_(reply_msg) {
}
void Run(int result) {
ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, result);
filter_->Send(reply_msg_);
}
private:
scoped_refptr<ChromeBenchmarkingMessageFilter> filter_;
IPC::Message* reply_msg_;
};
void ClearCacheCallback(ChromeBenchmarkingMessageFilter* filter,
IPC::Message* reply_msg,
int result) {
ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, result);
filter->Send(reply_msg);
}
// Class to assist with clearing out the cache when we want to preserve
// the sslhostinfo entries. It's not very efficient, but its just for debug.
......@@ -50,13 +39,11 @@ class DoomEntriesHelper {
iter_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
base::Bind(&DoomEntriesHelper::CacheCallback,
base::Unretained(this)))),
clear_cache_helper_(NULL) {
base::Unretained(this)))) {
}
// Takes ownership of |callback|.
void ClearCache(ClearCacheHelper* helper) {
clear_cache_helper_.reset(helper);
void ClearCache(const net::CompletionCallback& callback) {
clear_cache_callback_ = callback;
return CacheCallback(net::OK); // Start clearing the cache.
}
......@@ -66,7 +53,7 @@ class DoomEntriesHelper {
void CacheCallback(int result) {
do {
if (result != net::OK) {
clear_cache_helper_->Run(result);
clear_cache_callback_.Run(result);
delete this;
return;
}
......@@ -90,7 +77,7 @@ class DoomEntriesHelper {
disk_cache::Entry* entry_;
void* iter_;
net::CompletionCallback callback_;
scoped_ptr<ClearCacheHelper> clear_cache_helper_;
net::CompletionCallback clear_cache_callback_;
};
} // namespace
......@@ -138,16 +125,14 @@ void ChromeBenchmarkingMessageFilter::OnClearCache(bool preserve_ssl_host_info,
disk_cache::Backend* backend = request_context_->GetURLRequestContext()->
http_transaction_factory()->GetCache()->GetCurrentBackend();
if (backend) {
scoped_ptr<ClearCacheHelper> clear_cache_helper(
new ClearCacheHelper(this, reply_msg));
net::CompletionCallback callback =
base::Bind(&ClearCacheCallback, make_scoped_refptr(this), reply_msg);
if (preserve_ssl_host_info) {
DoomEntriesHelper* helper = new DoomEntriesHelper(backend);
helper->ClearCache(clear_cache_helper.release()); // Will self clean.
helper->ClearCache(callback); // Will self clean.
return;
} else {
rv = backend->DoomAllEntries(
base::Bind(&ClearCacheHelper::Run,
base::Owned(clear_cache_helper.release())));
rv = backend->DoomAllEntries(callback);
if (rv == net::ERR_IO_PENDING) {
// The callback will send the reply.
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment