Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fix-build-errors-with-xcode10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeklim committed Apr 17, 2019
2 parents 9ec2c62 + d467d36 commit c810cf4
Show file tree
Hide file tree
Showing 27 changed files with 1,516 additions and 750 deletions.
15 changes: 13 additions & 2 deletions AppCenterCrashes/AppCenterCrashes/MSCrashes.mm
Expand Up @@ -1052,13 +1052,13 @@ - (BOOL)sendCrashReportsOrAwaitUserConfirmation {

// User confirmation is set to MSUserConfirmationAlways.
MSLogDebug([MSCrashes logTag], @"The flag for user confirmation is set to MSUserConfirmationAlways, continue sending logs");
[self notifyWithUserConfirmation:MSUserConfirmationSend];
[self handleUserConfirmation:MSUserConfirmationSend];
return alwaysSend;
} else if (self.automaticProcessing && !(self.userConfirmationHandler && [self userPromptedForConfirmation])) {

// User confirmation handler doesn't exist or returned NO which means 'want to process'.
MSLogDebug([MSCrashes logTag], @"The user confirmation handler is not implemented or returned NO, continue sending logs");
[self notifyWithUserConfirmation:MSUserConfirmationSend];
[self handleUserConfirmation:MSUserConfirmationSend];
} else if (!self.automaticProcessing) {
MSLogDebug([MSCrashes logTag], @"Automatic crash processing is disabled and \"AlwaysSend\" is false. Awaiting user confirmation.");
}
Expand Down Expand Up @@ -1095,6 +1095,17 @@ + (void)sendErrorAttachments:(NSArray<MSErrorAttachmentLog *> *)errorAttachments
}

- (void)notifyWithUserConfirmation:(MSUserConfirmation)userConfirmation {

// Check if there is no handler set and unprocessedReports are not initialized as NSMutableArray (Init occurs in correct call sequence).
if (!self.userConfirmationHandler && !self.unprocessedReports) {
MSLogError(MSCrashes.logTag, @"Incorrect usage of notifyWithUserConfirmation: it should only be called from userConfirmationHandler. "
@"For more information refer to the documentation.");
return;
}
[self handleUserConfirmation:userConfirmation];
}

- (void)handleUserConfirmation:(MSUserConfirmation)userConfirmation {
NSArray<MSErrorAttachmentLog *> *attachments;

// Check for user confirmation.
Expand Down
18 changes: 18 additions & 0 deletions AppCenterCrashes/AppCenterCrashesTests/MSCrashesTests.mm
Expand Up @@ -40,6 +40,7 @@ - (void)startDelayedCrashProcessing;
- (void)startCrashProcessing;
- (void)shouldAlwaysSend;
- (void)emptyLogBufferFiles;
- (void)handleUserConfirmation:(MSUserConfirmation)userConfirmation;

@property(nonatomic) dispatch_group_t bufferFileGroup;

Expand Down Expand Up @@ -1087,6 +1088,23 @@ - (void)testStartingCrashesWithAutomaticProcessing {
XCTAssertEqual([retrievedReports count], 0U);
}

- (void)testErrorOnIncorrectNotifyWithUserConfirmationCall {

// Wait for creation of buffers to avoid corruption on OCMPartialMock.
dispatch_group_wait(self.sut.bufferFileGroup, DISPATCH_TIME_FOREVER);

// If
self.sut = OCMPartialMock(self.sut);
id<MSChannelGroupProtocol> channelGroupMock = OCMProtocolMock(@protocol(MSChannelGroupProtocol));
[self startCrashes:self.sut withReports:YES withChannelGroup:channelGroupMock];

// Then
OCMReject([self.sut handleUserConfirmation:MSUserConfirmationAlways]);

// When
[self.sut notifyWithUserConfirmation:MSUserConfirmationAlways];
}

- (void)testCrashesSetCorrectUserIdToLogs {

// Wait for creation of buffers to avoid corruption on OCMPartialMock.
Expand Down
Expand Up @@ -145,6 +145,8 @@
4ACEAC9F225418B600976AEA /* MSDBDocumentStoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ACEAC9D225418B600976AEA /* MSDBDocumentStoreTests.m */; };
87FC45D718C70D5B72340A1C /* MSCosmosDbPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 87FA7FB5BC7302D0062016E1 /* MSCosmosDbPrivate.h */; };
87FD963F7BF9C9E07DE16D82 /* MSCosmosDbPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 87FA7FB5BC7302D0062016E1 /* MSCosmosDbPrivate.h */; };
8F1E76E922652B9D00A6D39F /* MSDataOperationProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1E76E822652B9D00A6D39F /* MSDataOperationProxyTests.m */; };
8F1E76EA22652B9D00A6D39F /* MSDataOperationProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1E76E822652B9D00A6D39F /* MSDataOperationProxyTests.m */; };
8F1FF9522255C1350083471E /* validTestDocument.json in Resources */ = {isa = PBXBuildFile; fileRef = 8F1FF9512255C12F0083471E /* validTestDocument.json */; };
8F1FF9532255C1360083471E /* validTestDocument.json in Resources */ = {isa = PBXBuildFile; fileRef = 8F1FF9512255C12F0083471E /* validTestDocument.json */; };
8F4548E02256D2450021B0BF /* MSDictionaryDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F4548DF2256D2450021B0BF /* MSDictionaryDocument.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -159,6 +161,10 @@
8F5227EE2253F0C8004F37FE /* zeroDocumentsPage.json in Resources */ = {isa = PBXBuildFile; fileRef = 8F5227EC2253F0C7004F37FE /* zeroDocumentsPage.json */; };
8F5227F02254255D004F37FE /* MSPaginatedDocumentsInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F5227EF22542556004F37FE /* MSPaginatedDocumentsInternal.h */; };
8F5227F12254255F004F37FE /* MSPaginatedDocumentsInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F5227EF22542556004F37FE /* MSPaginatedDocumentsInternal.h */; };
8F534A102260321100D18129 /* MSDataOperationProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F534A0F2260320200D18129 /* MSDataOperationProxy.h */; };
8F534A112260321200D18129 /* MSDataOperationProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F534A0F2260320200D18129 /* MSDataOperationProxy.h */; };
8F534A17226039F400D18129 /* MSDataOperationProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F534A16226039F400D18129 /* MSDataOperationProxy.m */; };
8F534A1822603A0000D18129 /* MSDataOperationProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F534A16226039F400D18129 /* MSDataOperationProxy.m */; };
8FCF9FE0225D4D870049B326 /* MSTokenResultPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8FCF9FDF225D4D870049B326 /* MSTokenResultPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
8FCF9FE1225D4D870049B326 /* MSTokenResultPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8FCF9FDF225D4D870049B326 /* MSTokenResultPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
9919248E225BCD070064E699 /* MSDocumentStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 9919248D225BCD060064E699 /* MSDocumentStore.h */; };
Expand Down Expand Up @@ -302,6 +308,7 @@
4A9C4400223B23E3008548A7 /* MSTokenTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSTokenTests.m; sourceTree = "<group>"; };
4ACEAC9D225418B600976AEA /* MSDBDocumentStoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSDBDocumentStoreTests.m; sourceTree = "<group>"; };
87FA7FB5BC7302D0062016E1 /* MSCosmosDbPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSCosmosDbPrivate.h; sourceTree = "<group>"; };
8F1E76E822652B9D00A6D39F /* MSDataOperationProxyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSDataOperationProxyTests.m; sourceTree = "<group>"; };
8F1FF9512255C12F0083471E /* validTestDocument.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = validTestDocument.json; sourceTree = "<group>"; };
8F4548DF2256D2450021B0BF /* MSDictionaryDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSDictionaryDocument.h; sourceTree = "<group>"; };
8F4548E22256D3160021B0BF /* MSDictionaryDocument.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSDictionaryDocument.m; sourceTree = "<group>"; };
Expand All @@ -312,6 +319,8 @@
8F5227E32253E22F004F37FE /* MSHttpTestUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MSHttpTestUtil.h; path = ../../AppCenter/AppCenterTests/Util/MSHttpTestUtil.h; sourceTree = "<group>"; };
8F5227EC2253F0C7004F37FE /* zeroDocumentsPage.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = zeroDocumentsPage.json; sourceTree = "<group>"; };
8F5227EF22542556004F37FE /* MSPaginatedDocumentsInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSPaginatedDocumentsInternal.h; sourceTree = "<group>"; };
8F534A0F2260320200D18129 /* MSDataOperationProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSDataOperationProxy.h; sourceTree = "<group>"; };
8F534A16226039F400D18129 /* MSDataOperationProxy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSDataOperationProxy.m; sourceTree = "<group>"; };
8FCF9FDF225D4D870049B326 /* MSTokenResultPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSTokenResultPrivate.h; sourceTree = "<group>"; };
9919248D225BCD060064E699 /* MSDocumentStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDocumentStore.h; sourceTree = "<group>"; };
D33A94511E5B11BB003966DB /* libAppCenterDataStorage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAppCenterDataStorage.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -545,6 +554,7 @@
children = (
D3AD5EC41E5C4F6A001627AB /* Info.plist */,
04B61DCA2248F518008D0102 /* MSTokenExchangeTests.m */,
8F1E76E822652B9D00A6D39F /* MSDataOperationProxyTests.m */,
2ACE55FF2245277000FCD5DF /* MSDocumentUtilsTests.m */,
2ACE56092245340A00FCD5DF /* MSBaseOptionsTests.m */,
2ACE562022453BE600FCD5DF /* MSDataSourceErrorTests.m */,
Expand Down Expand Up @@ -619,6 +629,8 @@
E8593A14222B91B20001F87E /* MSCosmosDb.h */,
E8593A15222B91B20001F87E /* MSCosmosDb.m */,
87FA7FB5BC7302D0062016E1 /* MSCosmosDbPrivate.h */,
8F534A0F2260320200D18129 /* MSDataOperationProxy.h */,
8F534A16226039F400D18129 /* MSDataOperationProxy.m */,
E86B95D72224B5F60062E552 /* MSTokenExchange.h */,
E86B95D92224B6310062E552 /* MSTokenExchange.m */,
);
Expand Down Expand Up @@ -670,7 +682,6 @@
049BC852224EDAFF00AE7FBB /* MSDataSourceError.h in Headers */,
8F4548E12256D2450021B0BF /* MSDictionaryDocument.h in Headers */,
4A193739225129C200459E1E /* MSDBDocumentStore.h in Headers */,
4A1937982252CA6600459E1E /* MSDocumentStore.h in Headers */,
049BC85B224EDB1D00AE7FBB /* MSPage.h in Headers */,
049BC85C224EDB2200AE7FBB /* MSReadOptions.h in Headers */,
04B1C8CA2252AF0A00CBD876 /* MSAppCenterErrors.h in Headers */,
Expand All @@ -689,6 +700,7 @@
049BC85A224EDB1900AE7FBB /* MSPaginatedDocuments.h in Headers */,
049BC84E224EDAEE00AE7FBB /* MSBaseOptions.h in Headers */,
8F5227F12254255F004F37FE /* MSPaginatedDocumentsInternal.h in Headers */,
8F534A112260321200D18129 /* MSDataOperationProxy.h in Headers */,
E8DADEF122286D1A00587E15 /* MSTokenResult.h in Headers */,
E80BE8922242215E004DD008 /* MSDataStoreErrors.h in Headers */,
049BC85D224EDB2700AE7FBB /* MSWriteOptions.h in Headers */,
Expand Down Expand Up @@ -727,6 +739,7 @@
4A193738225129B700459E1E /* MSDBDocumentStorePrivate.h in Headers */,
D3AD5F121E5C847B001627AB /* MSDataStorePrivate.h in Headers */,
8F5227F02254255D004F37FE /* MSPaginatedDocumentsInternal.h in Headers */,
8F534A102260321100D18129 /* MSDataOperationProxy.h in Headers */,
E8593A16222B91B20001F87E /* MSCosmosDb.h in Headers */,
E80BE8912242215E004DD008 /* MSDataStoreErrors.h in Headers */,
04A0820C1F74BBCA00DC776D /* MSService.h in Headers */,
Expand Down Expand Up @@ -981,6 +994,7 @@
049BC855224EDB0C00AE7FBB /* MSDocumentWrapper.m in Sources */,
E8DADEF222286D2100587E15 /* MSTokensResponse.m in Sources */,
049BC860224EDBCD00AE7FBB /* MSDocumentUtils.m in Sources */,
8F534A1822603A0000D18129 /* MSDataOperationProxy.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -993,6 +1007,7 @@
04B61DCC2248F518008D0102 /* MSTokenExchangeTests.m in Sources */,
8F4548E82256D5470021B0BF /* NSObject+MSTestFixture.m in Sources */,
2ACE56012245277000FCD5DF /* MSDocumentUtilsTests.m in Sources */,
8F1E76EA22652B9D00A6D39F /* MSDataOperationProxyTests.m in Sources */,
0469644F1F2A5D4A00F9D31F /* MSDataStoreTests.m in Sources */,
350D453B22568DFE00982E20 /* MSHttpTestUtil.m in Sources */,
359D1A5B225E678B003ABD4F /* MSDispatchTestUtil.m in Sources */,
Expand Down Expand Up @@ -1024,6 +1039,7 @@
267464F8222F28A300EC1FF3 /* MSPaginatedDocuments.m in Sources */,
267464EE222F28A300EC1FF3 /* MSDataSourceError.m in Sources */,
4A193736225129B700459E1E /* MSDBDocumentStore.m in Sources */,
8F534A17226039F400D18129 /* MSDataOperationProxy.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1036,6 +1052,7 @@
04B61DCB2248F518008D0102 /* MSTokenExchangeTests.m in Sources */,
8F4548E72256D5470021B0BF /* NSObject+MSTestFixture.m in Sources */,
2ACE56002245277000FCD5DF /* MSDocumentUtilsTests.m in Sources */,
8F1E76E922652B9D00A6D39F /* MSDataOperationProxyTests.m in Sources */,
0496A67B1F3128CE005AE1DB /* MSDataStoreTests.m in Sources */,
350D453A22568DFD00982E20 /* MSHttpTestUtil.m in Sources */,
359D1A5A225E678B003ABD4F /* MSDispatchTestUtil.m in Sources */,
Expand Down
@@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#import <Foundation/Foundation.h>

#import "MSBaseOptions.h"
#import "MSDataStore.h"
#import "MSDocumentStore.h"
#import "MSTokensResponse.h"
#import "MS_Reachability.h"

NS_ASSUME_NONNULL_BEGIN

typedef void (^MSCachedTokenCompletionHandler)(MSTokensResponse *_Nullable tokensResponse, NSError *_Nullable error);

/**
* Class responsible for the core logic between offline and remote calls.
*/
@interface MSDataOperationProxy : NSObject

/**
* Data store.
*/
@property(nonatomic, nonnull) id<MSDocumentStore> documentStore;

/**
* Network state helper.
*/
@property(nonatomic) MS_Reachability *reachability;

/**
* Initialize a `MSDataOperationProxy` instance.
*
* @param documentStore The document store instance.
* @param reachability Network state helper.
*
* @return A new `MSDataOperationProxy` instance.
*/
- (instancetype)initWithDocumentStore:(id<MSDocumentStore>)documentStore reachability:(MS_Reachability *)reachability;

/**
* Perform an operation for a given partition/document
* using a combination of the local store and/or CosmosDB remote calls.
*
* @param operation The operation (nil - read, CREATE, UPDATE, DELETE). Values are matching the pending operation column in the documents
* store.
* @param documentId The document identifier.
* @param documentType The document type.
* @param document The document (if the operation is CREATE or UPDATE).
* @param baseOptions The base options from which to get the device time to live (if specified).
* @param cachedTokenBlock A block returning the cached token.
* @param remoteDocumentBlock A block returning the remote document.
* @param completionHandler The completion handler called ultimately.
*/
- (void)performOperation:(NSString *_Nullable)operation
documentId:(NSString *)documentId
documentType:(Class)documentType
document:(id<MSSerializableDocument> _Nullable)document
baseOptions:(MSBaseOptions *_Nullable)baseOptions
cachedTokenBlock:(void (^)(MSCachedTokenCompletionHandler))cachedTokenBlock
remoteDocumentBlock:(void (^)(MSDocumentWrapperCompletionHandler))remoteDocumentBlock
completionHandler:(MSDocumentWrapperCompletionHandler)completionHandler;

@end

NS_ASSUME_NONNULL_END

0 comments on commit c810cf4

Please sign in to comment.