FIRInstallationsBackoffController.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2020 Google LLC
  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 "FirebaseInstallations/Source/Library/InstallationsIDController/FIRCurrentDateProvider.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. typedef NS_ENUM(NSInteger, FIRInstallationsBackoffEvent) {
  20. FIRInstallationsBackoffEventSuccess,
  21. FIRInstallationsBackoffEventRecoverableFailure,
  22. FIRInstallationsBackoffEventUnrecoverableFailure
  23. };
  24. /** The protocol defines API for a class that encapsulates backoff logic that prevents the SDK from
  25. * sending unnecessary server requests. See API docs for the methods for more details. */
  26. @protocol FIRInstallationsBackoffControllerProtocol <NSObject>
  27. /** The client must call the method each time a protected server request succeeds of fails. It will
  28. * affect the `isNextRequestAllowed` method result for the current time, e.g. when 3 recoverable
  29. * errors were logged in a row, then `isNextRequestAllowed` will return `YES` only in `pow(2, 3)`
  30. * seconds. */
  31. - (void)registerEvent:(FIRInstallationsBackoffEvent)event;
  32. /** Returns if sending a next protected is recommended based on the time and the sequence of logged
  33. * events and the current time. See also `registerEvent:`. */
  34. - (BOOL)isNextRequestAllowed;
  35. @end
  36. /** An implementation of `FIRInstallationsBackoffControllerProtocol` with exponential backoff for
  37. * recoverable errors and constant backoff for recoverable errors. */
  38. @interface FIRInstallationsBackoffController : NSObject <FIRInstallationsBackoffControllerProtocol>
  39. - (instancetype)initWithCurrentDateProvider:(FIRCurrentDateProvider)currentDateProvider;
  40. @end
  41. NS_ASSUME_NONNULL_END