mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Remove use of util::opts from storage_thread
This commit is contained in:
parent
1662e292d8
commit
8d919c5c1f
2 changed files with 15 additions and 14 deletions
|
@ -8,23 +8,22 @@ use resource_thread;
|
|||
use std::borrow::ToOwned;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use url::Url;
|
||||
use util::opts;
|
||||
use util::thread::spawn_named;
|
||||
|
||||
const QUOTA_SIZE_LIMIT: usize = 5 * 1024 * 1024;
|
||||
|
||||
pub trait StorageThreadFactory {
|
||||
fn new() -> Self;
|
||||
fn new(config_dir: Option<PathBuf>) -> Self;
|
||||
}
|
||||
|
||||
impl StorageThreadFactory for IpcSender<StorageThreadMsg> {
|
||||
/// Create a storage thread
|
||||
fn new() -> IpcSender<StorageThreadMsg> {
|
||||
fn new(config_dir: Option<PathBuf>) -> IpcSender<StorageThreadMsg> {
|
||||
let (chan, port) = ipc::channel().unwrap();
|
||||
spawn_named("StorageManager".to_owned(), move || {
|
||||
StorageManager::new(port).start();
|
||||
StorageManager::new(port, config_dir).start();
|
||||
});
|
||||
chan
|
||||
}
|
||||
|
@ -34,19 +33,22 @@ struct StorageManager {
|
|||
port: IpcReceiver<StorageThreadMsg>,
|
||||
session_data: HashMap<String, (usize, BTreeMap<String, String>)>,
|
||||
local_data: HashMap<String, (usize, BTreeMap<String, String>)>,
|
||||
config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl StorageManager {
|
||||
fn new(port: IpcReceiver<StorageThreadMsg>) -> StorageManager {
|
||||
fn new(port: IpcReceiver<StorageThreadMsg>,
|
||||
config_dir: Option<PathBuf>)
|
||||
-> StorageManager {
|
||||
let mut local_data = HashMap::new();
|
||||
if let Some(ref config_dir) = opts::get().config_dir {
|
||||
resource_thread::read_json_from_file(
|
||||
&mut local_data, Path::new(config_dir), "local_data.json");
|
||||
if let Some(ref config_dir) = config_dir {
|
||||
resource_thread::read_json_from_file(&mut local_data, config_dir, "local_data.json");
|
||||
}
|
||||
StorageManager {
|
||||
port: port,
|
||||
session_data: HashMap::new(),
|
||||
local_data: local_data,
|
||||
config_dir: config_dir,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,9 +79,8 @@ impl StorageManager {
|
|||
self.clear(sender, url, storage_type)
|
||||
}
|
||||
StorageThreadMsg::Exit(sender) => {
|
||||
if let Some(ref config_dir) = opts::get().config_dir {
|
||||
resource_thread::write_json_to_file(
|
||||
&self.local_data, Path::new(config_dir), "local_data.json");
|
||||
if let Some(ref config_dir) = self.config_dir {
|
||||
resource_thread::write_json_to_file(&self.local_data, config_dir, "local_data.json");
|
||||
}
|
||||
let _ = sender.send(());
|
||||
break
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue