FIRStorageComponent.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2018 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FirebaseStorage/Sources/FIRStorageComponent.h"
  15. #import <FirebaseStorage/FIRStorage.h>
  16. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  17. #import "Interop/Auth/Public/FIRAuthInterop.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @interface FIRStorage ()
  20. // Surface the internal initializer to create instances of FIRStorage.
  21. - (instancetype)initWithApp:(FIRApp *)app
  22. bucket:(NSString *)bucket
  23. auth:(nullable id<FIRAuthInterop>)auth;
  24. @end
  25. @interface FIRStorageComponent () <FIRLibrary>
  26. /// Internal initializer.
  27. - (instancetype)initWithApp:(FIRApp *)app;
  28. @end
  29. @implementation FIRStorageComponent
  30. #pragma mark - Initialization
  31. - (instancetype)initWithApp:(FIRApp *)app {
  32. self = [super init];
  33. if (self) {
  34. _app = app;
  35. }
  36. return self;
  37. }
  38. #pragma mark - Lifecycle
  39. + (void)load {
  40. [FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
  41. withName:@"fire-str"
  42. withVersion:[NSString stringWithUTF8String:FIRStorageVersionString]];
  43. }
  44. #pragma mark - FIRComponentRegistrant
  45. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  46. FIRDependency *authDep = [FIRDependency dependencyWithProtocol:@protocol(FIRAuthInterop)
  47. isRequired:NO];
  48. FIRComponentCreationBlock creationBlock =
  49. ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
  50. return [[FIRStorageComponent alloc] initWithApp:container.app];
  51. };
  52. FIRComponent *storageProvider =
  53. [FIRComponent componentWithProtocol:@protocol(FIRStorageMultiBucketProvider)
  54. instantiationTiming:FIRInstantiationTimingLazy
  55. dependencies:@[ authDep ]
  56. creationBlock:creationBlock];
  57. return @[ storageProvider ];
  58. }
  59. #pragma mark - FIRStorageInstanceProvider Conformance
  60. - (FIRStorage *)storageForBucket:(NSString *)bucket {
  61. // Create an instance of FIRStorage and return it.
  62. id<FIRAuthInterop> auth = FIR_COMPONENT(FIRAuthInterop, self.app.container);
  63. return [[FIRStorage alloc] initWithApp:self.app bucket:bucket auth:auth];
  64. }
  65. @end
  66. NS_ASSUME_NONNULL_END