blob: 93b9b1c92af67f13a260ebe26f2decee67ed3f2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
|