Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract out 'net/storage_thread' into separate components. #10768

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Extract out 'net/storage_thread' into separate components.

The logic for `storage_thread.rs` (in `net` and `net_traits`) is
already isolated from the rest of the other modules in the crates.
  • Loading branch information
frewsxcv committed Apr 24, 2016
commit b0f7cd06c62624edd0cbf426cbd5dc17846de353
@@ -47,6 +47,9 @@ path = "../canvas"
[dependencies.plugins]
path = "../plugins"

[dependencies.storage_traits]
path = "../storage_traits"

[dependencies.azure]
git = "https://github.com/servo/rust-azure"
features = ["plugins"]
@@ -37,7 +37,6 @@ use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
use msg::constellation_msg::{self, ConstellationChan, PanicMsg};
use msg::webdriver_msg;
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::storage_thread::{StorageThread, StorageThreadMsg};
use net_traits::{self, ResourceThread};
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pipeline::{CompositionPipeline, InitialPipelineState, Pipeline, UnprivilegedPipelineContent};
@@ -59,6 +58,7 @@ use std::marker::PhantomData;
use std::mem::replace;
use std::process;
use std::sync::mpsc::{Sender, channel, Receiver};
use storage_traits::storage_thread::{StorageThread, StorageThreadMsg};
use style_traits::cursor::Cursor;
use style_traits::viewport::ViewportConstraints;
use timer_scheduler::TimerScheduler;
@@ -40,6 +40,7 @@ extern crate profile_traits;
extern crate rand;
extern crate script_traits;
extern crate serde;
extern crate storage_traits;
extern crate style_traits;
extern crate time;
extern crate url;
@@ -19,7 +19,6 @@ use msg::constellation_msg::{LoadData, WindowSizeData};
use msg::constellation_msg::{PipelineNamespaceId};
use net_traits::ResourceThread;
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::storage_thread::StorageThread;
use profile_traits::mem as profile_mem;
use profile_traits::time;
use script_traits::{ConstellationControlMsg, InitialScriptState, MozBrowserEvent};
@@ -28,6 +27,7 @@ use script_traits::{ScriptToCompositorMsg, ScriptThreadFactory, TimerEventReques
use std::collections::HashMap;
use std::mem;
use std::sync::mpsc::{Receiver, Sender, channel};
use storage_traits::storage_thread::StorageThread;
use url::Url;
use util;
use util::geometry::{PagePx, ViewportPx};
@@ -50,7 +50,6 @@ pub mod image_cache_thread;
pub mod mime_classifier;
pub mod pub_domains;
pub mod resource_thread;
pub mod storage_thread;
pub mod websocket_loader;

/// An implementation of the [Fetch specification](https://fetch.spec.whatwg.org/)
@@ -22,22 +22,18 @@ use net_traits::ProgressMsg::Done;
use net_traits::{AsyncResponseTarget, Metadata, ProgressMsg, ResourceThread, ResponseAction};
use net_traits::{ControlMsg, CookieSource, LoadConsumer, LoadData, LoadResponse, ResourceId};
use net_traits::{NetworkError, WebSocketCommunicate, WebSocketConnectData};
use rustc_serialize::Encodable;
use rustc_serialize::json;
use std::borrow::ToOwned;
use std::boxed::FnBox;
use std::cell::Cell;
use std::collections::HashMap;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::sync::{Arc, RwLock};
use url::Url;
use util::opts;
use util::prefs;
use util::thread::spawn_named;
use util::write::write_json_to_file;
use websocket_loader;

pub enum ProgressSender {
@@ -219,31 +215,6 @@ impl ResourceChannelManager {
}
}

pub fn write_json_to_file<T: Encodable>(data: &T, profile_dir: &str, filename: &str) {
let json_encoded: String;
match json::encode(&data) {
Ok(d) => json_encoded = d,
Err(_) => return,
}
let path = Path::new(profile_dir).join(filename);
let display = path.display();

let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}: {}",
display,
Error::description(&why)),
Ok(file) => file,
};

match file.write_all(json_encoded.as_bytes()) {
Err(why) => {
panic!("couldn't write to {}: {}", display,
Error::description(&why))
},
Ok(_) => println!("successfully wrote to {}", display),
}
}

/// The optional resources required by the `CancellationListener`
pub struct CancellableResource {
/// The receiver which receives a message on load cancellation
@@ -45,7 +45,6 @@ pub mod image_cache_thread;
pub mod net_error_list;
pub mod request;
pub mod response;
pub mod storage_thread;

/// Image handling.
///
@@ -34,6 +34,9 @@ path = "../script_traits"
[dependencies.devtools_traits]
path = "../devtools_traits"

[dependencies.storage_traits]
path = "../storage_traits"

[dependencies.style]
path = "../style"

@@ -60,7 +60,6 @@ use msg::constellation_msg::{PipelineId, SubpageId, WindowSizeData, WindowSizeTy
use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::response::HttpsState;
use net_traits::storage_thread::StorageType;
use net_traits::{Metadata, NetworkError};
use offscreen_gl_context::GLLimits;
use profile_traits::mem::ProfilerChan as MemProfilerChan;
@@ -82,6 +81,7 @@ use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::mpsc::{Receiver, Sender};
use storage_traits::storage_thread::StorageType;
use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue};
use style::element_state::*;
@@ -14,10 +14,10 @@ use dom::event::{Event, EventBubbles, EventCancelable};
use dom::storageevent::StorageEvent;
use dom::urlhelper::UrlHelper;
use ipc_channel::ipc;
use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
use page::IterablePage;
use script_runtime::ScriptChan;
use script_thread::{MainThreadRunnable, MainThreadScriptChan, ScriptThread};
use storage_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
use task_source::dom_manipulation::DOMManipulationTask;
use url::Url;
use util::str::DOMString;
@@ -48,7 +48,6 @@ use msg::constellation_msg::{WindowSizeData, WindowSizeType};
use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
use net_traits::ResourceThread;
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::storage_thread::{StorageThread, StorageType};
use num_traits::ToPrimitive;
use page::Page;
use profile_traits::mem;
@@ -72,6 +71,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex};
use storage_traits::storage_thread::{StorageThread, StorageType};
use string_cache::Atom;
use style::context::ReflowGoal;
use style::error_reporting::ParseErrorReporter;
@@ -69,6 +69,7 @@ extern crate script_traits;
extern crate selectors;
extern crate serde;
extern crate smallvec;
extern crate storage_traits;
#[macro_use(atom, ns)] extern crate string_cache;
#[macro_use]
extern crate style;
@@ -65,7 +65,6 @@ use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
use msg::webdriver_msg::WebDriverScriptCommand;
use net_traits::LoadData as NetLoadData;
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread};
use net_traits::storage_thread::StorageThread;
use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, LoadContext, Metadata, ResourceThread};
use network_listener::NetworkListener;
use page::{Frame, IterablePage, Page};
@@ -92,6 +91,7 @@ use std::result::Result;
use std::sync::atomic::{Ordering, AtomicBool};
use std::sync::mpsc::{Receiver, Select, Sender, channel};
use std::sync::{Arc, Mutex};
use storage_traits::storage_thread::StorageThread;
use style::context::ReflowGoal;
use task_source::TaskSource;
use task_source::dom_manipulation::{DOMManipulationTaskSource, DOMManipulationTask};
@@ -26,6 +26,9 @@ path = "../plugins"
[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.storage_traits]
path = "../storage_traits"

[dependencies.style_traits]
path = "../style_traits"

@@ -24,6 +24,7 @@ extern crate net_traits;
extern crate offscreen_gl_context;
extern crate profile_traits;
extern crate serde;
extern crate storage_traits;
extern crate style_traits;
extern crate time;
extern crate url;
@@ -48,9 +49,9 @@ use msg::webdriver_msg::WebDriverScriptCommand;
use net_traits::ResourceThread;
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::response::HttpsState;
use net_traits::storage_thread::StorageThread;
use profile_traits::mem;
use std::any::Any;
use storage_traits::storage_thread::StorageThread;
use url::Url;
use util::ipc::OptionalOpaqueIpcSender;

Some generated files are not rendered by default. Learn more.

@@ -81,6 +81,12 @@ path = "../net_traits"
[dependencies.msg]
path = "../msg"

[dependencies.storage]
path = "../storage"

[dependencies.storage_traits]
path = "../storage_traits"

[dependencies.profile]
path = "../profile"

@@ -39,6 +39,8 @@ pub extern crate profile;
pub extern crate profile_traits;
pub extern crate script;
pub extern crate script_traits;
pub extern crate storage;
pub extern crate storage_traits;
pub extern crate style;
pub extern crate url;
pub extern crate util;
@@ -73,14 +75,14 @@ use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{self, IpcSender};
use net::image_cache_thread::new_image_cache_thread;
use net::resource_thread::new_resource_thread;
use net::storage_thread::StorageThreadFactory;
use net_traits::storage_thread::StorageThread;
use profile::mem as profile_mem;
use profile::time as profile_time;
use profile_traits::mem;
use profile_traits::time;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use storage::storage_thread::StorageThreadFactory;
use storage_traits::storage_thread::StorageThread;
use util::resource_files::resources_dir_path;
use util::{opts, prefs};

@@ -0,0 +1,19 @@
[package]
name = "storage"
version = "0.1.0"
publish = false

[lib]
path = "lib.rs"

[dependencies]
url = {version = "0.5.7", features = ["heap_size"]}

[dependencies.storage_traits]
path = "../storage_traits"

[dependencies.util]
path = "../util"

[dependencies.ipc-channel]
git = "https://github.com/servo/ipc-channel"
@@ -0,0 +1,10 @@
/* 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/. */

extern crate ipc_channel;
extern crate storage_traits;
extern crate url;
extern crate util;

pub mod storage_thread;
@@ -3,14 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use net_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
use resource_thread;
use std::borrow::ToOwned;
use std::collections::BTreeMap;
use std::collections::HashMap;
use storage_traits::storage_thread::{StorageThread, StorageThreadMsg, StorageType};
use url::Url;
use util::opts;
use util::thread::spawn_named;
use util::write::write_json_to_file;

const QUOTA_SIZE_LIMIT: usize = 5 * 1024 * 1024;

@@ -72,7 +72,7 @@ impl StorageManager {
}
StorageThreadMsg::Exit => {
if let Some(ref profile_dir) = opts::get().profile_dir {
resource_thread::write_json_to_file(&self.local_data, profile_dir, "local_data.json");
write_json_to_file(&self.local_data, profile_dir, "local_data.json");
}
break
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.