-
Notifications
You must be signed in to change notification settings - Fork 25
/
History.swift
106 lines (90 loc) · 3.63 KB
/
History.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Shared
open class IgnoredSiteError: MaybeErrorType {
open var description: String {
return "Ignored site."
}
}
/**
* The base history protocol for front-end code.
*
* Note that the implementation of these methods might be complicated if
* the implementing class also implements SyncableHistory -- for example,
* `clear` might or might not need to set a bunch of flags to upload deletions.
*/
public protocol BrowserHistory {
@discardableResult func addLocalVisit(_ visit: SiteVisit) -> Success
func clearHistory() -> Success
@discardableResult func removeHistoryForURL(_ url: String) -> Success
func removeHistoryFromDate(_ date: Date) -> Success
func removeSiteFromTopSites(_ site: Site) -> Success
func removeHostFromTopSites(_ host: String) -> Success
func getFrecentHistory() -> FrecentHistory
func getSitesByLastVisit(limit: Int, offset: Int) -> Deferred<Maybe<Cursor<Site>>>
func getTopSitesWithLimit(_ limit: Int) -> Deferred<Maybe<Cursor<Site>>>
func setTopSitesNeedsInvalidation()
func setTopSitesCacheSize(_ size: Int32)
func clearTopSitesCache() -> Success
// Pinning top sites
func removeFromPinnedTopSites(_ site: Site) -> Success
func addPinnedTopSite(_ site: Site) -> Success
func getPinnedTopSites() -> Deferred<Maybe<Cursor<Site>>>
func isPinnedTopSite(_ url: String) -> Deferred<Maybe<Bool>>
}
/**
* An interface for fast repeated frecency queries.
*/
public protocol FrecentHistory {
func getSites(matchingSearchQuery filter: String?, limit: Int) -> Deferred<Maybe<Cursor<Site>>>
func updateTopSitesCacheQuery() -> (String, Args?)
}
/**
* An interface for accessing recommendation content from Storage
*/
public protocol HistoryRecommendations {
func cleanupHistoryIfNeeded()
func repopulate(invalidateTopSites shouldInvalidateTopSites: Bool) -> Success
}
/**
* The interface that history storage needs to provide in order to be
* synced by a `HistorySynchronizer`.
*/
public protocol SyncableHistory {
/**
* Make sure that the local place with the provided URL has the provided GUID.
* Succeeds if no place exists with that URL.
*/
func ensurePlaceWithURL(_ url: String, hasGUID guid: GUID) -> Success
/**
* Delete the place with the provided GUID, and all of its visits. Succeeds if the GUID is unknown.
*/
func deleteByGUID(_ guid: GUID, deletedAt: Timestamp) -> Success
func storeRemoteVisits(_ visits: [Visit], forGUID guid: GUID) -> Success
func insertOrUpdatePlace(_ place: Place, modified: Timestamp) -> Deferred<Maybe<GUID>>
func getModifiedHistoryToUpload() -> Deferred<Maybe<[(Place, [Visit])]>>
func getDeletedHistoryToUpload() -> Deferred<Maybe<[GUID]>>
/**
* Chains through the provided timestamp.
*/
func markAsSynchronized(_: [GUID], modified: Timestamp) -> Deferred<Maybe<Timestamp>>
func markAsDeleted(_ guids: [GUID]) -> Success
func doneApplyingRecordsAfterDownload() -> Success
func doneUpdatingMetadataAfterUpload() -> Success
/**
* For inspecting whether we're an active participant in history sync.
*/
func hasSyncedHistory() -> Deferred<Maybe<Bool>>
}
// TO DO: integrate Site with this.
open class Place {
public let guid: GUID
public let url: String
public let title: String
public init(guid: GUID, url: String, title: String) {
self.guid = guid
self.url = url
self.title = title
}
}