mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Kill ResourceGroup
This commit is contained in:
parent
16863017a9
commit
10801caefd
1 changed files with 23 additions and 36 deletions
|
@ -41,11 +41,6 @@ use websocket_loader;
|
|||
|
||||
const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ResourceGroup {
|
||||
http_state: Arc<HttpState>,
|
||||
}
|
||||
|
||||
/// Returns a tuple of (public, private) senders to the new threads.
|
||||
pub fn new_resource_threads(user_agent: Cow<'static, str>,
|
||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||
|
@ -91,8 +86,7 @@ struct ResourceChannelManager {
|
|||
config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn create_resource_groups(config_dir: Option<&Path>)
|
||||
-> (ResourceGroup, ResourceGroup) {
|
||||
fn create_http_states(config_dir: Option<&Path>) -> (Arc<HttpState>, Arc<HttpState>) {
|
||||
let mut hsts_list = HstsList::from_servo_preload();
|
||||
let mut auth_cache = AuthCache::new();
|
||||
let mut cookie_jar = CookieStorage::new(150);
|
||||
|
@ -117,16 +111,11 @@ fn create_resource_groups(config_dir: Option<&Path>)
|
|||
ssl_client: ssl_client.clone(),
|
||||
connector: create_http_connector(ssl_client),
|
||||
};
|
||||
let resource_group = ResourceGroup {
|
||||
http_state: Arc::new(http_state),
|
||||
};
|
||||
|
||||
let private_ssl_client = create_ssl_client(&ca_file);
|
||||
let private_resource_group = ResourceGroup {
|
||||
http_state: Arc::new(HttpState::new(private_ssl_client)),
|
||||
};
|
||||
let private_http_state = HttpState::new(private_ssl_client);
|
||||
|
||||
(resource_group, private_resource_group)
|
||||
(Arc::new(http_state), Arc::new(private_http_state))
|
||||
}
|
||||
|
||||
impl ResourceChannelManager {
|
||||
|
@ -134,8 +123,8 @@ impl ResourceChannelManager {
|
|||
fn start(&mut self,
|
||||
public_receiver: IpcReceiver<CoreResourceMsg>,
|
||||
private_receiver: IpcReceiver<CoreResourceMsg>) {
|
||||
let (public_resource_group, private_resource_group) =
|
||||
create_resource_groups(self.config_dir.as_ref().map(Deref::deref));
|
||||
let (public_http_state, private_http_state) =
|
||||
create_http_states(self.config_dir.as_ref().map(Deref::deref));
|
||||
|
||||
let mut rx_set = IpcReceiverSet::new().unwrap();
|
||||
let private_id = rx_set.add(private_receiver).unwrap();
|
||||
|
@ -144,10 +133,10 @@ impl ResourceChannelManager {
|
|||
loop {
|
||||
for (id, data) in rx_set.select().unwrap().into_iter().map(|m| m.unwrap()) {
|
||||
let group = if id == private_id {
|
||||
&private_resource_group
|
||||
&private_http_state
|
||||
} else {
|
||||
assert_eq!(id, public_id);
|
||||
&public_resource_group
|
||||
&public_http_state
|
||||
};
|
||||
if let Ok(msg) = data.to() {
|
||||
if !self.process_msg(msg, group) {
|
||||
|
@ -162,28 +151,28 @@ impl ResourceChannelManager {
|
|||
/// Returns false if the thread should exit.
|
||||
fn process_msg(&mut self,
|
||||
msg: CoreResourceMsg,
|
||||
group: &ResourceGroup) -> bool {
|
||||
http_state: &Arc<HttpState>) -> bool {
|
||||
match msg {
|
||||
CoreResourceMsg::Fetch(init, sender) =>
|
||||
self.resource_manager.fetch(init, sender, group),
|
||||
self.resource_manager.fetch(init, sender, http_state),
|
||||
CoreResourceMsg::WebsocketConnect(connect, connect_data) =>
|
||||
self.resource_manager.websocket_connect(connect, connect_data, group),
|
||||
self.resource_manager.websocket_connect(connect, connect_data, http_state),
|
||||
CoreResourceMsg::SetCookieForUrl(request, cookie, source) =>
|
||||
self.resource_manager.set_cookie_for_url(&request, cookie.into_inner(), source, group),
|
||||
self.resource_manager.set_cookie_for_url(&request, cookie.into_inner(), source, http_state),
|
||||
CoreResourceMsg::SetCookiesForUrl(request, cookies, source) => {
|
||||
for cookie in cookies {
|
||||
self.resource_manager.set_cookie_for_url(&request, cookie.into_inner(), source, group);
|
||||
self.resource_manager.set_cookie_for_url(&request, cookie.into_inner(), source, http_state);
|
||||
}
|
||||
}
|
||||
CoreResourceMsg::GetCookiesForUrl(url, consumer, source) => {
|
||||
let mut cookie_jar = group.http_state.cookie_jar.write().unwrap();
|
||||
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
|
||||
consumer.send(cookie_jar.cookies_for_url(&url, source)).unwrap();
|
||||
}
|
||||
CoreResourceMsg::NetworkMediator(mediator_chan) => {
|
||||
self.resource_manager.swmanager_chan = Some(mediator_chan)
|
||||
}
|
||||
CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => {
|
||||
let mut cookie_jar = group.http_state.cookie_jar.write().unwrap();
|
||||
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
|
||||
let cookies = cookie_jar.cookies_data_for_url(&url, source).map(Serde).collect();
|
||||
consumer.send(cookies).unwrap();
|
||||
}
|
||||
|
@ -199,15 +188,15 @@ impl ResourceChannelManager {
|
|||
CoreResourceMsg::ToFileManager(msg) => self.resource_manager.filemanager.handle(msg, TFD_PROVIDER),
|
||||
CoreResourceMsg::Exit(sender) => {
|
||||
if let Some(ref config_dir) = self.config_dir {
|
||||
match group.http_state.auth_cache.read() {
|
||||
match http_state.auth_cache.read() {
|
||||
Ok(auth_cache) => write_json_to_file(&*auth_cache, config_dir, "auth_cache.json"),
|
||||
Err(_) => warn!("Error writing auth cache to disk"),
|
||||
}
|
||||
match group.http_state.cookie_jar.read() {
|
||||
match http_state.cookie_jar.read() {
|
||||
Ok(jar) => write_json_to_file(&*jar, config_dir, "cookie_jar.json"),
|
||||
Err(_) => warn!("Error writing cookie jar to disk"),
|
||||
}
|
||||
match group.http_state.hsts_list.read() {
|
||||
match http_state.hsts_list.read() {
|
||||
Ok(hsts) => write_json_to_file(&*hsts, config_dir, "hsts_list.json"),
|
||||
Err(_) => warn!("Error writing hsts list to disk"),
|
||||
}
|
||||
|
@ -321,9 +310,9 @@ impl CoreResourceManager {
|
|||
fn set_cookie_for_url(&mut self, request: &ServoUrl,
|
||||
cookie: cookie_rs::Cookie<'static>,
|
||||
source: CookieSource,
|
||||
resource_group: &ResourceGroup) {
|
||||
http_state: &Arc<HttpState>) {
|
||||
if let Some(cookie) = cookie::Cookie::new_wrapped(cookie, request, source) {
|
||||
let mut cookie_jar = resource_group.http_state.cookie_jar.write().unwrap();
|
||||
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
|
||||
cookie_jar.push(cookie, request, source)
|
||||
}
|
||||
}
|
||||
|
@ -331,8 +320,8 @@ impl CoreResourceManager {
|
|||
fn fetch(&self,
|
||||
init: RequestInit,
|
||||
mut sender: IpcSender<FetchResponseMsg>,
|
||||
group: &ResourceGroup) {
|
||||
let http_state = group.http_state.clone();
|
||||
http_state: &Arc<HttpState>) {
|
||||
let http_state = http_state.clone();
|
||||
let ua = self.user_agent.clone();
|
||||
let dc = self.devtools_chan.clone();
|
||||
let filemanager = self.filemanager.clone();
|
||||
|
@ -356,9 +345,7 @@ impl CoreResourceManager {
|
|||
fn websocket_connect(&self,
|
||||
connect: WebSocketCommunicate,
|
||||
connect_data: WebSocketConnectData,
|
||||
resource_grp: &ResourceGroup) {
|
||||
websocket_loader::init(connect,
|
||||
connect_data,
|
||||
resource_grp.http_state.clone());
|
||||
http_state: &Arc<HttpState>) {
|
||||
websocket_loader::init(connect, connect_data, http_state.clone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue