GDTCORStorageProtocol.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2020 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. #import <Foundation/Foundation.h>
  17. #import <GoogleDataTransport/GDTCORLifecycle.h>
  18. #import <GoogleDataTransport/GDTCORTargets.h>
  19. @class GDTCOREvent;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** Defines the interface a storage subsystem is expected to implement. */
  22. @protocol GDTCORStorageProtocol <NSObject, GDTCORLifecycleProtocol>
  23. @required
  24. /** Stores an event and calls onComplete with a non-nil error if anything went wrong.
  25. *
  26. * @param event The event to store
  27. * @param completion The completion block to call after an attempt to store the event has been made.
  28. */
  29. - (void)storeEvent:(GDTCOREvent *)event
  30. onComplete:(void (^_Nullable)(BOOL wasWritten, NSError *_Nullable error))completion;
  31. /** Removes the events from storage. */
  32. - (void)removeEvents:(NSSet<NSNumber *> *)eventIDs;
  33. /** Persists the given data with the given key.
  34. *
  35. * @param data The data to store.
  36. * @param key The unique key to store it to.
  37. * @param onComplete An block to be run when storage of the data is complete.
  38. */
  39. - (void)storeLibraryData:(NSData *)data
  40. forKey:(NSString *)key
  41. onComplete:(void (^)(NSError *_Nullable error))onComplete;
  42. /** Retrieves the stored data for the given key.
  43. *
  44. * @param key The key corresponding to the desired data.
  45. * @param onComplete The callback to invoke with the data once it's retrieved.
  46. */
  47. - (void)libraryDataForKey:(NSString *)key
  48. onComplete:(void (^)(NSData *_Nullable data, NSError *_Nullable error))onComplete;
  49. /** Removes data from storage and calls the callback when complete.
  50. *
  51. * @param key The key of the data to remove.
  52. * @param onComplete The callback that will be invoked when removing the data is complete.
  53. */
  54. - (void)removeLibraryDataForKey:(NSString *)key
  55. onComplete:(void (^)(NSError *_Nullable error))onComplete;
  56. @end
  57. /** Retrieves the storage instance for the given target.
  58. *
  59. * @param target The target.
  60. * * @return The storage instance registered for the target, or nil if there is none.
  61. */
  62. FOUNDATION_EXPORT
  63. id<GDTCORStorageProtocol> _Nullable GDTCORStorageInstanceForTarget(GDTCORTarget target);
  64. NS_ASSUME_NONNULL_END