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

Unified Diff: base/ios/scoped_critical_action.h

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_ios.mm ('k') | base/ios/scoped_critical_action.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/ios/scoped_critical_action.h
diff --git a/base/ios/scoped_critical_action.h b/base/ios/scoped_critical_action.h
new file mode 100644
index 0000000000000000000000000000000000000000..660a83ad024c00d4f9e7444133aadf3630f9dbf6
--- /dev/null
+++ b/base/ios/scoped_critical_action.h
@@ -0,0 +1,48 @@
+// 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.
+
+#ifndef BASE_IOS_SCOPED_CRITICAL_ACTION_H_
+#define BASE_IOS_SCOPED_CRITICAL_ACTION_H_
+
+#include "base/synchronization/lock.h"
+
+namespace base {
+namespace ios {
+
+// This class attempts to allow the application to continue to run for a period
+// of time after it transitions to the background. The construction of an
+// instance of this class marks the beginning of a task that needs background
+// running time when the application is moved to the background and the
+// destruction marks the end of such a task.
+//
+// Note there is no guarantee that the task will continue to finish when the
+// application is moved to the background.
+//
+// This class should be used at times where leaving a task unfinished might be
+// detrimental to user experience. For example, it should be used to ensure that
+// the application has enough time to save important data or at least attempt to
+// save such data.
+class ScopedCriticalAction {
+ public:
+ ScopedCriticalAction();
+ ~ScopedCriticalAction();
+
+ private:
+ // Informs the OS that the background task has completed.
+ void EndBackgroundTask();
+
+ // |UIBackgroundTaskIdentifier| returned by
+ // |beginBackgroundTaskWithExpirationHandler:| when marking the beginning of
+ // a long-running background task. It is defined as an |unsigned int| instead
+ // of a |UIBackgroundTaskIdentifier| so this class can be used in .cc files.
+ unsigned int background_task_id_;
+ Lock background_task_id_lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCriticalAction);
+};
+
+} // namespace ios
+} // namespace base
+
+#endif // BASE_IOS_SCOPED_CRITICAL_ACTION_H_
« no previous file with comments | « base/critical_closure_ios.mm ('k') | base/ios/scoped_critical_action.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698