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

Unified Diff: chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump

Issue 304153007: [SyncFS][Reland] Relay callback destruction to TaskRunner on RelayCallbackToTaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wrap .h.pump to 80 chars Created 6 years, 7 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
Index: chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump
diff --git a/chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump b/chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump
index cbd1c9fda521a7c5733e5cc323d5ae8316f2a442..a94c32620433188e2aaa1fdd6ac474e5e3c15674 100644
--- a/chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump
+++ b/chrome/browser/sync_file_system/drive_backend/callback_helper.h.pump
@@ -17,6 +17,7 @@ $var MAX_ARITY = 7
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/sequenced_task_runner.h"
#include "base/thread_task_runner_handle.h"
// TODO(tzik): Merge this file to media/base/bind_to_current_loop.h.
@@ -42,6 +43,36 @@ RebindForward(T& t) {
return t;
}
+template <typename T>
+class CallbackHolder {
+ public:
+ CallbackHolder(base::SequencedTaskRunner* task_runner,
+ const tracked_objects::Location& from_here,
+ const base::Callback<T>& callback)
+ : task_runner_(task_runner),
+ from_here_(from_here),
+ callback_(new base::Callback<T>(callback)) {
+ DCHECK(task_runner_);
+ }
+
+ ~CallbackHolder() {
+ base::Callback<T>* callback = callback_.release();
+ if (!task_runner_->DeleteSoon(from_here_, callback))
+ delete callback;
+ }
+
+ base::SequencedTaskRunner* task_runner() const { return task_runner_; }
+ const tracked_objects::Location& from_here() const { return from_here_; }
+ const base::Callback<T>& callback() const { return *callback_; }
+
+ private:
+ scoped_refptr<base::SequencedTaskRunner> task_runner_;
+ const tracked_objects::Location from_here_;
+ scoped_ptr<base::Callback<T> > callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(CallbackHolder);
+};
+
template <typename>
struct RelayToTaskRunnerHelper;
@@ -51,13 +82,12 @@ $range ARG 1..ARITY
template <$for ARG , [[typename A$(ARG)]]>
struct RelayToTaskRunnerHelper<void($for ARG , [[A$(ARG)]])> {
- static void Run(base::TaskRunner* task_runner,
- const tracked_objects::Location& from_here,
- const base::Callback<void($for ARG , [[A$(ARG)]])>& callback
+ static void Run(CallbackHolder<void($for ARG , [[A$(ARG)]])>* holder
$if ARITY != 0 [[, ]]
$for ARG , [[A$(ARG) a$(ARG)]]
) {
- task_runner->PostTask(from_here, base::Bind(callback
+ holder->task_runner()->PostTask(
+ holder->from_here(), base::Bind(holder->callback()
$if ARITY != 0 [[, ]]
$for ARG , [[RebindForward(a$(ARG))]]));
}
@@ -69,7 +99,7 @@ $for ARG , [[RebindForward(a$(ARG))]]));
template <typename T>
base::Callback<T> RelayCallbackToTaskRunner(
- base::TaskRunner* task_runner,
+ base::SequencedTaskRunner* task_runner,
const tracked_objects::Location& from_here,
const base::Callback<T>& callback) {
DCHECK(task_runner->RunsTasksOnCurrentThread());
@@ -78,8 +108,8 @@ base::Callback<T> RelayCallbackToTaskRunner(
return base::Callback<T>();
return base::Bind(&internal::RelayToTaskRunnerHelper<T>::Run,
- make_scoped_refptr(task_runner), from_here,
- callback);
+ base::Owned(new internal::CallbackHolder<T>(
+ task_runner, from_here, callback)));
}
template <typename T>

Powered by Google App Engine
This is Rietveld 408576698