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

Unified Diff: chrome/common/cancelable_task_tracker.cc

Issue 11410073: Add function to CancelableTaskTracker and convert BootTimeLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again and add tests Created 8 years, 1 month 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 | « chrome/common/cancelable_task_tracker.h ('k') | chrome/common/cancelable_task_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/cancelable_task_tracker.cc
diff --git a/chrome/common/cancelable_task_tracker.cc b/chrome/common/cancelable_task_tracker.cc
index 3570e0577fab680dea9e372ffaf91c865e91979e..28ee436455276543278edebed89b1c6b00a8326f 100644
--- a/chrome/common/cancelable_task_tracker.cc
+++ b/chrome/common/cancelable_task_tracker.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "base/synchronization/cancellation_flag.h"
@@ -33,6 +34,18 @@ void RunIfNotCanceledThenUntrack(const CancellationFlag* flag,
untrack.Run();
}
+bool IsCanceled(const CancellationFlag* flag,
+ base::ScopedClosureRunner* untrack_runner) {
+ return flag->IsSet();
+}
+
+void RunOrPostToTaskRunner(TaskRunner* task_runner, const Closure& closure) {
+ if (task_runner->RunsTasksOnCurrentThread())
+ closure.Run();
+ else
+ task_runner->PostTask(FROM_HERE, closure);
+}
+
} // namespace
// static
@@ -84,6 +97,29 @@ CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply(
return id;
}
+CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId(
+ IsCanceledCallback* is_canceled_cb) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(base::MessageLoopProxy::current());
+
+ TaskId id = next_id_;
+ next_id_++; // int64 is big enough that we ignore the potential overflow.
+
+ // Both owned by |is_canceled_cb|.
+ CancellationFlag* flag = new CancellationFlag();
+ base::ScopedClosureRunner* untrack_runner = new base::ScopedClosureRunner(
+ Bind(&RunOrPostToTaskRunner,
+ base::MessageLoopProxy::current(),
+ Bind(&CancelableTaskTracker::Untrack,
+ weak_factory_.GetWeakPtr(), id)));
+
+ *is_canceled_cb = Bind(&IsCanceled,
+ base::Owned(flag),
+ base::Owned(untrack_runner));
+ Track(id, flag);
+ return id;
+}
+
void CancelableTaskTracker::TryCancel(TaskId id) {
DCHECK(thread_checker_.CalledOnValidThread());
« no previous file with comments | « chrome/common/cancelable_task_tracker.h ('k') | chrome/common/cancelable_task_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698