Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/places/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "places"
edition = "2018"
version = "0.1.0"
authors = []

Expand Down
60 changes: 18 additions & 42 deletions components/places/examples/autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,17 @@
* 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/. */

extern crate places;

#[macro_use]
extern crate log;
extern crate env_logger;
#[macro_use]
extern crate failure;
extern crate rusqlite;

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate url;
#[macro_use]
extern crate clap;
extern crate find_places_db;
extern crate sql_support;
extern crate tempfile;
use clap::value_t;
use failure::bail;
use places::{VisitObservation, VisitTransition};
use serde_derive::*;
use sql_support::ConnExt;

#[cfg(not(windows))]
extern crate termion;

extern crate rand;

use std::io::prelude::*;

use url::Url;

use places::{VisitObservation, VisitTransition};

use std::{
fs,
path::{Path, PathBuf},
};
use url::Url;

type Result<T> = std::result::Result<T, failure::Error>;

Expand Down Expand Up @@ -181,9 +156,10 @@ fn import_places(
(ps, vs)
};

info!(
log::info!(
"Importing {} visits across {} places!",
place_count, visit_count
place_count,
visit_count
);
let mut stmt = old.prepare(
"
Expand Down Expand Up @@ -255,7 +231,7 @@ fn import_places(
println!("Finished processing records");
println!("Committing....");
tx.commit()?;
info!("Finished import!");
log::info!("Finished import!");
Ok(())
}

Expand Down Expand Up @@ -369,7 +345,7 @@ mod autocomplete {
}
Err(e) => {
// TODO: this is likely not to go very well since we're in raw mode...
error!("Got error doing autocomplete: {:?}", e);
log::error!("Got error doing autocomplete: {:?}", e);
panic!("Got error doing autocomplete: {:?}", e);
// return Err(e.into());
}
Expand Down Expand Up @@ -619,11 +595,11 @@ mod autocomplete {
}
}
Key::Ctrl('a') | Key::Home => {
write!(stdout, "{}", Goto(3, 2));
write!(stdout, "{}", Goto(3, 2))?;
cursor_idx = 0;
}
Key::Ctrl('e') | Key::End => {
write!(stdout, "{}", Goto(3 + query_str.len() as u16, 2));
write!(stdout, "{}", Goto(3 + query_str.len() as u16, 2))?;
cursor_idx = query_str.len();
}
Key::Ctrl('u') => {
Expand Down Expand Up @@ -832,14 +808,14 @@ fn main() -> Result<()> {
.unwrap_or(0.1),
};
let import_source = if import_places_arg == "auto" {
info!("Automatically locating largest places DB in your profile(s)");
log::info!("Automatically locating largest places DB in your profile(s)");
let profile_info = if let Some(info) = find_places_db::get_largest_places_db()? {
info
} else {
error!("Failed to locate your firefox profile!");
log::error!("Failed to locate your firefox profile!");
bail!("--import-places=auto specified, but couldn't find a `places.sqlite`");
};
info!(
log::info!(
"Using a {} places.sqlite from profile '{}' (places path = {:?})",
profile_info.friendly_db_size(),
profile_info.profile_name,
Expand Down Expand Up @@ -872,17 +848,17 @@ fn main() -> Result<()> {
}

if let Some(observations_json) = matches.value_of("import_observations") {
info!("Importing observations from {}", observations_json);
log::info!("Importing observations from {}", observations_json);
let observations: Vec<SerializedObservation> = read_json_file(observations_json)?;
let num_observations = observations.len();
info!("Found {} observations", num_observations);
log::info!("Found {} observations", num_observations);
let mut counter = 0;
for obs in observations {
let visit = obs.into_visit()?;
places::apply_observation(&mut conn, visit)?;
counter += 1;
if (counter % 1000) == 0 {
trace!("Importing observations {} / {}", counter, num_observations);
log::trace!("Importing observations {} / {}", counter, num_observations);
}
}
}
Expand Down
38 changes: 9 additions & 29 deletions components/places/examples/sync_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,7 @@
* 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/. */

extern crate fxa_client;
extern crate sync15_adapter;
extern crate url;

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

extern crate rusqlite;

extern crate clap;

#[macro_use]
extern crate log;
extern crate env_logger;
extern crate failure;

extern crate places;

use failure::Fail;

use fxa_client::{AccessTokenInfo, Config, FirefoxAccount};
use places::history_sync::store::HistoryStore;
use places::PlacesDb;
Expand Down Expand Up @@ -107,9 +86,10 @@ fn main() -> Result<()> {
.expect("Encryption key is not optional");

// Lets not log the encryption key, it's just not a good habit to be in.
debug!(
log::debug!(
"Using credential file = {:?}, db = {:?}",
cred_file, db_path
cred_file,
db_path
);

// TODO: allow users to use stage/etc.
Expand Down Expand Up @@ -137,22 +117,22 @@ fn main() -> Result<()> {
let store = HistoryStore::new(&db);

if matches.is_present("wipe-remote") {
info!("Wiping remote");
log::info!("Wiping remote");
let client = Sync15StorageClient::new(client_init.clone())?;
client.wipe_all_remote()?;
}

if matches.is_present("reset") {
info!("Resetting");
log::info!("Resetting");
store.reset()?;
}

info!("Syncing!");
log::info!("Syncing!");
if let Err(e) = store.sync(&client_init, &root_sync_key) {
warn!("Sync failed! {}", e);
warn!("BT: {:?}", e.backtrace());
log::warn!("Sync failed! {}", e);
log::warn!("BT: {:?}", e.backtrace());
} else {
info!("Sync was successful!");
log::info!("Sync was successful!");
}
println!("Exiting (bye!)");
Ok(())
Expand Down
1 change: 1 addition & 0 deletions components/places/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "places-ffi"
edition = "2018"
version = "0.1.0"
authors = ["Thom Chiovoloni <tchiovoloni@mozilla.com>"]

Expand Down
34 changes: 11 additions & 23 deletions components/places/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
* 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/. */

extern crate places;
extern crate rusqlite;
extern crate serde_json;
extern crate sync15_adapter;
extern crate url;

#[macro_use]
extern crate log;

#[cfg(target_os = "android")]
extern crate android_logger;

#[macro_use]
extern crate ffi_support;

use ffi_support::{call_with_result, rust_str_from_c, rust_string_from_c, ExternError};
use ffi_support::{
call_with_result, define_box_destructor, define_string_destructor, rust_str_from_c,
rust_string_from_c, ExternError,
};
use places::history_sync::store::HistoryStore;
use places::{storage, PlacesDb};
use std::os::raw::c_char;
Expand All @@ -36,7 +24,7 @@ fn logging_init() {
android_logger::Filter::default().with_min_level(log::Level::Trace),
Some("libplaces_ffi"),
);
debug!("Android logging should be hooked up!")
log::debug!("Android logging should be hooked up!")
}
}

Expand All @@ -51,7 +39,7 @@ pub unsafe extern "C" fn places_connection_new(
encryption_key: *const c_char,
error: &mut ExternError,
) -> *mut PlacesDb {
trace!("places_connection_new");
log::trace!("places_connection_new");
logging_init();
call_with_result(error, || {
let path = ffi_support::rust_string_from_c(db_path);
Expand All @@ -68,7 +56,7 @@ pub unsafe extern "C" fn places_note_observation(
json_observation: *const c_char,
error: &mut ExternError,
) {
trace!("places_note_observation");
log::trace!("places_note_observation");
call_with_result(error, || {
let json = ffi_support::rust_str_from_c(json_observation);
let visit: places::VisitObservation = serde_json::from_str(&json)?;
Expand All @@ -85,7 +73,7 @@ pub unsafe extern "C" fn places_query_autocomplete(
limit: u32,
error: &mut ExternError,
) -> *mut c_char {
trace!("places_query_autocomplete");
log::trace!("places_query_autocomplete");
call_with_result(error, || {
search_frecent(
conn,
Expand All @@ -103,7 +91,7 @@ pub unsafe extern "C" fn places_get_visited(
urls_json: *const c_char,
error: &mut ExternError,
) -> *mut c_char {
trace!("places_get_visited");
log::trace!("places_get_visited");
// This function has a dumb amount of overhead and copying...
call_with_result(error, || -> places::Result<String> {
let json = ffi_support::rust_str_from_c(urls_json);
Expand All @@ -127,7 +115,7 @@ pub extern "C" fn places_get_visited_urls_in_range(
include_remote: u8, // JNA has issues with bools...
error: &mut ExternError,
) -> *mut c_char {
trace!("places_get_visited_in_range");
log::trace!("places_get_visited_in_range");
call_with_result(error, || -> places::Result<String> {
let visited = storage::get_visited_urls(
conn,
Expand All @@ -149,7 +137,7 @@ pub unsafe extern "C" fn sync15_history_sync(
tokenserver_url: *const c_char,
error: &mut ExternError,
) {
trace!("sync15_history_sync");
log::trace!("sync15_history_sync");
call_with_result(error, || -> places::Result<()> {
// XXX - this is wrong - we kinda want this to be long-lived - the "Db"
// should own the store, but it's not part of the db.
Expand Down
13 changes: 6 additions & 7 deletions components/places/src/api/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* 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 url::Url;

use super::apply_observation;
use db::PlacesDb;
use error::*;
use observation::VisitObservation;
use types::*;
use crate::db::PlacesDb;
use crate::error::*;
use crate::observation::VisitObservation;
use crate::types::*;
use url::Url;

// This module can become, roughly: PlacesUtils.history()

Expand Down Expand Up @@ -182,7 +181,7 @@ pub fn visit_uri(
// EMBED visits are session-persistent and should not go through the database.
// They exist only to keep track of isVisited status during the session.
if transition == VisitTransition::Embed {
warn!("Embed visit, but in-memory storage of these isn't done yet");
log::warn!("Embed visit, but in-memory storage of these isn't done yet");
return Ok(());
}

Expand Down
15 changes: 7 additions & 8 deletions components/places/src/api/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* 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 db::PlacesDb;
use error::Result;
use rusqlite;
use crate::db::PlacesDb;
use crate::error::Result;
use serde_derive::*;
use url::Url;
use url_serde;

pub use match_impl::{MatchBehavior, SearchBehavior};
pub use crate::match_impl::{MatchBehavior, SearchBehavior};

#[derive(Debug, Clone)]
pub struct SearchParams {
Expand Down Expand Up @@ -519,9 +518,9 @@ impl<'query, 'conn> Suggestions<'query, 'conn> {
#[cfg(test)]
mod tests {
use super::*;
use observation::VisitObservation;
use storage::apply_observation;
use types::{Timestamp, VisitTransition};
use crate::observation::VisitObservation;
use crate::storage::apply_observation;
use crate::types::{Timestamp, VisitTransition};

#[test]
fn split() {
Expand Down
8 changes: 4 additions & 4 deletions components/places/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

pub mod history;
pub mod matcher;
use db::PlacesDb;
use error::Result;
use observation::VisitObservation;
use storage;
use crate::db::PlacesDb;
use crate::error::Result;
use crate::observation::VisitObservation;
use crate::storage;

pub fn apply_observation(conn: &mut PlacesDb, visit_obs: VisitObservation) -> Result<()> {
storage::apply_observation(conn, visit_obs)?;
Expand Down
Loading