/
History.swift
90 lines (75 loc) · 3.26 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
/* 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
import Deferred
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 {
func addLocalVisit(_ visit: SiteVisit) -> Success
func clearHistory() -> Success
func removeHistoryForURL(_ url: String) -> Success
func removeSiteFromTopSites(_ site: Site) -> Success
func getSitesByFrecencyWithHistoryLimit(_ limit: Int) -> Deferred<Maybe<Cursor<Site>>>
func getSitesByFrecencyWithHistoryLimit(_ limit: Int, whereURLContains filter: String) -> Deferred<Maybe<Cursor<Site>>>
func getSitesByFrecencyWithHistoryLimit(_ limit: Int, bookmarksLimit: Int, whereURLContains filter: String) -> Deferred<Maybe<Cursor<Site>>>
func getSitesByLastVisit(_ limit: Int) -> Deferred<Maybe<Cursor<Site>>>
func getTopSitesWithLimit(_ limit: Int) -> Deferred<Maybe<Cursor<Site>>>
func setTopSitesNeedsInvalidation()
func updateTopSitesCacheIfInvalidated() -> Deferred<Maybe<Bool>>
func setTopSitesCacheSize(_ size: Int32)
func clearTopSitesCache() -> Success
func refreshTopSitesCache() -> Success
func areTopSitesDirty(withLimit limit: Int) -> Deferred<Maybe<Bool>>
}
/**
* The interface that history storage needs to provide in order to be
* synced by a `HistorySynchronizer`.
*/
public protocol SyncableHistory: AccountRemovalDelegate {
/**
* 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>>
}
// TODO: integrate Site with this.
open class Place {
open let guid: GUID
open let url: String
open let title: String
public init(guid: GUID, url: String, title: String) {
self.guid = guid
self.url = url
self.title = title
}
}