FIRStorageComponent.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/Sources/Public/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 withName:@"fire-str"];
  41. }
  42. #pragma mark - FIRComponentRegistrant
  43. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  44. FIRDependency *authDep = [FIRDependency dependencyWithProtocol:@protocol(FIRAuthInterop)
  45. isRequired:NO];
  46. FIRComponentCreationBlock creationBlock =
  47. ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
  48. return [[FIRStorageComponent alloc] initWithApp:container.app];
  49. };
  50. FIRComponent *storageProvider =
  51. [FIRComponent componentWithProtocol:@protocol(FIRStorageMultiBucketProvider)
  52. instantiationTiming:FIRInstantiationTimingLazy
  53. dependencies:@[ authDep ]
  54. creationBlock:creationBlock];
  55. return @[ storageProvider ];
  56. }
  57. #pragma mark - FIRStorageInstanceProvider Conformance
  58. - (FIRStorage *)storageForBucket:(NSString *)bucket {
  59. // Create an instance of FIRStorage and return it.
  60. id<FIRAuthInterop> auth = FIR_COMPONENT(FIRAuthInterop, self.app.container);
  61. return [[FIRStorage alloc] initWithApp:self.app bucket:bucket auth:auth];
  62. }
  63. @end
  64. NS_ASSUME_NONNULL_END