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

Unified Diff: base/critical_closure.h

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 years, 3 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
« no previous file with comments | « base/callback_forward.h ('k') | base/debug/task_annotator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/critical_closure.h
diff --git a/base/critical_closure.h b/base/critical_closure.h
index 6ebd7afa503ce66d6b12c36fe5bfb9d1dbb80103..9970976ed71f7d5bde46feb6754555fea2c69c24 100644
--- a/base/critical_closure.h
+++ b/base/critical_closure.h
@@ -22,27 +22,13 @@ namespace internal {
// Returns true if multi-tasking is supported on this iOS device.
bool IsMultiTaskingSupported();
-// This class wraps a closure so it can continue to run for a period of time
+// This function wraps a closure so it can continue to run for a period of time
// when the application goes to the background by using
// |ios::ScopedCriticalAction|.
-template <typename R>
-class CriticalClosure {
- public:
- explicit CriticalClosure(const Callback<R(void)>& closure)
- : closure_(closure) {}
-
- ~CriticalClosure() {}
-
- R Run() {
- return closure_.Run();
- }
-
- private:
- ios::ScopedCriticalAction critical_action_;
- Callback<R(void)> closure_;
-
- DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
-};
+template <typename R, typename CallbackType>
+R RunCriticalClosure(ios::ScopedCriticalAction*, CallbackType closure) {
+ return std::forward<CallbackType>(closure).Run();
+}
#endif // defined(OS_IOS)
} // namespace internal
@@ -63,14 +49,28 @@ class CriticalClosure {
// before posting.
#if defined(OS_IOS)
template <typename R>
-Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
+RepeatingCallback<R()> MakeCriticalClosure(RepeatingCallback<R()> closure) {
DCHECK(internal::IsMultiTaskingSupported());
- return base::Bind(&internal::CriticalClosure<R>::Run,
- Owned(new internal::CriticalClosure<R>(closure)));
+ return base::BindRepeating(
+ &internal::RunCriticalClosure<R, RepeatingCallback<R()>>,
+ base::Owned(new ios::ScopedCriticalAction),
+ std::move(closure));
}
-#else // defined(OS_IOS)
+
template <typename R>
-inline Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
+OnceCallback<R()> MakeCriticalClosure(OnceCallback<R()> closure) {
+ DCHECK(internal::IsMultiTaskingSupported());
+ return base::BindOnce(
+ &internal::RunCriticalClosure<R, OnceCallback<R()>>,
+ base::Owned(new ios::ScopedCriticalAction),
+ std::move(closure));
+}
+#else // defined(OS_IOS)
+template <typename R,
+ internal::CopyMode copy_mode,
+ internal::RepeatMode repeat_mode>
+inline Callback<R(), copy_mode, repeat_mode> MakeCriticalClosure(
+ Callback<R(), copy_mode, repeat_mode> closure) {
// No-op for platforms where the application does not need to acquire
// background time for closures to finish when it goes into the background.
return closure;
« no previous file with comments | « base/callback_forward.h ('k') | base/debug/task_annotator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698