This repository was archived by the owner on Nov 1, 2022. It is now read-only.
-
Couldn't load subscription status.
- Fork 476
Closes #1126: Rust Places backed implementation of concept-storage #1164
Merged
grigoryk
merged 6 commits into
mozilla-mobile:master
from
grigoryk:historyDelegatePlaces
Nov 6, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c2e704d
Bump app-services dependency to 0.8.1
3687bb2
Switch HistoryStorage to use Deferred results and suspend functions
dcaf924
Add 'cleanup' method to HistoryStorage concept
61c4724
Add 'limit' to HistoryStorage's getSuggestion concept method
bd3204d
A Rust Places backed implementation of concept-storage
9a28351
Updated changelog to reflect concept-* and browser-* changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| package mozilla.components.browser.storage.memory | ||
|
|
||
| import android.support.annotation.VisibleForTesting | ||
| import kotlinx.coroutines.experimental.CompletableDeferred | ||
| import kotlinx.coroutines.experimental.Deferred | ||
| import mozilla.components.concept.storage.HistoryStorage | ||
| import mozilla.components.concept.storage.PageObservation | ||
| import mozilla.components.concept.storage.SearchResult | ||
|
|
@@ -24,7 +26,7 @@ class InMemoryHistoryStorage : HistoryStorage { | |
| @VisibleForTesting | ||
| internal val pageMeta: HashMap<String, PageObservation> = hashMapOf() | ||
|
|
||
| override fun recordVisit(uri: String, visitType: VisitType) { | ||
| override suspend fun recordVisit(uri: String, visitType: VisitType) { | ||
| val now = System.currentTimeMillis() | ||
|
|
||
| synchronized(pages) { | ||
|
|
@@ -36,14 +38,14 @@ class InMemoryHistoryStorage : HistoryStorage { | |
| } | ||
| } | ||
|
|
||
| override fun recordObservation(uri: String, observation: PageObservation) { | ||
| override suspend fun recordObservation(uri: String, observation: PageObservation) { | ||
| synchronized(pageMeta) { | ||
| pageMeta[uri] = observation | ||
| } | ||
| } | ||
|
|
||
| override fun getVisited(uris: List<String>, callback: (List<Boolean>) -> Unit) { | ||
| callback(synchronized(pages) { | ||
| override fun getVisited(uris: List<String>): Deferred<List<Boolean>> { | ||
| return CompletableDeferred(synchronized(pages) { | ||
| uris.map { | ||
| if (pages[it] != null && pages[it]!!.size > 0) { | ||
| return@map true | ||
|
|
@@ -53,13 +55,13 @@ class InMemoryHistoryStorage : HistoryStorage { | |
| }) | ||
| } | ||
|
|
||
| override fun getVisited(callback: (List<String>) -> Unit) { | ||
| callback(synchronized(pages) { | ||
| (pages.keys.toList()) | ||
| override fun getVisited(): Deferred<List<String>> { | ||
| return CompletableDeferred(synchronized(pages) { | ||
| pages.keys.toList() | ||
| }) | ||
| } | ||
|
|
||
| override fun getSuggestions(query: String): List<SearchResult> = synchronized(pages + pageMeta) { | ||
| override fun getSuggestions(query: String, limit: Int): List<SearchResult> = synchronized(pages + pageMeta) { | ||
| data class Hit(val url: String, val score: Int) | ||
|
|
||
| val urlMatches = pages.asSequence().map { | ||
|
|
@@ -84,7 +86,7 @@ class InMemoryHistoryStorage : HistoryStorage { | |
| // TODO exclude non-matching results entirely? Score that implies complete mismatch. | ||
| matchedUrls.asSequence().sortedBy { it.value }.map { | ||
| SearchResult(id = it.key, score = maxScore - it.value, url = it.key, title = pageMeta[it.key]?.title) | ||
| }.toList() | ||
| }.take(limit).toList() | ||
| } | ||
|
|
||
| // Borrowed from https://gist.github.com/ademar111190/34d3de41308389a0d0d8 | ||
|
|
@@ -115,4 +117,8 @@ class InMemoryHistoryStorage : HistoryStorage { | |
|
|
||
| return cost[lhsLength - 1] | ||
| } | ||
|
|
||
| override fun cleanup() { | ||
| // GC will take care of our internal data structures, so there's nothing to do here. | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now we call
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be blocking?