19
19
#import < GoogleDataTransport/GDTCORAssert.h>
20
20
#import < GoogleDataTransport/GDTCORClock.h>
21
21
#import < GoogleDataTransport/GDTCORConsoleLogger.h>
22
+ #import < GoogleDataTransport/GDTCORPlatform.h>
22
23
23
24
#import " GDTCORLibrary/Private/GDTCORDataFuture.h"
24
25
#import " GDTCORLibrary/Private/GDTCOREvent_Private.h"
@@ -47,7 +48,7 @@ - (instancetype)copy {
47
48
copy.qosTier = _qosTier;
48
49
copy.clockSnapshot = _clockSnapshot;
49
50
copy.customPrioritizationParams = _customPrioritizationParams;
50
- copy->_fileURL = _fileURL ;
51
+ copy->_GDTFilePath = _GDTFilePath ;
51
52
GDTCORLogDebug (" Copying event %@ to event %@" , self, copy);
52
53
return copy;
53
54
}
@@ -57,7 +58,7 @@ - (NSUInteger)hash {
57
58
NSUInteger mappingIDHash = [_mappingID hash ];
58
59
NSUInteger timeHash = [_clockSnapshot hash ];
59
60
NSInteger dataObjectHash = [_dataObject hash ];
60
- NSUInteger fileURL = [_fileURL hash ];
61
+ NSUInteger fileURL = [_GDTFilePath hash ];
61
62
62
63
return mappingIDHash ^ _target ^ _qosTier ^ timeHash ^ dataObjectHash ^ fileURL;
63
64
}
@@ -66,6 +67,8 @@ - (BOOL)isEqual:(id)object {
66
67
return [self hash ] == [object hash ];
67
68
}
68
69
70
+ #pragma mark - Property overrides
71
+
69
72
- (void )setDataObject : (id <GDTCOREventDataObject>)dataObject {
70
73
// If you're looking here because of a performance issue in -transportBytes slowing the assignment
71
74
// of -dataObject, one way to address this is to add a queue to this class,
@@ -75,22 +78,31 @@ - (void)setDataObject:(id<GDTCOREventDataObject>)dataObject {
75
78
}
76
79
}
77
80
78
- - (BOOL )writeToURL : (NSURL *)fileURL error : (NSError **)error {
81
+ - (NSURL *)fileURL {
82
+ if (!_GDTFilePath) {
83
+ _GDTFilePath = [NSString stringWithFormat: @" event-%lu " , (unsigned long )self .hash];
84
+ }
85
+ return [GDTCORRootDirectory () URLByAppendingPathComponent: _GDTFilePath];
86
+ }
87
+
88
+ #pragma mark - Private methods
89
+
90
+ - (BOOL )writeToGDTPath : (NSString *)filePath error : (NSError **)error {
79
91
NSData *dataTransportBytes = [_dataObject transportBytes ];
80
92
if (dataTransportBytes == nil ) {
81
- _fileURL = nil ;
93
+ _GDTFilePath = nil ;
82
94
_dataObject = nil ;
83
95
return NO ;
84
96
}
97
+ NSURL *fileURL = [GDTCORRootDirectory () URLByAppendingPathComponent: filePath];
85
98
BOOL writingSuccess = [dataTransportBytes writeToURL: fileURL
86
99
options: NSDataWritingAtomic
87
100
error: error];
88
101
if (!writingSuccess) {
89
102
GDTCORLogError (GDTCORMCEFileWriteError, @" An event file could not be written: %@ " , fileURL);
90
- _fileURL = nil ;
91
103
return NO ;
92
104
}
93
- _fileURL = fileURL ;
105
+ _GDTFilePath = filePath ;
94
106
_dataObject = nil ;
95
107
return YES ;
96
108
}
@@ -112,6 +124,9 @@ - (BOOL)writeToURL:(NSURL *)fileURL error:(NSError **)error {
112
124
/* * NSCoding key for fileURL property. */
113
125
static NSString *fileURLKey = @" _fileURL" ;
114
126
127
+ /* * NSCoding key for GDTFilePath property. */
128
+ static NSString *kGDTFilePathKey = @" _GDTFilePath" ;
129
+
115
130
/* * NSCoding key for customPrioritizationParams property. */
116
131
static NSString *customPrioritizationParams = @" _customPrioritizationParams" ;
117
132
@@ -152,7 +167,12 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
152
167
if (self) {
153
168
_qosTier = [aDecoder decodeIntegerForKey: qosTierKey];
154
169
_clockSnapshot = [aDecoder decodeObjectOfClass: [GDTCORClock class ] forKey: clockSnapshotKey];
155
- _fileURL = [aDecoder decodeObjectOfClass: [NSURL class ] forKey: fileURLKey];
170
+ NSURL *fileURL = [aDecoder decodeObjectOfClass: [NSURL class ] forKey: fileURLKey];
171
+ if (fileURL) {
172
+ _GDTFilePath = [fileURL lastPathComponent ];
173
+ } else {
174
+ _GDTFilePath = [aDecoder decodeObjectOfClass: [NSString class ] forKey: kGDTFilePathKey ];
175
+ }
156
176
_customPrioritizationParams = [aDecoder decodeObjectOfClass: [NSDictionary class ]
157
177
forKey: customPrioritizationParams];
158
178
}
@@ -171,7 +191,11 @@ - (id)initWithCoderForStoredEventBackwardCompatibility:(NSCoder *)aDecoder
171
191
forKey: kStoredEventQosTierKey ] integerValue ];
172
192
_clockSnapshot = [aDecoder decodeObjectOfClass: [GDTCORClock class ]
173
193
forKey: kStoredEventClockSnapshotKey ];
174
- _fileURL = fileURL;
194
+ if (fileURL) {
195
+ _GDTFilePath = [fileURL lastPathComponent ];
196
+ } else {
197
+ _GDTFilePath = [aDecoder decodeObjectOfClass: [NSString class ] forKey: kGDTFilePathKey ];
198
+ }
175
199
_customPrioritizationParams =
176
200
[aDecoder decodeObjectOfClass: [NSDictionary class ]
177
201
forKey: kStoredEventCustomPrioritizationParamsKey ];
@@ -184,7 +208,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
184
208
[aCoder encodeInteger: _target forKey: targetKey];
185
209
[aCoder encodeInteger: _qosTier forKey: qosTierKey];
186
210
[aCoder encodeObject: _clockSnapshot forKey: clockSnapshotKey];
187
- [aCoder encodeObject: _fileURL forKey: fileURLKey ];
211
+ [aCoder encodeObject: _GDTFilePath forKey: kGDTFilePathKey ];
188
212
[aCoder encodeObject: _customPrioritizationParams forKey: customPrioritizationParams];
189
213
}
190
214
0 commit comments