OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 #import "chrome/app/breakpad_mac.h" |
| 6 |
| 7 #import <objc/objc-class.h> |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #import "base/basictypes.h" |
| 11 #import "base/logging.h" |
| 12 #import "base/scoped_nsautorelease_pool.h" |
| 13 |
| 14 // TODO(jeremy): Remove this block once we include the breakpad sources |
| 15 // in the public tree. |
| 16 @interface GoogleBreakpadWrapper : NSObject |
| 17 +(void*)Create:(NSDictionary*) parameters; |
| 18 +(void)Release:(void*) ref; |
| 19 @end |
| 20 typedef void* GoogleBreakpadRef; |
| 21 |
| 22 namespace { |
| 23 |
| 24 // TODO(jeremy): On Windows we store the current URL when a process crashes |
| 25 // we probably want to do the same on OS X. |
| 26 |
| 27 GoogleBreakpadRef gBreakpadRef = NULL; |
| 28 |
| 29 // Did the user optin for reporting stats. |
| 30 bool IsStatsReportingAllowed() { |
| 31 NOTIMPLEMENTED(); |
| 32 return true; |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 bool IsCrashReporterEnabled() { |
| 38 return gBreakpadRef == NULL; |
| 39 } |
| 40 |
| 41 void DestructCrashReporter() { |
| 42 if (gBreakpadRef) { |
| 43 Class breakpad_interface = objc_getClass("GoogleBreakpadWrapper"); |
| 44 [breakpad_interface Release:gBreakpadRef]; |
| 45 gBreakpadRef = NULL; |
| 46 } |
| 47 } |
| 48 |
| 49 void InitCrashReporter() { |
| 50 DCHECK(gBreakpadRef == NULL); |
| 51 base::ScopedNSAutoreleasePool autorelease_pool; |
| 52 |
| 53 // Check for Send stats preference. If preference is not specifically turned |
| 54 // on then disable crash reporting. |
| 55 if (!IsStatsReportingAllowed()) { |
| 56 LOG(WARNING) << "Breakpad disabled"; |
| 57 return; |
| 58 } |
| 59 |
| 60 NSBundle* main_bundle = [NSBundle mainBundle]; |
| 61 |
| 62 // Get location of breakpad. |
| 63 NSString* breakpadBundlePath = [[main_bundle privateFrameworksPath] |
| 64 stringByAppendingPathComponent:@"GoogleBreakpad.framework"]; |
| 65 |
| 66 BOOL is_dir = NO; |
| 67 if (![[NSFileManager defaultManager] fileExistsAtPath:breakpadBundlePath |
| 68 isDirectory:&is_dir] || !is_dir) { |
| 69 return; |
| 70 } |
| 71 |
| 72 NSBundle* breakpad_bundle = [NSBundle bundleWithPath:breakpadBundlePath]; |
| 73 if (![breakpad_bundle load]) { |
| 74 LOG(ERROR) << "Failed to load Breakpad framework."; |
| 75 return; |
| 76 } |
| 77 |
| 78 Class breakpad_interface = [breakpad_bundle |
| 79 classNamed:@"GoogleBreakpadWrapper"]; |
| 80 |
| 81 if (!breakpad_interface) { |
| 82 LOG(ERROR) << "Failed to find GoogleBreakpadWrapper class."; |
| 83 return; |
| 84 } |
| 85 |
| 86 NSDictionary* info_dictionary = [main_bundle infoDictionary]; |
| 87 GoogleBreakpadRef breakpad = 0; |
| 88 breakpad = [breakpad_interface Create:info_dictionary]; |
| 89 if (!breakpad) { |
| 90 LOG(ERROR) << "Breakpad init failed."; |
| 91 return; |
| 92 } |
| 93 |
| 94 gBreakpadRef = breakpad; |
| 95 } |
OLD | NEW |