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; |