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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/crash_loop_detection_util.h"
6
7 #import <Foundation/Foundation.h>
8
9 namespace {
10 NSString* const kAppStartupFailureCountKey = @"AppStartupFailureCount";
11 }
12
13 namespace crash_util {
14
15 int GetFailedStartupAttemptCount() {
16 static int startup_attempt_count = -1;
17 if (startup_attempt_count == -1) {
18 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
19 startup_attempt_count = [defaults integerForKey:kAppStartupFailureCountKey];
20 }
21 return startup_attempt_count;
22 }
23
24 void IncrementFailedStartupAttemptCount(bool flush_immediately) {
25 int startup_attempt_count = GetFailedStartupAttemptCount();
26 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
27 [defaults setInteger:(startup_attempt_count + 1)
28 forKey:kAppStartupFailureCountKey];
29 if (flush_immediately)
30 [defaults synchronize];
31 }
32
33 void ResetFailedStartupAttemptCount() {
34 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
35 if ([defaults integerForKey:kAppStartupFailureCountKey] != 0) {
36 [defaults setInteger:0 forKey:kAppStartupFailureCountKey];
37 [defaults synchronize];
38 }
39 }
40
41 } // namespace crash_util
OLDNEW
« 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