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 @@ ...@@ -124,7 +124,7 @@
// There are three main components to the system: // There are three main components to the system:
// 1) The Callback classes. // 1) The Callback classes.
// 2) The Bind() functions. // 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, // The Callback classes represent a generic function pointer. Internally,
// it stores a refcounted piece of state that represents the target function // it stores a refcounted piece of state that represents the target function
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
// to refcount a target object if the function being bound is a class method. // 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 // 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 // that are passed by value, and wrap a pointer to argument. See the
// file-level comment in base/bind_helpers.h for more info. // file-level comment in base/bind_helpers.h for more info.
// //
...@@ -197,7 +197,7 @@ ...@@ -197,7 +197,7 @@
// Lastly, tr1::function and tr1::bind has a more general and flexible API. // Lastly, tr1::function and tr1::bind has a more general and flexible API.
// This includes things like argument reordering by use of // This includes things like argument reordering by use of
// tr1::bind::placeholder, support for non-const reference parameters, and some // 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)>). // 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 // These are not features that are required in Chromium. Some of them, such as
......
...@@ -129,7 +129,7 @@ $var MAX_ARITY = 7 ...@@ -129,7 +129,7 @@ $var MAX_ARITY = 7
// There are three main components to the system: // There are three main components to the system:
// 1) The Callback classes. // 1) The Callback classes.
// 2) The Bind() functions. // 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, // The Callback classes represent a generic function pointer. Internally,
// it stores a refcounted piece of state that represents the target function // it stores a refcounted piece of state that represents the target function
...@@ -165,7 +165,7 @@ $var MAX_ARITY = 7 ...@@ -165,7 +165,7 @@ $var MAX_ARITY = 7
// to refcount a target object if the function being bound is a class method. // 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 // 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 // that are passed by value, and wrap a pointer to argument. See the
// file-level comment in base/bind_helpers.h for more info. // file-level comment in base/bind_helpers.h for more info.
// //
...@@ -202,7 +202,7 @@ $var MAX_ARITY = 7 ...@@ -202,7 +202,7 @@ $var MAX_ARITY = 7
// Lastly, tr1::function and tr1::bind has a more general and flexible API. // Lastly, tr1::function and tr1::bind has a more general and flexible API.
// This includes things like argument reordering by use of // This includes things like argument reordering by use of
// tr1::bind::placeholder, support for non-const reference parameters, and some // 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)>). // 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 // These are not features that are required in Chromium. Some of them, such as
......
...@@ -22,23 +22,12 @@ ...@@ -22,23 +22,12 @@
namespace { namespace {
class ClearCacheHelper { void ClearCacheCallback(ChromeBenchmarkingMessageFilter* filter,
public: IPC::Message* reply_msg,
ClearCacheHelper(ChromeBenchmarkingMessageFilter* filter, int result) {
IPC::Message* reply_msg) ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, result);
: filter_(filter), filter->Send(reply_msg);
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_;
};
// Class to assist with clearing out the cache when we want to preserve // 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. // the sslhostinfo entries. It's not very efficient, but its just for debug.
...@@ -50,13 +39,11 @@ class DoomEntriesHelper { ...@@ -50,13 +39,11 @@ class DoomEntriesHelper {
iter_(NULL), iter_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(callback_( ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
base::Bind(&DoomEntriesHelper::CacheCallback, base::Bind(&DoomEntriesHelper::CacheCallback,
base::Unretained(this)))), base::Unretained(this)))) {
clear_cache_helper_(NULL) {
} }
// Takes ownership of |callback|. void ClearCache(const net::CompletionCallback& callback) {
void ClearCache(ClearCacheHelper* helper) { clear_cache_callback_ = callback;
clear_cache_helper_.reset(helper);
return CacheCallback(net::OK); // Start clearing the cache. return CacheCallback(net::OK); // Start clearing the cache.
} }
...@@ -66,7 +53,7 @@ class DoomEntriesHelper { ...@@ -66,7 +53,7 @@ class DoomEntriesHelper {
void CacheCallback(int result) { void CacheCallback(int result) {
do { do {
if (result != net::OK) { if (result != net::OK) {
clear_cache_helper_->Run(result); clear_cache_callback_.Run(result);
delete this; delete this;
return; return;
} }
...@@ -90,7 +77,7 @@ class DoomEntriesHelper { ...@@ -90,7 +77,7 @@ class DoomEntriesHelper {
disk_cache::Entry* entry_; disk_cache::Entry* entry_;
void* iter_; void* iter_;
net::CompletionCallback callback_; net::CompletionCallback callback_;
scoped_ptr<ClearCacheHelper> clear_cache_helper_; net::CompletionCallback clear_cache_callback_;
}; };
} // namespace } // namespace
...@@ -138,16 +125,14 @@ void ChromeBenchmarkingMessageFilter::OnClearCache(bool preserve_ssl_host_info, ...@@ -138,16 +125,14 @@ void ChromeBenchmarkingMessageFilter::OnClearCache(bool preserve_ssl_host_info,
disk_cache::Backend* backend = request_context_->GetURLRequestContext()-> disk_cache::Backend* backend = request_context_->GetURLRequestContext()->
http_transaction_factory()->GetCache()->GetCurrentBackend(); http_transaction_factory()->GetCache()->GetCurrentBackend();
if (backend) { if (backend) {
scoped_ptr<ClearCacheHelper> clear_cache_helper( net::CompletionCallback callback =
new ClearCacheHelper(this, reply_msg)); base::Bind(&ClearCacheCallback, make_scoped_refptr(this), reply_msg);
if (preserve_ssl_host_info) { if (preserve_ssl_host_info) {
DoomEntriesHelper* helper = new DoomEntriesHelper(backend); DoomEntriesHelper* helper = new DoomEntriesHelper(backend);
helper->ClearCache(clear_cache_helper.release()); // Will self clean. helper->ClearCache(callback); // Will self clean.
return; return;
} else { } else {
rv = backend->DoomAllEntries( rv = backend->DoomAllEntries(callback);
base::Bind(&ClearCacheHelper::Run,
base::Owned(clear_cache_helper.release())));
if (rv == net::ERR_IO_PENDING) { if (rv == net::ERR_IO_PENDING) {
// The callback will send the reply. // The callback will send the reply.
return; 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