| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/crash_report/breakpad_helper.h" | 5 #include "ios/chrome/browser/crash_report/breakpad_helper.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/debug/crash_logging.h" | 12 #include "base/debug/crash_logging.h" |
| 13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| 20 #include "ios/chrome/browser/chrome_paths.h" | 20 #include "ios/chrome/browser/chrome_paths.h" |
| 21 #import "ios/chrome/browser/crash_report/crash_report_user_application_state.h" | 21 #import "ios/chrome/browser/crash_report/crash_report_user_application_state.h" |
| 22 #include "ios/web/public/web_thread.h" | 22 #include "ios/web/public/web_thread.h" |
| 23 | 23 |
| 24 // TODO(stuartmorgan): Move this up where it belongs once | 24 // TODO(stuartmorgan): Move this up where it belongs once |
| 25 // http://code.google.com/p/google-breakpad/issues/detail?id=487 | 25 // http://code.google.com/p/google-breakpad/issues/detail?id=487 |
| 26 // is fixed. For now, put it at the end to avoid compiler errors. | 26 // is fixed. For now, put it at the end to avoid compiler errors. |
| 27 #import "breakpad/src/client/ios/BreakpadController.h" | 27 #import "breakpad/src/client/ios/BreakpadController.h" |
| 28 | 28 |
| 29 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 30 #error "This file requires ARC support." |
| 31 #endif |
| 32 |
| 29 namespace breakpad_helper { | 33 namespace breakpad_helper { |
| 30 | 34 |
| 31 namespace { | 35 namespace { |
| 32 | 36 |
| 33 // Key in NSUserDefaults for a Boolean value that stores whether to upload | 37 // Key in NSUserDefaults for a Boolean value that stores whether to upload |
| 34 // crash reports. | 38 // crash reports. |
| 35 NSString* const kCrashReportsUploadingEnabledKey = | 39 NSString* const kCrashReportsUploadingEnabledKey = |
| 36 @"CrashReportsUploadingEnabled"; | 40 @"CrashReportsUploadingEnabled"; |
| 37 | 41 |
| 38 NSString* const kCrashedInBackground = @"crashed_in_background"; | 42 NSString* const kCrashedInBackground = @"crashed_in_background"; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 [[BreakpadController sharedInstance] addUploadParameter:value forKey:key]; | 191 [[BreakpadController sharedInstance] addUploadParameter:value forKey:key]; |
| 188 return; | 192 return; |
| 189 } | 193 } |
| 190 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 194 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| 191 [[BreakpadController sharedInstance] withBreakpadRef:^(BreakpadRef ref) { | 195 [[BreakpadController sharedInstance] withBreakpadRef:^(BreakpadRef ref) { |
| 192 if (ref) | 196 if (ref) |
| 193 BreakpadAddUploadParameter(ref, key, value); | 197 BreakpadAddUploadParameter(ref, key, value); |
| 194 dispatch_semaphore_signal(semaphore); | 198 dispatch_semaphore_signal(semaphore); |
| 195 }]; | 199 }]; |
| 196 dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 200 dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| 197 dispatch_release(semaphore); | |
| 198 } | 201 } |
| 199 | 202 |
| 200 int GetCrashReportCount() { | 203 int GetCrashReportCount() { |
| 201 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 204 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| 202 __block int outerCrashReportCount = 0; | 205 __block int outerCrashReportCount = 0; |
| 203 [[BreakpadController sharedInstance] getCrashReportCount:^(int count) { | 206 [[BreakpadController sharedInstance] getCrashReportCount:^(int count) { |
| 204 outerCrashReportCount = count; | 207 outerCrashReportCount = count; |
| 205 dispatch_semaphore_signal(semaphore); | 208 dispatch_semaphore_signal(semaphore); |
| 206 }]; | 209 }]; |
| 207 dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 210 dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| 208 dispatch_release(semaphore); | |
| 209 return outerCrashReportCount; | 211 return outerCrashReportCount; |
| 210 } | 212 } |
| 211 | 213 |
| 212 void GetCrashReportCount(void (^callback)(int)) { | 214 void GetCrashReportCount(void (^callback)(int)) { |
| 213 [[BreakpadController sharedInstance] getCrashReportCount:callback]; | 215 [[BreakpadController sharedInstance] getCrashReportCount:callback]; |
| 214 } | 216 } |
| 215 | 217 |
| 216 bool HasReportToUpload() { | 218 bool HasReportToUpload() { |
| 217 return GetCrashReportCount() > 0; | 219 return GetCrashReportCount() > 0; |
| 218 } | 220 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 void RestoreDefaultConfiguration() { | 362 void RestoreDefaultConfiguration() { |
| 361 if (!g_crash_reporter_enabled) | 363 if (!g_crash_reporter_enabled) |
| 362 return; | 364 return; |
| 363 [[BreakpadController sharedInstance] stop]; | 365 [[BreakpadController sharedInstance] stop]; |
| 364 [[BreakpadController sharedInstance] resetConfiguration]; | 366 [[BreakpadController sharedInstance] resetConfiguration]; |
| 365 [[BreakpadController sharedInstance] start:NO]; | 367 [[BreakpadController sharedInstance] start:NO]; |
| 366 [[BreakpadController sharedInstance] setUploadingEnabled:NO]; | 368 [[BreakpadController sharedInstance] setUploadingEnabled:NO]; |
| 367 } | 369 } |
| 368 | 370 |
| 369 } // namespace breakpad_helper | 371 } // namespace breakpad_helper |
| OLD | NEW |