зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1874915 - Vendored AppServices with uniffied webext storage component r=markh
Differential Revision: https://phabricator.services.mozilla.com/D199392
This commit is contained in:
Родитель
f582455208
Коммит
4129c49cc4
|
@ -55,9 +55,9 @@ git = "https://github.com/mozilla-spidermonkey/jsparagus"
|
|||
rev = "61f399c53a641ebd3077c1f39f054f6d396a633c"
|
||||
replace-with = "vendored-sources"
|
||||
|
||||
[source."git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5"]
|
||||
[source."git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"]
|
||||
git = "https://github.com/mozilla/application-services"
|
||||
rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
replace-with = "vendored-sources"
|
||||
|
||||
[source."git+https://github.com/mozilla/audioipc?rev=8b391135f9421dc5ab0c45f646c21651a906ce7f"]
|
||||
|
|
|
@ -1572,7 +1572,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "error-support"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"error-support-macros",
|
||||
"lazy_static",
|
||||
|
@ -1584,7 +1584,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "error-support-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -2798,7 +2798,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "interrupt-support"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
|
@ -3975,7 +3975,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "nss_build_common"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
|
||||
[[package]]
|
||||
name = "nsstring"
|
||||
|
@ -4646,7 +4646,7 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
|
|||
[[package]]
|
||||
name = "remote_settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
"serde",
|
||||
|
@ -5176,7 +5176,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "sql-support"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"ffi-support",
|
||||
"interrupt-support",
|
||||
|
@ -5357,7 +5357,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
|||
[[package]]
|
||||
name = "suggest"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
@ -5404,7 +5404,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "sync-guid"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"base64 0.21.3",
|
||||
"rand",
|
||||
|
@ -5415,7 +5415,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "sync15"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"error-support",
|
||||
|
@ -5447,7 +5447,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "tabs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"error-support",
|
||||
|
@ -6089,7 +6089,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|||
[[package]]
|
||||
name = "viaduct"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"ffi-support",
|
||||
"log",
|
||||
|
@ -6235,7 +6235,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "webext-storage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=63a6260c14847c21c5a1fa3003efaf0114a3e4e5#63a6260c14847c21c5a1fa3003efaf0114a3e4e5"
|
||||
source = "git+https://github.com/mozilla/application-services?rev=9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253#9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"error-support",
|
||||
|
@ -6253,6 +6253,7 @@ dependencies = [
|
|||
"sync-guid",
|
||||
"sync15",
|
||||
"thiserror",
|
||||
"uniffi",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -206,13 +206,13 @@ warp = { git = "https://github.com/seanmonstar/warp", rev = "9d081461ae1167eb321
|
|||
malloc_size_of_derive = { path = "xpcom/rust/malloc_size_of_derive" }
|
||||
|
||||
# application-services overrides to make updating them all simpler.
|
||||
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
sql-support = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
suggest = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
sync15 = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
tabs = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
viaduct = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "63a6260c14847c21c5a1fa3003efaf0114a3e4e5" }
|
||||
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
sql-support = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
suggest = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
sync15 = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
tabs = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
viaduct = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "9d1ab279d2aa31e4c6c80dd1ee0baf9345e26253" }
|
||||
|
||||
# Patch mio 0.8.8 to use windows-sys 0.52 (backport https://github.com/tokio-rs/mio/commit/eea9e3e0c469480e5c59c01e6c3c7e5fd88f0848)
|
||||
mio_0_8 = { package = "mio", git = "https://github.com/glandium/mio", rev = "9a2ef335c366044ffe73b1c4acabe50a1daefe05" }
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"cf73fe7b6066cb2ccccb0939f19b14d4e27d9cfdc20c9e527de3210029f2ee6f","README.md":"8030b4a314b1be31ba018ac12c3b586bb736db5307c3c395f2857fffe0130322","android/build.gradle":"200fe9fcf26477ae4e941dd1e702c43deae9fb0a7252569bd7352eac1771efbe","android/src/main/AndroidManifest.xml":"4f8b16fa6a03120ac810c6438a3a60294075414d92e06caa7e85388e389e5d17","build.rs":"c8d3c38c1208eea36224662b284d8daf3e7ad1b07d22d750524f3da1cc66ccca","src/errorsupport.udl":"e793034d01a2608298528051757f38405e006ee1abc4cf65dc6f18c53590ace8","src/handling.rs":"6e0568b18d426531cb2ae9967c8dd0d51ece5a065f68b15eeb308b995edaa167","src/lib.rs":"96ae3cc2c1077ae45442ace6b5b5311b86267d0b9067f3ff58396af30ccbbc07","src/macros.rs":"0d03f82fab20c96a182f941baf3fcf2a286b00fea871ee7fd8e339abc14f9522","src/redact.rs":"c9a4df1a87be68b15d583587bda941d4c60a1d0449e2d43ff99f3611a290a863","src/reporting.rs":"38efd24d86ba8facfb181cb27e8b698d2831db0afab85691ffda034a4dc68dfa","uniffi.toml":"644fe81c12fe3c01ee81e017ca3c00d0e611f014b7eade51aadaf208179a3450"},"package":null}
|
||||
{"files":{"Cargo.toml":"cf73fe7b6066cb2ccccb0939f19b14d4e27d9cfdc20c9e527de3210029f2ee6f","README.md":"8030b4a314b1be31ba018ac12c3b586bb736db5307c3c395f2857fffe0130322","android/build.gradle":"d4ecda8eebf9c1b3c7542ca86652a3e8c0d2dfc0ad7426e78447a35e4fb39eab","android/src/main/AndroidManifest.xml":"108cabbbdc93da70e1da3e60b74171580872017d996c20e37946c27aaa078031","build.rs":"c8d3c38c1208eea36224662b284d8daf3e7ad1b07d22d750524f3da1cc66ccca","src/errorsupport.udl":"e793034d01a2608298528051757f38405e006ee1abc4cf65dc6f18c53590ace8","src/handling.rs":"6e0568b18d426531cb2ae9967c8dd0d51ece5a065f68b15eeb308b995edaa167","src/lib.rs":"96ae3cc2c1077ae45442ace6b5b5311b86267d0b9067f3ff58396af30ccbbc07","src/macros.rs":"0d03f82fab20c96a182f941baf3fcf2a286b00fea871ee7fd8e339abc14f9522","src/redact.rs":"c9a4df1a87be68b15d583587bda941d4c60a1d0449e2d43ff99f3611a290a863","src/reporting.rs":"38efd24d86ba8facfb181cb27e8b698d2831db0afab85691ffda034a4dc68dfa","uniffi.toml":"644fe81c12fe3c01ee81e017ca3c00d0e611f014b7eade51aadaf208179a3450"},"package":null}
|
|
@ -1,7 +1,10 @@
|
|||
|
||||
apply from: "$rootDir/build-scripts/component-common.gradle"
|
||||
apply from: "$rootDir/publish.gradle"
|
||||
|
||||
android {
|
||||
namespace 'org.mozilla.appservices.errorsupport'
|
||||
}
|
||||
|
||||
ext.configureUniFFIBindgen("../src/errorsupport.udl")
|
||||
ext.dependsOnTheMegazord()
|
||||
ext.configurePublish()
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mozilla.appservices.errorsupport" />
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"7e5e03ee92f01a28fa398d77167619e5a55c73db083cc27b74c4d63ab44db173","README.md":"8d7457893194e255b87e5a2667ee25c87bd470f5338d7078506f866a67a3fdbd","build.rs":"78780c5cccfe22c3ff4198624b9e188559c437c3e6fa1c8bb66548eee6aa66bf","src/db.rs":"6d39e96bcdaa2b01dc662b3ed17b3a022246534b919b13be637e4646c3b9c1dd","src/error.rs":"f47763a1a5d228b446eb8f718433e49fdb1c7b304de1255891215144dddd7a43","src/keyword.rs":"988d0ab021c0df19cfd3c519df7d37f606bf984cd14d0efca4e5a7aff88344dd","src/lib.rs":"95ac0da8585ddfe712884e05ae53fd5fdf79564675a1070222e4a310a79959f4","src/pocket.rs":"c4dda43390d1c39dc795933596b3c1e4e282932cac6c69da53c6e05d39e9ef29","src/provider.rs":"8cecefb01d3c09c164d7334647e586c5407e14d0ee7ef99eea6e5095ec59586c","src/rs.rs":"e27ba1e8e6f5b470f1df8bef7f2a7d7edd8ff2c0c0aedead86206fb3019a5f97","src/schema.rs":"3135d28652e3f0df6670a3afa3bdf03d95039383720f1f0d77523c0f4faf1797","src/store.rs":"0d06ef245440028f7f25e7823846947dd9ef64a1ad60b91cc21b44885c91b50b","src/suggest.udl":"e129cc04665a8484572c57c87b4a1713a7600254bf4110e06a5fe0d4eb746bb5","src/suggestion.rs":"dfe7c02e11ea9a01d3fdd71eb2c83b1c1d1b830c34f76829a91a01cda44c38b8","src/yelp.rs":"3e3868873643feddfa99d360f6547aab2a9d7983929b90e7911559d685bff33f","uniffi.toml":"f26317442ddb5b3281245bef6e60ffcb78bb95d29fe4a351a56dbb88d4ec8aab"},"package":null}
|
||||
{"files":{"Cargo.toml":"7e5e03ee92f01a28fa398d77167619e5a55c73db083cc27b74c4d63ab44db173","README.md":"8d7457893194e255b87e5a2667ee25c87bd470f5338d7078506f866a67a3fdbd","build.rs":"78780c5cccfe22c3ff4198624b9e188559c437c3e6fa1c8bb66548eee6aa66bf","src/db.rs":"6d39e96bcdaa2b01dc662b3ed17b3a022246534b919b13be637e4646c3b9c1dd","src/error.rs":"f47763a1a5d228b446eb8f718433e49fdb1c7b304de1255891215144dddd7a43","src/keyword.rs":"988d0ab021c0df19cfd3c519df7d37f606bf984cd14d0efca4e5a7aff88344dd","src/lib.rs":"95ac0da8585ddfe712884e05ae53fd5fdf79564675a1070222e4a310a79959f4","src/pocket.rs":"c4dda43390d1c39dc795933596b3c1e4e282932cac6c69da53c6e05d39e9ef29","src/provider.rs":"8cecefb01d3c09c164d7334647e586c5407e14d0ee7ef99eea6e5095ec59586c","src/rs.rs":"1388ae7473d1d87f7eb731b1e34bd1d2f8ef844b7e0f09d7e3442cfc7d56286a","src/schema.rs":"3135d28652e3f0df6670a3afa3bdf03d95039383720f1f0d77523c0f4faf1797","src/store.rs":"6743136b02bcc3caec89ff1386a8ae5a5e89bab2bb095c60eb905f5c19735be9","src/suggest.udl":"e129cc04665a8484572c57c87b4a1713a7600254bf4110e06a5fe0d4eb746bb5","src/suggestion.rs":"dfe7c02e11ea9a01d3fdd71eb2c83b1c1d1b830c34f76829a91a01cda44c38b8","src/yelp.rs":"5d788854c3e1f9e5a2e55a8ecc4c5a10c1ad93ab84791535e4d88ec94602d615","uniffi.toml":"f26317442ddb5b3281245bef6e60ffcb78bb95d29fe4a351a56dbb88d4ec8aab"},"package":null}
|
|
@ -285,4 +285,6 @@ pub(crate) struct DownloadedYelpSuggestion {
|
|||
pub post_modifiers: Vec<String>,
|
||||
#[serde(rename = "locationSigns")]
|
||||
pub location_signs: Vec<DownloadedYelpLocationSign>,
|
||||
#[serde(rename = "yelpModifiers")]
|
||||
pub yelp_modifiers: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -1846,7 +1846,8 @@ mod tests {
|
|||
{ "keyword": "near", "needLocation": true },
|
||||
{ "keyword": "near by", "needLocation": false },
|
||||
{ "keyword": "near me", "needLocation": false },
|
||||
]
|
||||
],
|
||||
"yelpModifiers": ["yelp", "yelp keyword"],
|
||||
}),
|
||||
)?
|
||||
.with_icon("icon-2.png", "i-am-an-icon".as_bytes().into())
|
||||
|
@ -2765,6 +2766,97 @@ mod tests {
|
|||
[]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `yelp ramen`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "yelp ramen".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Yelp {
|
||||
url: "https://www.yelp.com/search?find_desc=ramen",
|
||||
title: "yelp ramen",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `yelp keyword ramen`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "yelp keyword ramen".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Yelp {
|
||||
url: "https://www.yelp.com/search?find_desc=ramen",
|
||||
title: "yelp keyword ramen",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `ramen in tokyo yelp`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "ramen in tokyo yelp".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Yelp {
|
||||
url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo",
|
||||
title: "ramen in tokyo yelp",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `ramen in tokyo yelp keyword`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "ramen in tokyo yelp keyword".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Yelp {
|
||||
url: "https://www.yelp.com/search?find_desc=ramen&find_loc=tokyo",
|
||||
title: "ramen in tokyo yelp keyword",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `yelp ramen yelp`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "yelp ramen yelp".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Yelp {
|
||||
url: "https://www.yelp.com/search?find_desc=ramen",
|
||||
title: "yelp ramen yelp",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
),
|
||||
(
|
||||
"keyword = `best yelp ramen`; Yelp only",
|
||||
SuggestionQuery {
|
||||
keyword: "best yelp ramen".into(),
|
||||
providers: vec![SuggestionProvider::Yelp],
|
||||
limit: None,
|
||||
},
|
||||
expect![[r#"
|
||||
[]
|
||||
"#]],
|
||||
),
|
||||
];
|
||||
for (what, query, expect) in table {
|
||||
expect.assert_debug_eq(
|
||||
|
|
|
@ -19,8 +19,9 @@ use crate::{
|
|||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
#[repr(u8)]
|
||||
enum Modifier {
|
||||
PreModifier = 0,
|
||||
PostModifier = 1,
|
||||
Pre = 0,
|
||||
Post = 1,
|
||||
Yelp = 2,
|
||||
}
|
||||
|
||||
impl ToSql for Modifier {
|
||||
|
@ -30,9 +31,9 @@ impl ToSql for Modifier {
|
|||
}
|
||||
|
||||
/// This module assumes like following query.
|
||||
/// "Pre-modifier? Subject Post-modifier? (Location-modifier | Location-sign Location?)?"
|
||||
/// "Yelp-modifier? Pre-modifier? Subject Post-modifier? (Location-modifier | Location-sign Location?)? Yelp-modifier?"
|
||||
/// For example, the query below is valid.
|
||||
/// "Best(Pre-modifier) Ramen(Subject) Delivery(Post-modifier) In(Location-sign) Tokyo(Location)"
|
||||
/// "Yelp (Yelp-modifier) Best(Pre-modifier) Ramen(Subject) Delivery(Post-modifier) In(Location-sign) Tokyo(Location)"
|
||||
/// Also, as everything except Subject is optional, "Ramen" will be also valid query.
|
||||
/// However, "Best Best Ramen" and "Ramen Best" is out of the above appearance order rule,
|
||||
/// parsing will be failed. Also, every words except Location needs to be registered in DB.
|
||||
|
@ -70,7 +71,7 @@ impl<'a> SuggestDao<'a> {
|
|||
"INSERT INTO yelp_modifiers(record_id, type, keyword) VALUES(:record_id, :type, :keyword)",
|
||||
named_params! {
|
||||
":record_id": record_id.as_str(),
|
||||
":type": Modifier::PreModifier,
|
||||
":type": Modifier::Pre,
|
||||
":keyword": keyword,
|
||||
},
|
||||
)?;
|
||||
|
@ -82,7 +83,19 @@ impl<'a> SuggestDao<'a> {
|
|||
"INSERT INTO yelp_modifiers(record_id, type, keyword) VALUES(:record_id, :type, :keyword)",
|
||||
named_params! {
|
||||
":record_id": record_id.as_str(),
|
||||
":type": Modifier::PostModifier,
|
||||
":type": Modifier::Post,
|
||||
":keyword": keyword,
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
for keyword in &suggestion.yelp_modifiers {
|
||||
self.scope.err_if_interrupted()?;
|
||||
self.conn.execute_cached(
|
||||
"INSERT INTO yelp_modifiers(record_id, type, keyword) VALUES(:record_id, :type, :keyword)",
|
||||
named_params! {
|
||||
":record_id": record_id.as_str(),
|
||||
":type": Modifier::Yelp,
|
||||
":keyword": keyword,
|
||||
},
|
||||
)?;
|
||||
|
@ -131,9 +144,13 @@ impl<'a> SuggestDao<'a> {
|
|||
return Ok(Some(builder.into()));
|
||||
}
|
||||
|
||||
// Find the yelp keyword modifier and remove them from the query.
|
||||
let (query_without_yelp_modifiers, _, _) =
|
||||
self.find_modifiers(query_string, Modifier::Yelp, Modifier::Yelp)?;
|
||||
|
||||
// Find the location sign and the location.
|
||||
let (query_without_location, location_sign, location, need_location) =
|
||||
self.find_location(query_string)?;
|
||||
self.find_location(&query_without_yelp_modifiers)?;
|
||||
|
||||
if let (Some(_), false) = (&location, need_location) {
|
||||
// The location sign does not need the specific location, but user is setting something.
|
||||
|
@ -147,7 +164,7 @@ impl<'a> SuggestDao<'a> {
|
|||
|
||||
// Find the modifiers.
|
||||
let (subject_candidate, pre_modifier, post_modifier) =
|
||||
self.find_modifiers(&query_without_location)?;
|
||||
self.find_modifiers(&query_without_location, Modifier::Pre, Modifier::Post)?;
|
||||
|
||||
if !self.is_subject(&subject_candidate)? {
|
||||
return Ok(None);
|
||||
|
@ -232,7 +249,12 @@ impl<'a> SuggestDao<'a> {
|
|||
/// Option<String>: Pre-modifier found in the yelp_modifiers table. If not found, returns None.
|
||||
/// Option<String>: Post-modifier found in the yelp_modifiers table. If not found, returns None.
|
||||
/// )
|
||||
fn find_modifiers(&self, query: &str) -> Result<(String, Option<String>, Option<String>)> {
|
||||
fn find_modifiers(
|
||||
&self,
|
||||
query: &str,
|
||||
pre_modifier_type: Modifier,
|
||||
post_modifier_type: Modifier,
|
||||
) -> Result<(String, Option<String>, Option<String>)> {
|
||||
if !query.contains(' ') {
|
||||
return Ok((query.to_string(), None, None));
|
||||
}
|
||||
|
@ -243,7 +265,7 @@ impl<'a> SuggestDao<'a> {
|
|||
for n in (1..=MAX_MODIFIER_WORDS_NUMBER).rev() {
|
||||
let mut candidate_chunks = words.chunks(n);
|
||||
let candidate = candidate_chunks.next().unwrap_or(&[""]).join(" ");
|
||||
if self.is_modifier(&candidate, Modifier::PreModifier)? {
|
||||
if self.is_modifier(&candidate, pre_modifier_type)? {
|
||||
pre_modifier = Some(candidate);
|
||||
break;
|
||||
}
|
||||
|
@ -253,22 +275,22 @@ impl<'a> SuggestDao<'a> {
|
|||
for n in (1..=MAX_MODIFIER_WORDS_NUMBER).rev() {
|
||||
let mut candidate_chunks = words.rchunks(n);
|
||||
let candidate = candidate_chunks.next().unwrap_or(&[""]).join(" ");
|
||||
if self.is_modifier(&candidate, Modifier::PostModifier)? {
|
||||
if self.is_modifier(&candidate, post_modifier_type)? {
|
||||
post_modifier = Some(candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let mut subject_candidate = query;
|
||||
let mut without_modifiers = query;
|
||||
if let Some(ref modifier) = pre_modifier {
|
||||
subject_candidate = &subject_candidate[modifier.len()..];
|
||||
without_modifiers = &without_modifiers[modifier.len()..];
|
||||
}
|
||||
if let Some(ref modifier) = post_modifier {
|
||||
subject_candidate = &subject_candidate[..subject_candidate.len() - modifier.len()];
|
||||
without_modifiers = &without_modifiers[..without_modifiers.len() - modifier.len()];
|
||||
}
|
||||
|
||||
Ok((
|
||||
subject_candidate.trim().to_string(),
|
||||
without_modifiers.trim().to_string(),
|
||||
pre_modifier,
|
||||
post_modifier,
|
||||
))
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"b2dea7e5dcb0a157bd4a2f52e05966840feca0e0739ffdb74d2e196e13537d0e","README.md":"1fd617294339930ee1ad5172377648b268cce0216fc3971facbfe7c6839e9ab1","build.rs":"2bea192a782a5ebe3d3ec0ca6dae2d51844eb7ad163a38a2a62fbfe6dd3c34d8","sql/create_schema.sql":"a17311a407ec10e033886b7125da4c8b84bc6d761f6b28edc9594de430e1d964","sql/create_sync_temp_tables.sql":"860ede362c94feb47d85522553fa2852f9bdb9f9b025d6438dd5dee3d4acd527","sql/tests/create_schema_v1.sql":"77cf0c90eaac3e1aea626537147e1b8ec349b68d6076c92fa7ae402aac613050","src/api.rs":"f3e6f8065089df06ef4b8ce093727154f96afb7ea168b083d942a30266e7dbf8","src/db.rs":"931459b6b71f96e91d588d2f568a2165adb3b6bd47eb98cdd5ed6a3526ed0a62","src/error.rs":"7857c368d72872c09b1dbf47e8b364e8e4b6007ff0798f8cab4a44ebe997955e","src/ffi.rs":"670088d3a13a7349e751489197a3bb123990db69fccf8b815831e9bf5901afc6","src/lib.rs":"324300143818ad545f7e85f9bb5dba03ca45e9002e110d824a3639b5213d8763","src/migration.rs":"8d92f82b2ba38e1039fd054c8c75078a6b896a0d3cdc1a52571456b25a32c9c3","src/schema.rs":"d8dd8f66cad71e3e369722734e0d5d16fd9423d5f6a5abba1854a27e1e814724","src/store.rs":"94f29198cba0b44d050ffd208bc0254fe3036a30ec574d36c9bf26d8b34d20c9","src/sync/bridge.rs":"d4a2dfe6c567d5afe24319e29b0056d38d92f3507793c96e874814bb289bfa73","src/sync/incoming.rs":"dd77c64e2ade4f39cba258decab6d3db8ad0b5f513aa018efbd56b9869a021d9","src/sync/mod.rs":"bd1bc5c428dfda6aee7efe53b6e74b8015da5129a303638a21ca8d63516e4061","src/sync/outgoing.rs":"dacb77b956f2546fd60a89367927a199d9b662b17201d0781145f7405b61fdce","src/sync/sync_tests.rs":"f3846ca7e463315ba9788826613b987ddcff7b21672ff257a98769ee94f4191a"},"package":null}
|
||||
{"files":{"Cargo.toml":"261161e1eea9bfa070c3025ce4398b5e53d9db44ca1539313e05b849723d625b","README.md":"1fd617294339930ee1ad5172377648b268cce0216fc3971facbfe7c6839e9ab1","android/build.gradle":"7c8ef7424dd3cc110cd96a0dca6fabef1b8479668bfc403902813efbf5187a83","android/src/main/AndroidManifest.xml":"0abfabd45a3a6415861c33532d4efcd658e9f78c30342e3e3e3570296a3cc8c2","android/src/test/java/mozilla/appservices/webextstorage/WebExtStorageTest.kt":"aff94a9798c7e91f8efd8e4329ead05ea3afa1d0579a78d86ab93a5d40a715b1","build.rs":"92f7d380f3d8fab1e6d80276915af57192e276321d132a5f800ea4520e9cb469","sql/create_schema.sql":"a17311a407ec10e033886b7125da4c8b84bc6d761f6b28edc9594de430e1d964","sql/create_sync_temp_tables.sql":"860ede362c94feb47d85522553fa2852f9bdb9f9b025d6438dd5dee3d4acd527","sql/tests/create_schema_v1.sql":"77cf0c90eaac3e1aea626537147e1b8ec349b68d6076c92fa7ae402aac613050","src/api.rs":"6fe362e4f437def2ad2249de385cca8f0d1d5d67679240351e9f57523fefe5e7","src/db.rs":"b95024c1d8f36a76a6f3098acea5a82bc49de144a24cdc280ed38e9bcc8e772b","src/error.rs":"6437e9a0edefac2707af85eef13bdbfcd53a84d7aa7859599155d10451d42361","src/ffi.rs":"f66a81393bebe7a4b7e7960cb426df106ff1f02bfebcaa6e335b4b8b56c5c936","src/lib.rs":"ab25e7c6ea67fb905fe6dad866c0d2c462b1e93bcff283db947513aeabbb2d73","src/migration.rs":"8d92f82b2ba38e1039fd054c8c75078a6b896a0d3cdc1a52571456b25a32c9c3","src/schema.rs":"d8dd8f66cad71e3e369722734e0d5d16fd9423d5f6a5abba1854a27e1e814724","src/store.rs":"d208689c46fb97cd2c60a0c610ba1998a7132fb50fffa2eefa1d6b169b7c34f0","src/sync/bridge.rs":"996de05beb2904f84b3cbfc9ef85c4844078fdb4867d9068390d496156bee614","src/sync/incoming.rs":"dd77c64e2ade4f39cba258decab6d3db8ad0b5f513aa018efbd56b9869a021d9","src/sync/mod.rs":"bd1bc5c428dfda6aee7efe53b6e74b8015da5129a303638a21ca8d63516e4061","src/sync/outgoing.rs":"dacb77b956f2546fd60a89367927a199d9b662b17201d0781145f7405b61fdce","src/sync/sync_tests.rs":"f3846ca7e463315ba9788826613b987ddcff7b21672ff257a98769ee94f4191a","src/webext-storage.udl":"0341d431ba837cf64ea210ef6157010c6664a0b5a194e89acb0414938636b391","uniffi.toml":"beeec89c2f877eb89be0090dc304dbc7c74e787385e7459bad78c6165bb66791"},"package":null}
|
|
@ -27,6 +27,7 @@ serde = "1"
|
|||
serde_derive = "1"
|
||||
serde_json = "1"
|
||||
thiserror = "1.0"
|
||||
uniffi = "0.25.2"
|
||||
|
||||
[dependencies.error-support]
|
||||
path = "../support/error"
|
||||
|
@ -75,5 +76,9 @@ path = "../support/sql"
|
|||
[build-dependencies.nss_build_common]
|
||||
path = "../support/rc_crypto/nss/nss_build_common"
|
||||
|
||||
[build-dependencies.uniffi]
|
||||
version = "0.25.2"
|
||||
features = ["build"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// TODO: Uncomment this code when webext-storage component is integrated in android
|
||||
|
||||
// apply from: "$rootDir/build-scripts/component-common.gradle"
|
||||
// apply from: "$rootDir/publish.gradle"
|
||||
|
||||
// dependencies {
|
||||
// // Part of the public API.
|
||||
// api project(':sync15')
|
||||
|
||||
// implementation "org.mozilla.telemetry:glean:$glean_version"
|
||||
// implementation "androidx.core:core-ktx:$androidx_core_version"
|
||||
|
||||
// testImplementation "androidx.test:core-ktx:$androidx_test_version"
|
||||
// testImplementation "androidx.test.ext:junit-ktx:$androidx_test_junit_version"
|
||||
// testImplementation "androidx.work:work-testing:$androidx_work_testing_version"
|
||||
// testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version"
|
||||
// }
|
||||
|
||||
|
||||
// ext.configureUniFFIBindgen("../src/webext-storage.udl")
|
||||
// ext.dependsOnTheMegazord()
|
||||
// ext.configurePublish()
|
|
@ -0,0 +1,2 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mozilla.appservices.webextstorage" />
|
76
third_party/rust/webext-storage/android/src/test/java/mozilla/appservices/webextstorage/WebExtStorageTest.kt
поставляемый
Normal file
76
third_party/rust/webext-storage/android/src/test/java/mozilla/appservices/webextstorage/WebExtStorageTest.kt
поставляемый
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
package mozilla.appservices.webextstorage
|
||||
|
||||
import mozilla.appservices.Megazord
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE)
|
||||
class WebExtStorageTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val dbFolder = TemporaryFolder()
|
||||
|
||||
fun createTestStore(): WebExtStorageStore {
|
||||
Megazord.init()
|
||||
val dbPath = dbFolder.newFile()
|
||||
return WebExtStorageStore(path = dbPath.absolutePath)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSet() {
|
||||
val store = createTestStore()
|
||||
val extId = "ab"
|
||||
val jsonString = """{"a":"a"}"""
|
||||
|
||||
store.set(extId, jsonString)
|
||||
val data = store.get(extId, "null")
|
||||
Assert.assertEquals(jsonString, data)
|
||||
store.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemove() {
|
||||
val store = createTestStore()
|
||||
val extId = "ab"
|
||||
val jsonString = """{"a":"a","b":"b"}"""
|
||||
|
||||
store.set(extId, jsonString)
|
||||
val change = store.remove("ab", """["b"]""").changes[0]
|
||||
|
||||
Assert.assertEquals(change.key, "b")
|
||||
Assert.assertEquals(change.oldValue, """"b"""")
|
||||
Assert.assertNull(change.newValue)
|
||||
store.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClear() {
|
||||
val store = createTestStore()
|
||||
val extId = "ab"
|
||||
val jsonString = """{"a":"a","b":"b"}"""
|
||||
|
||||
store.set(extId, jsonString)
|
||||
val result = store.clear(extId)
|
||||
|
||||
val firstChange = result.changes[0]
|
||||
Assert.assertEquals(firstChange.key, "a")
|
||||
Assert.assertEquals(firstChange.oldValue, """"a"""")
|
||||
Assert.assertNull(firstChange.newValue)
|
||||
|
||||
val secondChange = result.changes[1]
|
||||
Assert.assertEquals(secondChange.key, "b")
|
||||
Assert.assertEquals(secondChange.oldValue, """"b"""")
|
||||
Assert.assertNull(secondChange.newValue)
|
||||
|
||||
store.close()
|
||||
}
|
||||
}
|
|
@ -10,4 +10,6 @@ fn main() {
|
|||
|
||||
// If NSS_DIR isn't set, we don't really care, ignore the Err case.
|
||||
let _ = nss_build_common::link_nss();
|
||||
|
||||
uniffi::generate_scaffolding("./src/webext-storage.udl").unwrap();
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn save_to_db(tx: &Transaction<'_>, ext_id: &str, val: &StorageChangeOp) -> Resu
|
|||
StorageChangeOp::Set(v) => {
|
||||
let sv = v.to_string();
|
||||
if sv.len() > SYNC_QUOTA_BYTES {
|
||||
return Err(ErrorKind::QuotaError(QuotaReason::TotalBytes).into());
|
||||
return Err(Error::QuotaError(QuotaReason::TotalBytes));
|
||||
}
|
||||
sv
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ pub struct StorageValueChange {
|
|||
// be a plain vec
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct StorageChanges {
|
||||
changes: Vec<StorageValueChange>,
|
||||
pub changes: Vec<StorageValueChange>,
|
||||
}
|
||||
|
||||
impl StorageChanges {
|
||||
|
@ -167,7 +167,7 @@ impl StorageChanges {
|
|||
|
||||
// and it serializes as a map.
|
||||
impl Serialize for StorageChanges {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
|
@ -205,12 +205,12 @@ pub fn set(tx: &Transaction<'_>, ext_id: &str, val: JsonValue) -> Result<Storage
|
|||
for (k, v) in val_map.into_iter() {
|
||||
let old_value = current.remove(&k);
|
||||
if current.len() >= SYNC_MAX_ITEMS {
|
||||
return Err(ErrorKind::QuotaError(QuotaReason::MaxItems).into());
|
||||
return Err(Error::QuotaError(QuotaReason::MaxItems));
|
||||
}
|
||||
// Reading the chrome docs literally re the quota, the length of the key
|
||||
// is just the string len, but the value is the json val, as bytes
|
||||
if get_quota_size_of(&k, &v) > SYNC_QUOTA_BYTES_PER_ITEM {
|
||||
return Err(ErrorKind::QuotaError(QuotaReason::ItemBytes).into());
|
||||
return Err(Error::QuotaError(QuotaReason::ItemBytes));
|
||||
}
|
||||
let change = StorageValueChange {
|
||||
key: k.clone(),
|
||||
|
@ -610,8 +610,8 @@ mod tests {
|
|||
)?;
|
||||
}
|
||||
let e = set(&tx, ext_id, json!({"another": "another"})).unwrap_err();
|
||||
match e.kind() {
|
||||
ErrorKind::QuotaError(QuotaReason::MaxItems) => {}
|
||||
match e {
|
||||
Error::QuotaError(QuotaReason::MaxItems) => {}
|
||||
_ => panic!("unexpected error type"),
|
||||
};
|
||||
Ok(())
|
||||
|
@ -636,8 +636,8 @@ mod tests {
|
|||
|
||||
// Key length does push it over.
|
||||
let e = set(&tx, ext_id, json!({ "xxxx": val })).unwrap_err();
|
||||
match e.kind() {
|
||||
ErrorKind::QuotaError(QuotaReason::ItemBytes) => {}
|
||||
match e {
|
||||
Error::QuotaError(QuotaReason::ItemBytes) => {}
|
||||
_ => panic!("unexpected error type"),
|
||||
};
|
||||
Ok(())
|
||||
|
@ -659,8 +659,8 @@ mod tests {
|
|||
|
||||
// Adding more data fails.
|
||||
let e = set(&tx, ext_id, json!({ "y": "newvalue" })).unwrap_err();
|
||||
match e.kind() {
|
||||
ErrorKind::QuotaError(QuotaReason::TotalBytes) => {}
|
||||
match e {
|
||||
Error::QuotaError(QuotaReason::TotalBytes) => {}
|
||||
_ => panic!("unexpected error type"),
|
||||
};
|
||||
|
||||
|
|
|
@ -214,11 +214,11 @@ pub fn ensure_url_path(p: impl AsRef<Path>) -> Result<Url> {
|
|||
if u.scheme() == "file" {
|
||||
Ok(u)
|
||||
} else {
|
||||
Err(ErrorKind::IllegalDatabasePath(p.as_ref().to_owned()).into())
|
||||
Err(Error::IllegalDatabasePath(p.as_ref().to_owned()))
|
||||
}
|
||||
} else {
|
||||
let p = p.as_ref();
|
||||
let u = Url::from_file_path(p).map_err(|_| ErrorKind::IllegalDatabasePath(p.to_owned()))?;
|
||||
let u = Url::from_file_path(p).map_err(|_| Error::IllegalDatabasePath(p.to_owned()))?;
|
||||
Ok(u)
|
||||
}
|
||||
}
|
||||
|
@ -243,11 +243,11 @@ fn normalize_path(p: impl AsRef<Path>) -> Result<PathBuf> {
|
|||
// parent directory, etc.
|
||||
let file_name = path
|
||||
.file_name()
|
||||
.ok_or_else(|| ErrorKind::IllegalDatabasePath(path.clone()))?;
|
||||
.ok_or_else(|| Error::IllegalDatabasePath(path.clone()))?;
|
||||
|
||||
let parent = path
|
||||
.parent()
|
||||
.ok_or_else(|| ErrorKind::IllegalDatabasePath(path.clone()))?;
|
||||
.ok_or_else(|| Error::IllegalDatabasePath(path.clone()))?;
|
||||
|
||||
let mut canonical = parent.canonicalize()?;
|
||||
canonical.push(file_name);
|
||||
|
|
|
@ -2,17 +2,46 @@
|
|||
* 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/. */
|
||||
|
||||
use error_support::{ErrorHandling, GetErrorHandling};
|
||||
use interrupt_support::Interrupted;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Result enum used by all implementation functions in this crate.
|
||||
/// These wll be automagically turned into `WebExtStorageApiError` at the
|
||||
/// FFI layer.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum QuotaReason {
|
||||
TotalBytes,
|
||||
ItemBytes,
|
||||
MaxItems,
|
||||
}
|
||||
|
||||
impl fmt::Display for QuotaReason {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
QuotaReason::ItemBytes => write!(f, "ItemBytes"),
|
||||
QuotaReason::MaxItems => write!(f, "MaxItems"),
|
||||
QuotaReason::TotalBytes => write!(f, "TotalBytes"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ErrorKind {
|
||||
pub enum WebExtStorageApiError {
|
||||
#[error("Unexpected webext-storage error: {reason}")]
|
||||
UnexpectedError { reason: String },
|
||||
|
||||
#[error("Error parsing JSON data: {reason}")]
|
||||
JsonError { reason: String },
|
||||
|
||||
#[error("Quota exceeded: {reason}")]
|
||||
QuotaError { reason: QuotaReason },
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Quota exceeded: {0:?}")]
|
||||
QuotaError(QuotaReason),
|
||||
|
||||
|
@ -60,13 +89,57 @@ pub enum ErrorKind {
|
|||
SyncError(String),
|
||||
}
|
||||
|
||||
error_support::define_error! {
|
||||
ErrorKind {
|
||||
(JsonError, serde_json::Error),
|
||||
(SqlError, rusqlite::Error),
|
||||
(IoError, std::io::Error),
|
||||
(InterruptedError, Interrupted),
|
||||
(Utf8Error, std::str::Utf8Error),
|
||||
(OpenDatabaseError, sql_support::open_database::Error),
|
||||
impl GetErrorHandling for Error {
|
||||
type ExternalError = WebExtStorageApiError;
|
||||
|
||||
fn get_error_handling(&self) -> ErrorHandling<Self::ExternalError> {
|
||||
match self {
|
||||
Error::QuotaError(reason) => {
|
||||
log::info!("webext-storage-quota-error");
|
||||
ErrorHandling::convert(WebExtStorageApiError::QuotaError { reason: *reason })
|
||||
}
|
||||
Error::JsonError(e) => {
|
||||
log::info!("webext-storage-json-error");
|
||||
ErrorHandling::convert(WebExtStorageApiError::JsonError {
|
||||
reason: e.to_string(),
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
log::info!("webext-storage-unexpected-error");
|
||||
ErrorHandling::convert(WebExtStorageApiError::UnexpectedError {
|
||||
reason: self.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for WebExtStorageApiError {
|
||||
fn from(err: Error) -> WebExtStorageApiError {
|
||||
match err {
|
||||
Error::JsonError(e) => WebExtStorageApiError::JsonError {
|
||||
reason: e.to_string(),
|
||||
},
|
||||
Error::QuotaError(reason) => WebExtStorageApiError::QuotaError { reason },
|
||||
_ => WebExtStorageApiError::UnexpectedError {
|
||||
reason: err.to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rusqlite::Error> for WebExtStorageApiError {
|
||||
fn from(value: rusqlite::Error) -> Self {
|
||||
WebExtStorageApiError::UnexpectedError {
|
||||
reason: value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for WebExtStorageApiError {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
WebExtStorageApiError::JsonError {
|
||||
reason: value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
/// a trait in `ffi_support` for a type in `webext_storage`).
|
||||
use ffi_support::{ErrorCode, ExternError};
|
||||
|
||||
use crate::error::{Error, ErrorKind, QuotaReason};
|
||||
use crate::error::{Error, QuotaReason};
|
||||
|
||||
mod error_codes {
|
||||
/// An unexpected error occurred which likely cannot be meaningfully handled
|
||||
|
@ -34,13 +34,13 @@ mod error_codes {
|
|||
|
||||
impl From<Error> for ExternError {
|
||||
fn from(err: Error) -> ExternError {
|
||||
let code = ErrorCode::new(match err.kind() {
|
||||
ErrorKind::JsonError(_) => error_codes::INVALID_JSON,
|
||||
ErrorKind::QuotaError(QuotaReason::TotalBytes) => {
|
||||
error_codes::QUOTA_TOTAL_BYTES_EXCEEDED
|
||||
}
|
||||
ErrorKind::QuotaError(QuotaReason::ItemBytes) => error_codes::QUOTA_ITEM_BYTES_EXCEEDED,
|
||||
ErrorKind::QuotaError(QuotaReason::MaxItems) => error_codes::QUOTA_MAX_ITEMS_EXCEEDED,
|
||||
let code = ErrorCode::new(match &err {
|
||||
Error::JsonError(_) => error_codes::INVALID_JSON,
|
||||
Error::QuotaError(reason) => match reason {
|
||||
QuotaReason::ItemBytes => error_codes::QUOTA_ITEM_BYTES_EXCEEDED,
|
||||
QuotaReason::MaxItems => error_codes::QUOTA_MAX_ITEMS_EXCEEDED,
|
||||
QuotaReason::TotalBytes => error_codes::QUOTA_TOTAL_BYTES_EXCEEDED,
|
||||
},
|
||||
_ => error_codes::UNEXPECTED,
|
||||
});
|
||||
ExternError::new_error(code, err.to_string())
|
||||
|
|
|
@ -23,4 +23,22 @@ pub use api::SYNC_MAX_ITEMS;
|
|||
pub use api::SYNC_QUOTA_BYTES;
|
||||
pub use api::SYNC_QUOTA_BYTES_PER_ITEM;
|
||||
|
||||
pub use crate::error::{QuotaReason, WebExtStorageApiError};
|
||||
pub use crate::store::WebExtStorageStore;
|
||||
pub use api::UsageInfo;
|
||||
pub use api::{StorageChanges, StorageValueChange};
|
||||
|
||||
uniffi::include_scaffolding!("webext-storage");
|
||||
|
||||
use serde_json::Value as JsonValue;
|
||||
impl UniffiCustomTypeConverter for JsonValue {
|
||||
type Builtin = String;
|
||||
|
||||
fn into_custom(val: Self::Builtin) -> uniffi::Result<JsonValue> {
|
||||
Ok(serde_json::from_str(val.as_str()).unwrap())
|
||||
}
|
||||
|
||||
fn from_custom(obj: Self) -> Self::Builtin {
|
||||
obj.to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ use serde_json::Value as JsonValue;
|
|||
/// Note that our Db implementation is behind an Arc<> because we share that
|
||||
/// connection with our sync engines - ie, these engines also hold an Arc<>
|
||||
/// around the same object.
|
||||
pub struct Store {
|
||||
pub struct WebExtStorageStore {
|
||||
db: Arc<ThreadSafeStorageDb>,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
impl WebExtStorageStore {
|
||||
/// Creates a store backed by a database at `db_path`. The path can be a
|
||||
/// file path or `file:` URI.
|
||||
pub fn new(db_path: impl AsRef<Path>) -> Result<Self> {
|
||||
|
@ -153,7 +153,7 @@ impl Store {
|
|||
// connections, and the next rusqlite version will not panic anyway.
|
||||
// So this-is-fine.jpg
|
||||
log::warn!("Attempting to close a store while other DB references exist.");
|
||||
return Err(ErrorKind::OtherConnectionReferencesExist.into());
|
||||
return Err(Error::OtherConnectionReferencesExist);
|
||||
}
|
||||
};
|
||||
// consume the mutex and get back the inner.
|
||||
|
@ -207,11 +207,11 @@ pub mod test {
|
|||
fn test_send() {
|
||||
fn ensure_send<T: Send>() {}
|
||||
// Compile will fail if not send.
|
||||
ensure_send::<Store>();
|
||||
ensure_send::<WebExtStorageStore>();
|
||||
}
|
||||
|
||||
pub fn new_mem_store() -> Store {
|
||||
Store {
|
||||
pub fn new_mem_store() -> WebExtStorageStore {
|
||||
WebExtStorageStore {
|
||||
db: Arc::new(ThreadSafeStorageDb::new(crate::db::test::new_mem_db())),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ impl BridgedEngine {
|
|||
fn thread_safe_storage_db(&self) -> Result<Arc<ThreadSafeStorageDb>> {
|
||||
self.db
|
||||
.upgrade()
|
||||
.ok_or_else(|| crate::error::ErrorKind::DatabaseConnectionClosed.into())
|
||||
.ok_or_else(|| crate::error::Error::DatabaseConnectionClosed.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ impl sync15::engine::BridgedEngine for BridgedEngine {
|
|||
|
||||
impl From<anyhow::Error> for crate::error::Error {
|
||||
fn from(value: anyhow::Error) -> Self {
|
||||
crate::error::ErrorKind::SyncError(value.to_string()).into()
|
||||
crate::error::Error::SyncError(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* 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/. */
|
||||
|
||||
[Custom]
|
||||
typedef string JsonValue;
|
||||
|
||||
namespace webextstorage {
|
||||
|
||||
};
|
||||
|
||||
enum QuotaReason {
|
||||
"TotalBytes",
|
||||
"ItemBytes",
|
||||
"MaxItems",
|
||||
};
|
||||
|
||||
[Error]
|
||||
interface WebExtStorageApiError {
|
||||
UnexpectedError(string reason);
|
||||
JsonError(string reason);
|
||||
QuotaError(QuotaReason reason);
|
||||
};
|
||||
|
||||
dictionary StorageValueChange {
|
||||
string key;
|
||||
JsonValue? old_value;
|
||||
JsonValue? new_value;
|
||||
};
|
||||
|
||||
dictionary StorageChanges {
|
||||
sequence<StorageValueChange> changes;
|
||||
};
|
||||
|
||||
interface WebExtStorageStore {
|
||||
[Throws=WebExtStorageApiError]
|
||||
constructor(string path);
|
||||
|
||||
[Throws=WebExtStorageApiError]
|
||||
StorageChanges set([ByRef] string ext_id, JsonValue val);
|
||||
|
||||
[Throws=WebExtStorageApiError]
|
||||
JsonValue get([ByRef] string ext_id, JsonValue keys);
|
||||
|
||||
[Throws=WebExtStorageApiError]
|
||||
StorageChanges remove([ByRef] string ext_id, JsonValue keys);
|
||||
|
||||
[Throws=WebExtStorageApiError]
|
||||
StorageChanges clear([ByRef] string ext_id);
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
[bindings.kotlin]
|
||||
package_name = "mozilla.appservices.webextstorage"
|
||||
cdylib_name = "megazord"
|
|
@ -12,7 +12,6 @@ use nserror::{
|
|||
};
|
||||
use serde_json::error::Error as JsonError;
|
||||
use webext_storage::error::Error as WebextStorageError;
|
||||
use webext_storage::error::ErrorKind as WebextStorageErrorKind;
|
||||
|
||||
/// A specialized `Result` type for extension storage operations.
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
@ -84,8 +83,8 @@ impl From<Error> for nsresult {
|
|||
fn from(error: Error) -> nsresult {
|
||||
match error {
|
||||
Error::Nsresult(result) => result,
|
||||
Error::WebextStorage(e) => match e.kind() {
|
||||
WebextStorageErrorKind::QuotaError(_) => NS_ERROR_DOM_QUOTA_EXCEEDED_ERR,
|
||||
Error::WebextStorage(e) => match e {
|
||||
WebextStorageError::QuotaError(_) => NS_ERROR_DOM_QUOTA_EXCEEDED_ERR,
|
||||
_ => NS_ERROR_FAILURE,
|
||||
},
|
||||
Error::MigrationFailed(_) => NS_ERROR_CANNOT_CONVERT_DATA,
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{fs::remove_file, path::PathBuf, sync::Arc};
|
|||
|
||||
use interrupt_support::SqlInterruptHandle;
|
||||
use once_cell::sync::OnceCell;
|
||||
use webext_storage::store::Store;
|
||||
use webext_storage::store::WebExtStorageStore as Store;
|
||||
|
||||
use crate::error::{self, Error};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче