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

Unified Diff: base/worker_pool.h

Issue 6094005: Create "Prebind" a wrapper to tr1::bind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Closure example ported to Prebinds Created 10 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
Index: base/worker_pool.h
diff --git a/base/worker_pool.h b/base/worker_pool.h
index e0b75a9a753ad1169a16cea9cbb2de6c9295131e..c81ca1d50a5b383052ab1be856e100c325d7642a 100644
--- a/base/worker_pool.h
+++ b/base/worker_pool.h
@@ -7,6 +7,8 @@
#pragma once
#include "base/tracked.h"
+#include "base/closure.h"
+#include "base/task.h"
class Task;
@@ -26,6 +28,33 @@ class WorkerPool {
// return value, ownership of |task| is transferred to the worker pool.
static bool PostTask(const tracked_objects::Location& from_here,
Task* task, bool task_is_slow);
+ static bool PostClosure(const tracked_objects::Location& from_here,
+ base::Closure closure, bool task_is_slow) {
+ // The wrapping of Closure in Task will screw up task tracking...that will
+ // be fixed if we actually wave the Closure class through the API
+ // correctly.
+ return PostTask(from_here, new ClosureTaskAdapter(from_here, closure),
+ task_is_slow);
+ }
+
+private:
+ // This is a complete hack just for the proof of concept. Really, we want
+ // to modify PendingTask to understand base::Closure.
+ class ClosureTaskAdapter : public Task {
+ public:
+ explicit ClosureTaskAdapter(const tracked_objects::Location& from_here,
+ base::Closure c)
+ : closure_(c) {
+ closure_.tracked()->SetBirthPlace(from_here);
+ }
+
+ virtual void Run() {
+ closure_();
+ }
+
+ private:
+ base::Closure closure_;
+ };
};
#endif // BASE_WORKER_POOL_H_

Powered by Google App Engine
This is Rietveld 408576698