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

Unified Diff: chrome/browser/chrome_benchmarking_message_filter.cc

Issue 8897026: Reland r113263 rebased after revert of r113249. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | net/disk_cache/backend_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_benchmarking_message_filter.cc
diff --git a/chrome/browser/chrome_benchmarking_message_filter.cc b/chrome/browser/chrome_benchmarking_message_filter.cc
index 577679c811f9473578fb426dd42ed9c8932096b4..3421192daefe3e18283f1ea279421ae9a995fad4 100644
--- a/chrome/browser/chrome_benchmarking_message_filter.cc
+++ b/chrome/browser/chrome_benchmarking_message_filter.cc
@@ -4,7 +4,10 @@
#include "chrome/browser/chrome_benchmarking_message_filter.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/profiles/profile.h"
@@ -19,18 +22,17 @@
namespace {
-class ClearCacheCompletion : public net::OldCompletionCallback {
+class ClearCacheHelper {
public:
- ClearCacheCompletion(ChromeBenchmarkingMessageFilter* filter,
- IPC::Message* reply_msg)
+ ClearCacheHelper(ChromeBenchmarkingMessageFilter* filter,
awong 2011/12/12 18:52:58 Can this be reduced to just a single function that
James Hawkins 2011/12/12 20:40:22 No, the callback being used is a CompletionCallbac
+ IPC::Message* reply_msg)
: filter_(filter),
reply_msg_(reply_msg) {
}
- virtual void RunWithParams(const Tuple1<int>& params) {
- ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, params.a);
+ void Run(int result) {
+ ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg_, result);
filter_->Send(reply_msg_);
- delete this;
}
private:
@@ -46,21 +48,25 @@ class DoomEntriesHelper {
: backend_(backend),
entry_(NULL),
iter_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_(this,
- &DoomEntriesHelper::CacheCallback)),
- user_callback_(NULL) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ base::Bind(&DoomEntriesHelper::CacheCallback,
+ base::Unretained(this)))),
+ clear_cache_helper_(NULL) {
}
- void ClearCache(ClearCacheCompletion* callback) {
- user_callback_ = callback;
+ // Takes ownership of |callback|.
+ void ClearCache(ClearCacheHelper* helper) {
+ clear_cache_helper_.reset(helper);
return CacheCallback(net::OK); // Start clearing the cache.
}
+ const net::CompletionCallback& callback() { return callback_; }
+
private:
void CacheCallback(int result) {
do {
if (result != net::OK) {
- user_callback_->RunWithParams(Tuple1<int>(result));
+ clear_cache_helper_->Run(result);
delete this;
return;
}
@@ -76,15 +82,15 @@ class DoomEntriesHelper {
entry_->Close();
entry_ = NULL;
}
- result = backend_->OpenNextEntry(&iter_, &entry_, &callback_);
+ result = backend_->OpenNextEntry(&iter_, &entry_, callback_);
} while (result != net::ERR_IO_PENDING);
}
disk_cache::Backend* backend_;
disk_cache::Entry* entry_;
void* iter_;
- net::OldCompletionCallbackImpl<DoomEntriesHelper> callback_;
- ClearCacheCompletion* user_callback_;
+ net::CompletionCallback callback_;
+ scoped_ptr<ClearCacheHelper> clear_cache_helper_;
};
} // namespace
@@ -132,20 +138,20 @@ void ChromeBenchmarkingMessageFilter::OnClearCache(bool preserve_ssl_host_info,
disk_cache::Backend* backend = request_context_->GetURLRequestContext()->
http_transaction_factory()->GetCache()->GetCurrentBackend();
if (backend) {
- ClearCacheCompletion* callback =
- new ClearCacheCompletion(this, reply_msg);
+ scoped_ptr<ClearCacheHelper> clear_cache_helper(
+ new ClearCacheHelper(this, reply_msg));
if (preserve_ssl_host_info) {
DoomEntriesHelper* helper = new DoomEntriesHelper(backend);
- helper->ClearCache(callback); // Will self clean.
+ helper->ClearCache(clear_cache_helper.release()); // Will self clean.
return;
} else {
- rv = backend->DoomAllEntries(callback);
+ rv = backend->DoomAllEntries(
+ base::Bind(&ClearCacheHelper::Run,
+ base::Owned(clear_cache_helper.release())));
if (rv == net::ERR_IO_PENDING) {
// The callback will send the reply.
return;
}
- // Completed synchronously, no need for the callback.
- delete callback;
}
}
ChromeViewHostMsg_ClearCache::WriteReplyParams(reply_msg, rv);
« no previous file with comments | « no previous file | net/disk_cache/backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698