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

Unified Diff: base/critical_closure.h

Issue 257003007: Introduce a new framework for back-and-forth tracked/protected preferences migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +cleanup-only tests 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: base/critical_closure.h
diff --git a/base/critical_closure.h b/base/critical_closure.h
index ca51ed5cef27d40923ba8e4d99de4044c63fa457..a3f969496492d1881acdc2a87d0466870e766e2f 100644
--- a/base/critical_closure.h
+++ b/base/critical_closure.h
@@ -7,9 +7,45 @@
#include "base/callback.h"
+#if defined(OS_IOS)
+#import <UIKit/UIKit.h>
Nico 2014/05/06 03:00:10 wot, why do you need UIKit in base? That's why th
gab 2014/05/06 14:40:35 Oh of course, moved that as-is from the .mm file;
+
+#include "base/bind.h"
+#include "base/ios/scoped_critical_action.h"
+#endif
+
namespace base {
-// Returns a closure that will continue to run for a period of time when the
+namespace internal {
+
+#if defined(OS_IOS)
+// This class 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() {}
+
+ void Run() {
+ closure_.Run();
+ }
+
+ private:
+ ios::ScopedCriticalAction critical_action_;
+ Callback<R(void)> closure_;
+
+ DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
+};
+#endif // defined(OS_IOS)
+
+} // namespace internal
+
+// Returns a closure (which may return a result, but must not require any extra
+// arguments) that will continue to run for a period of time when the
// application goes to the background if possible on platforms where
// applications don't execute while backgrounded, otherwise the original task is
// returned.
@@ -23,14 +59,20 @@ namespace base {
// background running time, |MakeCriticalClosure| should be applied on them
// before posting.
#if defined(OS_IOS)
-base::Closure MakeCriticalClosure(const base::Closure& closure);
-#else
-inline base::Closure MakeCriticalClosure(const base::Closure& closure) {
+template <typename R>
+Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& closure) {
+ DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
+ return base::Bind(&internals::CriticalClosure<R>::Run,
+ Owned(new internals::CriticalClosure<R>(closure)));
+}
+#else // defined(OS_IOS)
+template <typename R>
+inline Callback<R(void)> MakeCriticalClosure(const Callback<R(void)>& 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;
}
-#endif // !defined(OS_IOS)
+#endif // defined(OS_IOS)
} // namespace base
« no previous file with comments | « base/base.gypi ('k') | base/critical_closure_ios.mm » ('j') | base/prefs/json_pref_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698