GDTCORPrioritizer.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2018 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/GDTCOREvent.h>
  18. #import <GoogleDataTransport/GDTCORLifecycle.h>
  19. #import <GoogleDataTransport/GDTCORUploadPackage.h>
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** Options that define a set of upload conditions. This is used to help minimize end user data
  22. * consumption impact.
  23. */
  24. typedef NS_OPTIONS(NSInteger, GDTCORUploadConditions) {
  25. /** An upload shouldn't be attempted, because there's no network. */
  26. GDTCORUploadConditionNoNetwork = 1 << 0,
  27. /** An upload would likely use mobile data. */
  28. GDTCORUploadConditionMobileData = 1 << 1,
  29. /** An upload would likely use wifi data. */
  30. GDTCORUploadConditionWifiData = 1 << 2,
  31. /** An upload uses some sort of network connection, but it's unclear which. */
  32. GDTCORUploadConditionUnclearConnection = 1 << 3,
  33. /** A high priority event has occurred. */
  34. GDTCORUploadConditionHighPriority = 1 << 4,
  35. };
  36. /** This protocol defines the common interface of event prioritization. Prioritizers are
  37. * stateful objects that prioritize events upon insertion into storage and remain prepared to return
  38. * a set of filenames to the storage system.
  39. */
  40. @protocol GDTCORPrioritizer <NSObject, GDTCORLifecycleProtocol, GDTCORUploadPackageProtocol>
  41. @required
  42. /** Accepts an event and uses the event metadata to make choices on how to prioritize the event.
  43. * This method exists as a way to help prioritize which events should be sent, which is dependent on
  44. * the request proto structure of your backend.
  45. *
  46. * @param event The event to prioritize.
  47. */
  48. - (void)prioritizeEvent:(GDTCOREvent *)event;
  49. /** Returns a set of events to upload given a set of conditions.
  50. *
  51. * @param target The target to create an upload package for.
  52. * @param conditions A bit mask specifying the current upload conditions.
  53. * @return An object to be used by the uploader to determine file URLs to upload with respect to the
  54. * current conditions.
  55. */
  56. - (GDTCORUploadPackage *)uploadPackageWithTarget:(GDTCORTarget)target
  57. conditions:(GDTCORUploadConditions)conditions;
  58. @optional
  59. /** Saves the state of the prioritizer. */
  60. - (void)saveState;
  61. @end
  62. NS_ASSUME_NONNULL_END