Skip to content

Commit

Permalink
Add HistoryCoordinatingDebuggingSupport protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Feb 5, 2025
1 parent 7f6f5dd commit 84c705d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions Sources/History/HistoryCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import os.log

public typealias BrowsingHistory = [HistoryEntry]

public protocol HistoryCoordinating: AnyObject {
public protocol HistoryCoordinatingDebuggingSupport {
@discardableResult func addVisit(of url: URL, at date: Date) -> Visit?
}

public protocol HistoryCoordinating: AnyObject, HistoryCoordinatingDebuggingSupport {

func loadHistory(onCleanFinished: @escaping () -> Void)

Expand All @@ -47,6 +51,12 @@ public protocol HistoryCoordinating: AnyObject {
func removeUrlEntry(_ url: URL, completion: ((Error?) -> Void)?)
}

extension HistoryCoordinating {
public func addVisit(of url: URL) -> Visit? {
addVisit(of: url, at: Date())
}
}

/// Coordinates access to History. Uses its own queue with high qos for all operations.
final public class HistoryCoordinator: HistoryCoordinating {

Expand Down Expand Up @@ -86,14 +96,14 @@ final public class HistoryCoordinator: HistoryCoordinating {

private var cancellables = Set<AnyCancellable>()

@discardableResult public func addVisit(of url: URL) -> Visit? {
@discardableResult public func addVisit(of url: URL, at date: Date) -> Visit? {
guard let historyDictionary = historyDictionary else {
Logger.history.debug("Visit of \(url.absoluteString) ignored")
return nil
}

let entry = historyDictionary[url] ?? HistoryEntry(url: url)
let visit = entry.addVisit()
let visit = entry.addVisit(at: date)
entry.failedToLoad = false

self.historyDictionary?[url] = entry
Expand Down
6 changes: 3 additions & 3 deletions Sources/History/HistoryEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ final public class HistoryEntry {

public var visits: Set<Visit>

func addVisit() -> Visit {
let visit = Visit(date: Date(), historyEntry: self)
func addVisit(at date: Date = Date()) -> Visit {
let visit = Visit(date: date, historyEntry: self)
visits.insert(visit)

lastVisit = numberOfTotalVisits == 0 ? date : max(lastVisit, date)
numberOfTotalVisits += 1
lastVisit = Date()

return visit
}
Expand Down

0 comments on commit 84c705d

Please sign in to comment.