FIRStorageComponent.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <FirebaseAuthInterop/FIRAuthInterop.h>
  17. #import <FirebaseCore/FIRAppInternal.h>
  18. #import <FirebaseCore/FIRComponent.h>
  19. #import <FirebaseCore/FIRComponentContainer.h>
  20. #import <FirebaseCore/FIRDependency.h>
  21. #import <FirebaseCore/FIRLibrary.h>
  22. NS_ASSUME_NONNULL_BEGIN
  23. @interface FIRStorage ()
  24. // Surface the internal initializer to create instances of FIRStorage.
  25. - (instancetype)initWithApp:(FIRApp *)app
  26. bucket:(NSString *)bucket
  27. auth:(nullable id<FIRAuthInterop>)auth;
  28. @end
  29. @interface FIRStorageComponent () <FIRLibrary>
  30. /// Internal initializer.
  31. - (instancetype)initWithApp:(FIRApp *)app;
  32. @end
  33. @implementation FIRStorageComponent
  34. #pragma mark - Initialization
  35. - (instancetype)initWithApp:(FIRApp *)app {
  36. self = [super init];
  37. if (self) {
  38. _app = app;
  39. }
  40. return self;
  41. }
  42. #pragma mark - Lifecycle
  43. + (void)load {
  44. [FIRApp registerInternalLibrary:(Class<FIRLibrary>)self
  45. withName:@"fire-str"
  46. withVersion:[NSString stringWithUTF8String:FIRStorageVersionString]];
  47. }
  48. #pragma mark - FIRComponentRegistrant
  49. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  50. FIRDependency *authDep = [FIRDependency dependencyWithProtocol:@protocol(FIRAuthInterop)
  51. isRequired:NO];
  52. FIRComponentCreationBlock creationBlock =
  53. ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
  54. return [[FIRStorageComponent alloc] initWithApp:container.app];
  55. };
  56. FIRComponent *storageProvider =
  57. [FIRComponent componentWithProtocol:@protocol(FIRStorageMultiBucketProvider)
  58. instantiationTiming:FIRInstantiationTimingLazy
  59. dependencies:@[ authDep ]
  60. creationBlock:creationBlock];
  61. return @[ storageProvider ];
  62. }
  63. #pragma mark - FIRStorageInstanceProvider Conformance
  64. - (FIRStorage *)storageForBucket:(NSString *)bucket {
  65. // Create an instance of FIRStorage and return it.
  66. id<FIRAuthInterop> auth = FIR_COMPONENT(FIRAuthInterop, self.app.container);
  67. return [[FIRStorage alloc] initWithApp:self.app bucket:bucket auth:auth];
  68. }
  69. @end
  70. NS_ASSUME_NONNULL_END