StorageTask.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2022 Google LLC
  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 Foundation
  15. import FirebaseStorageObjC
  16. /**
  17. * A superclass to all Storage*Tasks, including StorageUploadTask
  18. * and StorageDownloadTask, to provide state transitions, event raising, and common storage
  19. * or metadata and errors.
  20. * Callbacks are always fired on the developer specified callback queue.
  21. * If no queue is specified by the developer, it defaults to the main queue.
  22. * Currently not thread safe, so only call methods on the main thread.
  23. */
  24. @objc(FIRStorageTask) open class StorageTask: NSObject {
  25. /**
  26. * An immutable view of the task and associated metadata, progress, error, etc.
  27. */
  28. @objc public var snapshot: StorageTaskSnapshot {
  29. return StorageTaskSnapshot(task: self)
  30. }
  31. // MARK: - Internal APIs
  32. internal let impl: FIRIMPLStorageTask
  33. internal init(impl: FIRIMPLStorageTask) {
  34. self.impl = impl
  35. }
  36. }
  37. /**
  38. * Defines task operations such as pause, resume, cancel, and enqueue for all tasks.
  39. * All tasks are required to implement enqueue, which begins the task, and may optionally
  40. * implement pause, resume, and cancel, which operate on the task to pause, resume, and cancel
  41. * operations.
  42. */
  43. @objc(FIRStorageTaskManagement) public protocol StorageTaskManagement: NSObjectProtocol {
  44. /**
  45. * Prepares a task and begins execution.
  46. */
  47. @objc func enqueue() -> Void
  48. /**
  49. * Pauses a task currently in progress.
  50. */
  51. @objc optional func pause() -> Void
  52. /**
  53. * Pauses a task currently in progress.
  54. */
  55. @objc optional func cancel() -> Void
  56. /**
  57. * Pauses a task currently in progress.
  58. */
  59. @objc optional func resume() -> Void
  60. }