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

Unified Diff: ios/chrome/browser/crash_loop_detection_util.mm

Issue 1147703002: [iOS] Upstream crash loop detection utilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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: ios/chrome/browser/crash_loop_detection_util.mm
diff --git a/ios/chrome/browser/crash_loop_detection_util.mm b/ios/chrome/browser/crash_loop_detection_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..93b9b1c92af67f13a260ebe26f2decee67ed3f2b
--- /dev/null
+++ b/ios/chrome/browser/crash_loop_detection_util.mm
@@ -0,0 +1,41 @@
+// Copyright 2013 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 "ios/chrome/browser/crash_loop_detection_util.h"
+
+#import <Foundation/Foundation.h>
+
+namespace {
+NSString* const kAppStartupFailureCountKey = @"AppStartupFailureCount";
+}
+
+namespace crash_util {
+
+int GetFailedStartupAttemptCount() {
+ static int startup_attempt_count = -1;
+ if (startup_attempt_count == -1) {
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+ startup_attempt_count = [defaults integerForKey:kAppStartupFailureCountKey];
+ }
+ return startup_attempt_count;
+}
+
+void IncrementFailedStartupAttemptCount(bool flush_immediately) {
+ int startup_attempt_count = GetFailedStartupAttemptCount();
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+ [defaults setInteger:(startup_attempt_count + 1)
+ forKey:kAppStartupFailureCountKey];
+ if (flush_immediately)
+ [defaults synchronize];
+}
+
+void ResetFailedStartupAttemptCount() {
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+ if ([defaults integerForKey:kAppStartupFailureCountKey] != 0) {
+ [defaults setInteger:0 forKey:kAppStartupFailureCountKey];
+ [defaults synchronize];
+ }
+}
+
+} // namespace crash_util
« no previous file with comments | « ios/chrome/browser/crash_loop_detection_util.h ('k') | ios/chrome/browser/crash_loop_detection_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698