FIRDatabaseConfig.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2017 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 "FIRDatabaseConfig.h"
  17. #import "FAuthTokenProvider.h"
  18. #import "FIRDatabaseConfig_Private.h"
  19. #import "FIRNoopAuthTokenProvider.h"
  20. @interface FIRDatabaseConfig (Private)
  21. @property (nonatomic, strong, readwrite) NSString *sessionIdentifier;
  22. @end
  23. @implementation FIRDatabaseConfig
  24. - (id)init {
  25. [NSException raise:NSInvalidArgumentException format:@"Can't create config objects!"];
  26. return nil;
  27. }
  28. - (id)initWithSessionIdentifier:(NSString *)identifier authTokenProvider:(id<FAuthTokenProvider>)authTokenProvider {
  29. self = [super init];
  30. if (self != nil) {
  31. self->_sessionIdentifier = identifier;
  32. self->_callbackQueue = dispatch_get_main_queue();
  33. self->_persistenceCacheSizeBytes = 10*1024*1024; // Default cache size is 10MB
  34. self->_authTokenProvider = authTokenProvider;
  35. }
  36. return self;
  37. }
  38. - (void)assertUnfrozen {
  39. if (self.isFrozen) {
  40. [NSException raise:NSGenericException format:@"Can't modify config objects after they are in use for FIRDatabaseReferences."];
  41. }
  42. }
  43. - (void)setAuthTokenProvider:(id<FAuthTokenProvider>)authTokenProvider {
  44. [self assertUnfrozen];
  45. self->_authTokenProvider = authTokenProvider;
  46. }
  47. - (void)setPersistenceEnabled:(BOOL)persistenceEnabled {
  48. [self assertUnfrozen];
  49. self->_persistenceEnabled = persistenceEnabled;
  50. }
  51. - (void)setPersistenceCacheSizeBytes:(NSUInteger)persistenceCacheSizeBytes {
  52. [self assertUnfrozen];
  53. // Can't be less than 1MB
  54. if (persistenceCacheSizeBytes < 1024*1024) {
  55. [NSException raise:NSInvalidArgumentException format:@"The minimum cache size must be at least 1MB"];
  56. }
  57. if (persistenceCacheSizeBytes > 100*1024*1024) {
  58. [NSException raise:NSInvalidArgumentException format:@"Firebase Database currently doesn't support a cache size larger than 100MB"];
  59. }
  60. self->_persistenceCacheSizeBytes = persistenceCacheSizeBytes;
  61. }
  62. - (void)setCallbackQueue:(dispatch_queue_t)callbackQueue {
  63. [self assertUnfrozen];
  64. self->_callbackQueue = callbackQueue;
  65. }
  66. - (void)freeze {
  67. self->_isFrozen = YES;
  68. }
  69. @end