2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

  1. //
  2. // SCContextAwareSnapCreationThrottleRequest.m
  3. // SCCamera
  4. //
  5. // Created by Cheng Jiang on 4/24/18.
  6. //
  7. #import "SCContextAwareSnapCreationThrottleRequest.h"
  8. #import <SCFoundation/SCAssertWrapper.h>
  9. #import <SCFoundation/SCContextAwareTaskManagementResourceProvider.h>
  10. #import <SCFoundation/SCZeroDependencyExperiments.h>
  11. #import <Tweaks/FBTweakInline.h>
  12. BOOL SCCATMSnapCreationEnabled(void)
  13. {
  14. static dispatch_once_t capturingOnceToken;
  15. static BOOL capturingImprovementEnabled;
  16. dispatch_once(&capturingOnceToken, ^{
  17. BOOL enabledWithAB = SCExperimentWithContextAwareTaskManagementCapturingImprovementEnabled();
  18. NSInteger tweakOption = [FBTweakValue(@"CATM", @"Performance Improvement", @"Capturing", (id) @0,
  19. (@{ @0 : @"Respect A/B",
  20. @1 : @"YES",
  21. @2 : @"NO" })) integerValue];
  22. switch (tweakOption) {
  23. case 0:
  24. capturingImprovementEnabled = enabledWithAB;
  25. break;
  26. case 1:
  27. capturingImprovementEnabled = YES;
  28. break;
  29. case 2:
  30. capturingImprovementEnabled = NO;
  31. break;
  32. default:
  33. SCCAssertFail(@"Illegal option");
  34. }
  35. });
  36. return capturingImprovementEnabled;
  37. }
  38. @implementation SCContextAwareSnapCreationThrottleRequest {
  39. NSString *_requestID;
  40. }
  41. - (instancetype)init
  42. {
  43. if (self = [super init]) {
  44. _requestID = @"SCContextAwareSnapCreationThrottleRequest";
  45. }
  46. return self;
  47. }
  48. - (BOOL)shouldThrottle:(SCApplicationContextState)context
  49. {
  50. return SCCATMSnapCreationEnabled() && context != SCApplicationContextStateCamera;
  51. }
  52. - (NSString *)requestID
  53. {
  54. return _requestID;
  55. }
  56. - (BOOL)isEqual:(id<SCContextAwareThrottleRequest>)object
  57. {
  58. return [[object requestID] isEqualToString:_requestID];
  59. }
  60. @end