From 202df02549a5dc0e9a64f0afcd6c9f8df8789e6d Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Tue, 1 Feb 2022 16:45:23 +1100 Subject: [PATCH] Add is_remote flag to HistoryVisitInfo --- components/places/src/ffi.rs | 1 + components/places/src/places.udl | 1 + components/places/src/storage/history.rs | 15 ++++++++++----- components/places/src/storage/mod.rs | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/places/src/ffi.rs b/components/places/src/ffi.rs index 8426bc613d..c82c930f51 100644 --- a/components/places/src/ffi.rs +++ b/components/places/src/ffi.rs @@ -521,6 +521,7 @@ pub struct HistoryVisitInfo { pub visit_type: VisitTransition, pub is_hidden: bool, pub preview_image_url: Option, + pub is_remote: bool, } #[derive(Clone, PartialEq)] pub struct HistoryVisitInfosWithBound { diff --git a/components/places/src/places.udl b/components/places/src/places.udl index a8d2c62d94..fd39be0f3d 100644 --- a/components/places/src/places.udl +++ b/components/places/src/places.udl @@ -278,6 +278,7 @@ dictionary HistoryVisitInfo { VisitTransition visit_type; boolean is_hidden; Url? preview_image_url; + boolean is_remote; }; dictionary HistoryVisitInfosWithBound { diff --git a/components/places/src/storage/history.rs b/components/places/src/storage/history.rs index cb4303203a..073ab26213 100644 --- a/components/places/src/storage/history.rs +++ b/components/places/src/storage/history.rs @@ -1263,7 +1263,8 @@ pub fn get_visit_infos( ) -> Result> { let allowed_types = exclude_types.complement(); let infos = db.query_rows_and_then_named_cached( - "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url + "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url, + v.is_local FROM moz_places h JOIN moz_historyvisits v ON h.id = v.place_id @@ -1308,7 +1309,8 @@ pub fn get_visit_page( ) -> Result> { let allowed_types = exclude_types.complement(); let infos = db.query_rows_and_then_named_cached( - "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url + "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url, + v.is_local FROM moz_places h JOIN moz_historyvisits v ON h.id = v.place_id @@ -1336,7 +1338,8 @@ pub fn get_visit_page_with_bound( ) -> Result { let allowed_types = exclude_types.complement(); let infos = db.query_rows_and_then_named_cached( - "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url + "SELECT h.url, h.title, v.visit_date, v.visit_type, h.hidden, h.preview_image_url, + v.is_local FROM moz_places h JOIN moz_historyvisits v ON h.id = v.place_id @@ -2897,7 +2900,7 @@ mod tests { let now: Timestamp = SystemTime::now().into(); let now_u64 = now.0; let now_i64 = now.0 as i64; - // (url, when, is_remote, (expected_always, expected_only_local) + // (url, title, when, is_remote, (expected_always, expected_only_local) let to_add = [ ( "https://www.example.com/0", @@ -2910,7 +2913,7 @@ mod tests { "https://www.example.com/1", "older 1", now_u64 - 200_100, - false, + true, (true, false), ), ( @@ -3003,7 +3006,9 @@ mod tests { .unwrap(); let infos = infos_with_bound.infos; assert_eq!(infos[0].title.as_ref().unwrap().as_str(), "older 1",); + assert!(infos[0].is_remote); // "older 1" is remote assert_eq!(infos[1].title.as_ref().unwrap().as_str(), "older 2",); + assert!(!infos[1].is_remote); // "older 2" is local assert_eq!(infos_with_bound.bound, now_i64 - 200_200,); assert_eq!(infos_with_bound.offset, 1,); diff --git a/components/places/src/storage/mod.rs b/components/places/src/storage/mod.rs index 7416550e06..50eadbebb1 100644 --- a/components/places/src/storage/mod.rs +++ b/components/places/src/storage/mod.rs @@ -184,7 +184,7 @@ fn new_page_info(db: &PlacesDb, url: &Url, new_guid: Option) -> Result } impl HistoryVisitInfo { - pub(crate) fn from_row(row: &rusqlite::Row<'_>) -> Result { + fn from_row(row: &rusqlite::Row<'_>) -> Result { let visit_type = VisitTransition::from_primitive(row.get::<_, u8>("visit_type")?) // Do we have an existing error we use for this? For now they // probably don't care too much about VisitTransition, so this @@ -203,6 +203,7 @@ impl HistoryVisitInfo { Some(s) => Some(Url::parse(&s)?), None => None, }, + is_remote: !row.get("is_local")?, }) } }