SessionCoordinator.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. ///
  16. /// SessionCoordinator is responsible for coordinating the systems in this SDK
  17. /// involved with sending a Session Start event.
  18. ///
  19. class SessionCoordinator {
  20. let identifiers: IdentifierProvider
  21. let fireLogger: EventGDTLoggerProtocol
  22. init(identifiers: IdentifierProvider, fireLogger: EventGDTLoggerProtocol) {
  23. self.identifiers = identifiers
  24. self.fireLogger = fireLogger
  25. }
  26. // Begins the process of logging a SessionStartEvent to FireLog, while taking into account Data Collection, Sampling, and fetching Settings
  27. func attemptLoggingSessionStart(event: SessionStartEvent,
  28. callback: @escaping (Result<Void, Error>) -> Void) {
  29. event.setInstallationID(identifiers: identifiers)
  30. fireLogger.logEvent(event: event) { result in
  31. switch result {
  32. case .success():
  33. Logger.logInfo("Successfully logged Session Start event to GoogleDataTransport")
  34. callback(.success(()))
  35. case let .failure(error):
  36. Logger
  37. .logError(
  38. "Error logging Session Start event to GoogleDataTransport: \(error)."
  39. )
  40. callback(.failure(error))
  41. }
  42. }
  43. }
  44. }