2022-03-17 16:00:42 -07:00
|
|
|
// Copyright 2022 Google LLC
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* `StorageTaskSnapshot` represents an immutable view of a task.
|
|
|
|
|
* A snapshot contains a task, storage reference, metadata (if it exists),
|
2022-03-17 16:00:42 -07:00
|
|
|
* progress, and an error (if one occurred).
|
|
|
|
|
*/
|
2024-07-03 11:30:27 -07:00
|
|
|
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
|
2022-03-17 16:00:42 -07:00
|
|
|
@objc(FIRStorageTaskSnapshot) open class StorageTaskSnapshot: NSObject {
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* The task this snapshot represents.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let task: StorageTask
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* Metadata returned by the task, or `nil` if no metadata returned.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let metadata: StorageMetadata?
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* The `StorageReference` this task operates on.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let reference: StorageReference
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* An object which tracks the progress of an upload or download.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let progress: Progress?
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* An error raised during task execution, or `nil` if no error occurred.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let error: Error?
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 11:04:38 -07:00
|
|
|
* The status of the task.
|
2022-03-17 16:00:42 -07:00
|
|
|
*/
|
|
|
|
|
@objc public let status: StorageTaskStatus
|
|
|
|
|
|
2022-06-29 10:29:49 -07:00
|
|
|
// MARK: NSObject overrides
|
2022-03-17 16:00:42 -07:00
|
|
|
|
|
|
|
|
@objc override public var description: String {
|
2022-06-29 10:29:49 -07:00
|
|
|
switch status {
|
|
|
|
|
case .resume: return "<State: Resume>"
|
|
|
|
|
case .progress: return "<State: Progress, Progress: \(String(describing: progress))>"
|
|
|
|
|
case .pause: return "<State: Paused>"
|
|
|
|
|
case .success: return "<State: Success>"
|
|
|
|
|
case .failure: return "<State: Failed, Error: \(String(describing: error))"
|
|
|
|
|
case .unknown: return "<State: Unknown>"
|
|
|
|
|
}
|
2022-03-17 16:00:42 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-21 12:12:05 -08:00
|
|
|
init(task: StorageTask,
|
|
|
|
|
state: StorageTaskState,
|
|
|
|
|
reference: StorageReference,
|
|
|
|
|
progress: Progress,
|
|
|
|
|
metadata: StorageMetadata? = nil,
|
2024-06-14 15:51:49 -07:00
|
|
|
error: Error? = nil) {
|
2022-03-17 16:00:42 -07:00
|
|
|
self.task = task
|
2022-08-17 07:14:16 -07:00
|
|
|
self.reference = reference
|
2022-06-29 10:29:49 -07:00
|
|
|
self.progress = progress
|
|
|
|
|
self.error = error
|
2022-07-19 11:10:41 -07:00
|
|
|
self.metadata = metadata
|
2022-06-29 10:29:49 -07:00
|
|
|
|
|
|
|
|
switch state {
|
|
|
|
|
case .queueing, .running, .resuming: status = StorageTaskStatus.resume
|
|
|
|
|
case .progress: status = StorageTaskStatus.progress
|
|
|
|
|
case .paused, .pausing: status = StorageTaskStatus.pause
|
|
|
|
|
case .success, .completing: status = StorageTaskStatus.success
|
|
|
|
|
case .cancelled, .failed, .failing: status = .failure
|
|
|
|
|
case .unknown: status = .unknown
|
2022-03-17 16:00:42 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|