FIRStorageComponent.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "FirebaseAppCheck/Sources/Interop/FIRAppCheckInterop.h"
  17. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  18. #import "Interop/Auth/Public/FIRAuthInterop.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FIRStorage ()
  21. // Surface the internal initializer to create instances of FIRStorage.
  22. - (instancetype)initWithApp:(FIRApp *)app
  23. bucket:(NSString *)bucket
  24. auth:(nullable id<FIRAuthInterop>)auth
  25. appCheck:(nullable id<FIRAppCheckInterop>)appCheck;
  26. @end
  27. @interface FIRStorageComponent () <FIRLibrary>
  28. /// Internal initializer.
  29. - (instancetype)initWithApp:(FIRApp *)app;
  30. @end
  31. @implementation FIRStorageComponent
  32. #pragma mark - Initialization
  33. - (instancetype)initWithApp:(FIRApp *)app {
  34. self = [super init];
  35. if (self) {
  36. _app = app;
  37. }
  38. return self;
  39. }
  40. #pragma mark - Lifecycle
  41. + (void)load {
  42. [FIRApp registerInternalLibrary:(Class<FIRLibrary>)self withName:@"fire-str"];
  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. id<FIRAppCheckInterop> appCheck = FIR_COMPONENT(FIRAppCheckInterop, self.app.container);
  64. return [[FIRStorage alloc] initWithApp:self.app bucket:bucket auth:auth appCheck:appCheck];
  65. }
  66. @end
  67. NS_ASSUME_NONNULL_END