Files
firebase-ios-sdk/GoogleDataTransport/GDTCORLibrary/Private/GDTCORTransformer.h
T
Michael Haney aeb4def61d Libraries should save state if a completion block is requested (#5147)
* Libraries should save state if a completion block is requested

Currently, the onComplete block of sendXEvent:onComplete: is invoked when the event bytes are written to disk. However, if the app crashes before a lifecycle event occurs (trigger GDTCORStorage to serialize to disk), that event if effectively lost because the metadata has all been lost. This change triggers the saving of state of GDTCORStorage and prioritizers (if they implement it) if an onComplete block has been given.

* Remove flaky check

* Update GDTCORStorage.m
2020-03-18 15:00:37 -07:00

57 lines
2.1 KiB
Objective-C

/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import <GoogleDataTransport/GDTCORLifecycle.h>
@class GDTCOREvent;
@protocol GDTCOREventTransformer;
NS_ASSUME_NONNULL_BEGIN
/** Manages the transforming of events. It's desirable for this to be its own class
* because running all events through a single instance ensures that transformers are thread-safe.
* Having a per-transport queue to run on isn't sufficient because transformer objects could
* maintain state (or at least, there's nothing to stop them from doing that) and the same instances
* may be used across multiple instances.
*/
@interface GDTCORTransformer : NSObject <GDTCORLifecycleProtocol>
/** Instantiates or returns the event transformer singleton.
*
* @return The singleton instance of the event transformer.
*/
+ (instancetype)sharedInstance;
/** Writes the result of applying the given transformers' -transform method on the given event.
*
* @note If the app is suspended, a background task will be created to complete work in-progress,
* but this method will not send any further events until the app is resumed.
*
* @param event The event to apply transformers on.
* @param transformers The list of transformers to apply.
* @param completion A block to run when an event was written to disk or dropped.
*/
- (void)transformEvent:(GDTCOREvent *)event
withTransformers:(nullable NSArray<id<GDTCOREventTransformer>> *)transformers
onComplete:(void (^_Nullable)(BOOL wasWritten, NSError *_Nullable error))completion;
@end
NS_ASSUME_NONNULL_END