1 // Copyright (c) 2012, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef CLIENT_IOS_HANDLER_IOS_BREAKPAD_CONTROLLER_H_ 31 #define CLIENT_IOS_HANDLER_IOS_BREAKPAD_CONTROLLER_H_ 32 33 #import <Foundation/Foundation.h> 34 35 #import "client/ios/Breakpad.h" 36 37 // This class is used to offer a higher level API around BreakpadRef. It 38 // configures it, ensures thread-safety, and sends crash reports back to the 39 // collecting server. By default, no crash reports are sent, the user must call 40 // |setUploadingEnabled:YES| to start the uploading. 41 @interface BreakpadController : NSObject { 42 @private 43 // The dispatch queue that will own the breakpad reference. 44 dispatch_queue_t queue_; 45 46 // Instance of Breakpad crash reporter. This is owned by the queue, but can 47 // be created on the main thread at startup. 48 BreakpadRef breakpadRef_; 49 50 // The dictionary that contains configuration for breakpad. Modifying it 51 // should only happen when the controller is not started. The initial value 52 // is the infoDictionary of the bundle of the application. 53 NSMutableDictionary* configuration_; 54 55 // Whether or not crash reports should be uploaded. 56 BOOL enableUploads_; 57 58 // Whether the controller has been started on the main thread. This is only 59 // used to assert the initialization order is correct. 60 BOOL started_; 61 62 // The interval to wait between two uploads. Value is 0 if no upload must be 63 // done. 64 int uploadIntervalInSeconds_; 65 66 // The dictionary that contains additional server parameters to send when 67 // uploading crash reports. 68 NSDictionary* uploadTimeParameters_; 69 70 // The callback to call on report upload completion. 71 BreakpadUploadCompletionCallback uploadCompleteCallback_; 72 } 73 74 // Singleton. 75 + (BreakpadController*)sharedInstance; 76 77 // Update the controller configuration. Merges its old configuration with the 78 // new one. Merge is done by replacing the old values by the new values. 79 - (void)updateConfiguration:(NSDictionary*)configuration; 80 81 // Reset the controller configuration to its initial value, which is the 82 // infoDictionary of the bundle of the application. 83 - (void)resetConfiguration; 84 85 // Configure the URL to upload the report to. This must be called at least once 86 // if the URL is not in the bundle information. 87 - (void)setUploadingURL:(NSString*)url; 88 89 // Set the minimal interval between two uploads in seconds. This must be called 90 // at least once if the interval is not in the bundle information. A value of 0 91 // will prevent uploads. 92 - (void)setUploadInterval:(int)intervalInSeconds; 93 94 // Set additional server parameters to send when uploading crash reports. 95 - (void)setParametersToAddAtUploadTime:(NSDictionary*)uploadTimeParameters; 96 97 // Specify an upload parameter that will be added to the crash report when a 98 // crash report is generated. See |BreakpadAddUploadParameter|. 99 - (void)addUploadParameter:(NSString*)value forKey:(NSString*)key; 100 101 // Sets the callback to be called after uploading a crash report to the server. 102 // Only the latest callback registered will be called. 103 - (void)setUploadCallback:(BreakpadUploadCompletionCallback)callback; 104 105 // Remove a previously-added parameter from the upload parameter set. See 106 // |BreakpadRemoveUploadParameter|. 107 - (void)removeUploadParameterForKey:(NSString*)key; 108 109 // Access the underlying BreakpadRef. This method is asynchronous, and will be 110 // executed on the thread owning the BreakpadRef variable. Moreover, if the 111 // controller is not started, the block will be called with a NULL parameter. 112 - (void)withBreakpadRef:(void(^)(BreakpadRef))callback; 113 114 // Starts the BreakpadController by registering crash handlers. If 115 // |onCurrentThread| is YES, all setup is done on the current thread, otherwise 116 // it is done on a private queue. 117 - (void)start:(BOOL)onCurrentThread; 118 119 // Unregisters the crash handlers. 120 - (void)stop; 121 122 // Returns whether or not the controller is started. 123 - (BOOL)isStarted; 124 125 // Enables or disables uploading of crash reports, but does not stop the 126 // BreakpadController. 127 - (void)setUploadingEnabled:(BOOL)enabled; 128 129 // Check if there is currently a crash report to upload. 130 - (void)hasReportToUpload:(void(^)(BOOL))callback; 131 132 // Get the number of crash reports waiting to upload. 133 - (void)getCrashReportCount:(void(^)(int))callback; 134 135 // Get the next report to upload. 136 // - If upload is disabled, callback will be called with (nil, -1). 137 // - If a delay is to be waited before sending, callback will be called with 138 // (nil, n), with n (> 0) being the number of seconds to wait. 139 // - if no delay is needed, callback will be called with (0, configuration), 140 // configuration being next report to upload, or nil if none is pending. 141 - (void)getNextReportConfigurationOrSendDelay: 142 (void(^)(NSDictionary*, int))callback; 143 144 // Get the date of the most recent crash report. 145 - (void)getDateOfMostRecentCrashReport:(void(^)(NSDate *))callback; 146 147 // Sends synchronously the report specified by |configuration|. This method is 148 // NOT thread safe and must be called from the breakpad thread. 149 - (void)threadUnsafeSendReportWithConfiguration:(NSDictionary*)configuration 150 withBreakpadRef:(BreakpadRef)ref; 151 152 @end 153 154 #endif // CLIENT_IOS_HANDLER_IOS_BREAKPAD_CONTROLLER_H_ 155