Skip to content

Commit fbf91f6

Browse files
mikehaney24paulb777
authored andcommitted
Cherry pick GDT changes for 6.8.0 and increment versions (#3770)
1 parent 5dc46ad commit fbf91f6

21 files changed

+206
-97
lines changed

GoogleDataTransport.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'GoogleDataTransport'
3-
s.version = '1.1.3'
3+
s.version = '1.2.0'
44
s.summary = 'Google iOS SDK data transport.'
55

66
s.description = <<-DESC

GoogleDataTransport/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.2.0
2+
- Removes all NSAsserts in favor of custom asserts. (#3747)
3+
14
# v1.1.3
25
- Wrap decoding in GDTUploadCoordinator in a try catch. (#3676)
36

GoogleDataTransport/GDTLibrary/GDTAssert.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
#import "GDTLibrary/Private/GDTAssert.h"
17+
#import "GDTLibrary/Public/GDTAssert.h"
1818

19-
GDTAssertionBlock GDTAssertionBlockToRunInsteadOfNSAssert(void) {
19+
GDTAssertionBlock GDTAssertionBlockToRunInstead(void) {
2020
// This class is only compiled in by unit tests, and this should fail quickly in optimized builds.
2121
Class GDTAssertClass = NSClassFromString(@"GDTAssertHelper");
2222
if (__builtin_expect(!!GDTAssertClass, 0)) {

GoogleDataTransport/GDTLibrary/GDTEvent.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616

1717
#import <GoogleDataTransport/GDTEvent.h>
1818

19+
#import <GoogleDataTransport/GDTAssert.h>
1920
#import <GoogleDataTransport/GDTStoredEvent.h>
2021

21-
#import "GDTLibrary/Private/GDTAssert.h"
2222
#import "GDTLibrary/Private/GDTEvent_Private.h"
2323

2424
@implementation GDTEvent
2525

2626
- (instancetype)initWithMappingID:(NSString *)mappingID target:(NSInteger)target {
2727
GDTAssert(mappingID.length > 0, @"Please give a valid mapping ID");
2828
GDTAssert(target > 0, @"A target cannot be negative or 0");
29+
if (mappingID == nil || mappingID.length == 0 || target <= 0) {
30+
return nil;
31+
}
2932
self = [super init];
3033
if (self) {
3134
_mappingID = mappingID;

GoogleDataTransport/GDTLibrary/GDTPlatform.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <GoogleDataTransport/GDTPlatform.h>
1818

19+
#import <GoogleDataTransport/GDTAssert.h>
20+
1921
const GDTBackgroundIdentifier GDTBackgroundIdentifierInvalid = 0;
2022

2123
NSString *const kGDTApplicationDidEnterBackgroundNotification =
@@ -40,8 +42,8 @@ @implementation GDTApplication
4042
+ (void)load {
4143
#if TARGET_OS_IOS || TARGET_OS_TV
4244
// If this asserts, please file a bug at https://github.com/firebase/firebase-ios-sdk/issues.
43-
NSAssert(GDTBackgroundIdentifierInvalid == UIBackgroundTaskInvalid,
44-
@"GDTBackgroundIdentifierInvalid and UIBackgroundTaskInvalid should be the same.");
45+
GDTFatalAssert(GDTBackgroundIdentifierInvalid == UIBackgroundTaskInvalid,
46+
@"GDTBackgroundIdentifierInvalid and UIBackgroundTaskInvalid should be the same.");
4547
#endif
4648
[self sharedApplication];
4749
}

GoogleDataTransport/GDTLibrary/GDTStorage.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#import "GDTLibrary/Private/GDTStorage.h"
1818
#import "GDTLibrary/Private/GDTStorage_Private.h"
1919

20+
#import <GoogleDataTransport/GDTAssert.h>
2021
#import <GoogleDataTransport/GDTConsoleLogger.h>
2122
#import <GoogleDataTransport/GDTLifecycle.h>
2223
#import <GoogleDataTransport/GDTPrioritizer.h>
2324
#import <GoogleDataTransport/GDTStoredEvent.h>
2425

25-
#import "GDTLibrary/Private/GDTAssert.h"
2626
#import "GDTLibrary/Private/GDTEvent_Private.h"
2727
#import "GDTLibrary/Private/GDTRegistrar_Private.h"
2828
#import "GDTLibrary/Private/GDTUploadCoordinator.h"
@@ -74,6 +74,10 @@ - (instancetype)init {
7474
}
7575

7676
- (void)storeEvent:(GDTEvent *)event {
77+
if (event == nil) {
78+
return;
79+
}
80+
7781
[self createEventDirectoryIfNotExists];
7882

7983
__block GDTBackgroundIdentifier bgID = GDTBackgroundIdentifierInvalid;

GoogleDataTransport/GDTLibrary/GDTTransformer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#import "GDTLibrary/Private/GDTTransformer.h"
1818
#import "GDTLibrary/Private/GDTTransformer_Private.h"
1919

20+
#import <GoogleDataTransport/GDTAssert.h>
2021
#import <GoogleDataTransport/GDTConsoleLogger.h>
2122
#import <GoogleDataTransport/GDTEventTransformer.h>
2223
#import <GoogleDataTransport/GDTLifecycle.h>
2324

24-
#import "GDTLibrary/Private/GDTAssert.h"
2525
#import "GDTLibrary/Private/GDTStorage.h"
2626

2727
@implementation GDTTransformer

GoogleDataTransport/GDTLibrary/GDTTransport.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717
#import <GoogleDataTransport/GDTTransport.h>
1818
#import "GDTLibrary/Private/GDTTransport_Private.h"
1919

20+
#import <GoogleDataTransport/GDTAssert.h>
2021
#import <GoogleDataTransport/GDTClock.h>
2122
#import <GoogleDataTransport/GDTEvent.h>
2223

23-
#import "GDTLibrary/Private/GDTAssert.h"
2424
#import "GDTLibrary/Private/GDTTransformer.h"
2525

2626
@implementation GDTTransport
2727

2828
- (instancetype)initWithMappingID:(NSString *)mappingID
2929
transformers:(nullable NSArray<id<GDTEventTransformer>> *)transformers
3030
target:(NSInteger)target {
31+
GDTAssert(mappingID.length > 0, @"A mapping ID cannot be nil or empty");
32+
GDTAssert(target > 0, @"A target cannot be negative or 0");
33+
if (mappingID == nil || mappingID.length == 0 || target <= 0) {
34+
return nil;
35+
}
3136
self = [super init];
3237
if (self) {
33-
GDTAssert(mappingID.length > 0, @"A mapping ID cannot be nil or empty");
34-
GDTAssert(target > 0, @"A target cannot be negative or 0");
3538
_mappingID = mappingID;
3639
_transformers = transformers;
3740
_target = target;

GoogleDataTransport/GDTLibrary/GDTUploadCoordinator.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
#import "GDTLibrary/Private/GDTUploadCoordinator.h"
1818

19+
#import <GoogleDataTransport/GDTAssert.h>
1920
#import <GoogleDataTransport/GDTClock.h>
2021
#import <GoogleDataTransport/GDTConsoleLogger.h>
2122

22-
#import "GDTLibrary/Private/GDTAssert.h"
2323
#import "GDTLibrary/Private/GDTReachability.h"
2424
#import "GDTLibrary/Private/GDTRegistrar_Private.h"
2525
#import "GDTLibrary/Private/GDTStorage.h"

GoogleDataTransport/GDTLibrary/Private/GDTAssert.h

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import <GoogleDataTransport/GDTConsoleLogger.h>
20+
21+
/** A block type that could be run instead of normal assertion logging. No return type, no params.
22+
*/
23+
typedef void (^GDTAssertionBlock)(void);
24+
25+
/** Returns the result of executing a soft-linked method present in unit tests that allows a block
26+
* to be run instead of normal assertion logging. This helps ameliorate issues with catching
27+
* exceptions that occur on a dispatch_queue.
28+
*
29+
* @return A block that can be run instead of normal assert printing.
30+
*/
31+
FOUNDATION_EXPORT GDTAssertionBlock _Nullable GDTAssertionBlockToRunInstead(void);
32+
33+
#if defined(NS_BLOCK_ASSERTIONS)
34+
35+
#define GDTAssert(condition, ...) \
36+
do { \
37+
} while (0);
38+
39+
#define GDTFatalAssert(condition, ...) \
40+
do { \
41+
} while (0);
42+
43+
#else // defined(NS_BLOCK_ASSERTIONS)
44+
45+
/** Asserts using a console log, unless a block was specified to be run instead.
46+
*
47+
* @param condition The condition you'd expect to be YES.
48+
*/
49+
#define GDTAssert(condition, ...) \
50+
do { \
51+
if (__builtin_expect(!(condition), 0)) { \
52+
GDTAssertionBlock assertionBlock = GDTAssertionBlockToRunInstead(); \
53+
if (assertionBlock) { \
54+
assertionBlock(); \
55+
} else { \
56+
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
57+
NSString *__assert_file__ = [NSString stringWithUTF8String:__FILE__]; \
58+
__assert_file__ = __assert_file__ ? __assert_file__ : @"<Unknown File>"; \
59+
GDTLogError(GDTMCEGeneralError, @"Assertion failed (%@:%d): %s,", __assert_file__, \
60+
__LINE__, ##__VA_ARGS__); \
61+
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
62+
} \
63+
} \
64+
} while (0);
65+
66+
/** Asserts by logging to the console and throwing an exception if NS_BLOCK_ASSERTIONS is not
67+
* defined.
68+
*
69+
* @param condition The condition you'd expect to be YES.
70+
*/
71+
#define GDTFatalAssert(condition, ...) \
72+
do { \
73+
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
74+
if (__builtin_expect(!(condition), 0)) { \
75+
NSString *__assert_file__ = [NSString stringWithUTF8String:__FILE__]; \
76+
__assert_file__ = __assert_file__ ? __assert_file__ : @"<Unknown File>"; \
77+
GDTLogError(GDTMCEFatalAssertion, \
78+
@"Fatal assertion encountered, please open an issue at " \
79+
"https://github.com/firebase/firebase-ios-sdk/issues " \
80+
"(%@:%d): %s,", \
81+
__assert_file__, __LINE__, ##__VA_ARGS__); \
82+
[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd \
83+
object:self \
84+
file:__assert_file__ \
85+
lineNumber:__LINE__ \
86+
description:@"%@", ##__VA_ARGS__]; \
87+
} \
88+
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
89+
} while (0);
90+
91+
#endif // defined(NS_BLOCK_ASSERTIONS)

GoogleDataTransport/GDTLibrary/Public/GDTConsoleLogger.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ typedef NS_ENUM(NSInteger, GDTMessageCode) {
5656
GDTMCETransportBytesError = 1005,
5757

5858
/** For general purpose error messages in a dependency. */
59-
GDTMCEGeneralError = 1006
59+
GDTMCEGeneralError = 1006,
60+
61+
/** For fatal errors. Please go to https://github.com/firebase/firebase-ios-sdk/issues and open
62+
* an issue if you encounter an error with this code.
63+
*/
64+
GDTMCEFatalAssertion = 1007
6065
};
6166

6267
/** */

GoogleDataTransport/GDTTests/Integration/Helpers/GDTIntegrationTestUploader.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#import "GDTTests/Integration/Helpers/GDTIntegrationTestUploader.h"
1818

19+
#import <GoogleDataTransport/GDTAssert.h>
1920
#import <GoogleDataTransport/GDTRegistrar.h>
2021
#import <GoogleDataTransport/GDTStoredEvent.h>
2122

@@ -41,7 +42,8 @@ - (instancetype)initWithServerURL:(NSURL *)serverURL {
4142
}
4243

4344
- (void)uploadPackage:(GDTUploadPackage *)package {
44-
NSAssert(!_currentUploadTask, @"An upload shouldn't be initiated with another in progress.");
45+
GDTFatalAssert(!_currentUploadTask,
46+
@"An upload shouldn't be initiated with another in progress.");
4547
NSURL *serverURL = arc4random_uniform(2) ? [_serverURL URLByAppendingPathComponent:@"log"]
4648
: [_serverURL URLByAppendingPathComponent:@"logBatch"];
4749
NSURLSession *session = [NSURLSession sharedSession];
@@ -54,24 +56,24 @@ - (void)uploadPackage:(GDTUploadPackage *)package {
5456
// In real usage, you'd create an instance of whatever request proto your server needs.
5557
for (GDTStoredEvent *event in package.events) {
5658
NSData *fileData = [NSData dataWithContentsOfURL:event.dataFuture.fileURL];
57-
NSAssert(fileData, @"An event file shouldn't be empty");
59+
GDTFatalAssert(fileData, @"An event file shouldn't be empty");
5860
[uploadData appendData:fileData];
5961
}
60-
_currentUploadTask =
61-
[session uploadTaskWithRequest:request
62-
fromData:uploadData
63-
completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response,
64-
NSError *_Nullable error) {
65-
NSLog(@"Batch upload complete.");
66-
// Remove from the prioritizer if there were no errors.
67-
NSAssert(!error, @"There should be no errors uploading events: %@", error);
68-
if (error) {
69-
[package retryDeliveryInTheFuture];
70-
} else {
71-
[package completeDelivery];
72-
}
73-
self->_currentUploadTask = nil;
74-
}];
62+
_currentUploadTask = [session
63+
uploadTaskWithRequest:request
64+
fromData:uploadData
65+
completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response,
66+
NSError *_Nullable error) {
67+
NSLog(@"Batch upload complete.");
68+
// Remove from the prioritizer if there were no errors.
69+
GDTFatalAssert(!error, @"There should be no errors uploading events: %@", error);
70+
if (error) {
71+
[package retryDeliveryInTheFuture];
72+
} else {
73+
[package completeDelivery];
74+
}
75+
self->_currentUploadTask = nil;
76+
}];
7577
[_currentUploadTask resume];
7678
}
7779

0 commit comments

Comments
 (0)