FIRDatabaseConfig.m 3.1 KB

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