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

Unified Diff: base/critical_closure_ios.mm

Issue 10835032: Add APIs to protect critical tasks on iOS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: sync and address review comments Created 8 years, 5 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/critical_closure.h ('k') | base/ios/scoped_critical_action.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/critical_closure_ios.mm
diff --git a/base/critical_closure_ios.mm b/base/critical_closure_ios.mm
new file mode 100644
index 0000000000000000000000000000000000000000..156612b5127b54d3171572b4230a183c462891e2
--- /dev/null
+++ b/base/critical_closure_ios.mm
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/critical_closure.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/bind.h"
+#include "base/ios/scoped_critical_action.h"
+#include "base/memory/ref_counted.h"
+
+namespace {
+
+// 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
+// |base::ios::ScopedCriticalAction|.
+class CriticalClosure : public base::RefCountedThreadSafe<CriticalClosure> {
+ public:
+ explicit CriticalClosure(base::Closure* closure) : closure_(closure) {
+ background_scope_.reset(new base::ios::ScopedCriticalAction());
+ }
+
+ void Run() {
+ closure_->Run();
+
+ background_scope_.reset();
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<CriticalClosure>;
+
+ virtual ~CriticalClosure() {}
+
+ scoped_ptr<base::Closure> closure_;
+ scoped_ptr<base::ios::ScopedCriticalAction> background_scope_;
+
+ DISALLOW_COPY_AND_ASSIGN(CriticalClosure);
+};
+
+} // namespace
+
+namespace base {
+
+base::Closure MakeCriticalClosure(const base::Closure& closure) {
+ DCHECK([[UIDevice currentDevice] isMultitaskingSupported]);
+ scoped_refptr<CriticalClosure> critical_closure(
+ new CriticalClosure(new base::Closure(closure)));
+ return base::Bind(&CriticalClosure::Run, critical_closure.get());
+}
+
+} // namespace base
« no previous file with comments | « base/critical_closure.h ('k') | base/ios/scoped_critical_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698