OLD | NEW |
(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 |
OLD | NEW |