add a core resource thread-pool

This commit is contained in:
Gregory Terzian 2020-02-11 15:00:27 +08:00
parent baac1e2c69
commit 780a1bd6cb
7 changed files with 399 additions and 219 deletions

View file

@ -27,6 +27,7 @@ use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::{self, CancellationListener, FetchContext};
use net::filemanager_thread::FileManager;
use net::hsts::HstsEntry;
use net::resource_thread::CoreResourceThreadPool;
use net::test::HttpState;
use net_traits::request::{
Destination, Origin, RedirectMode, Referrer, Request, RequestBuilder, RequestMode,
@ -42,7 +43,7 @@ use std::fs;
use std::iter::FromIterator;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, Weak};
use std::time::{Duration, SystemTime};
use uuid::Uuid;
@ -154,7 +155,7 @@ fn test_fetch_blob() {
}
}
let context = new_fetch_context(None, None);
let context = new_fetch_context(None, None, None);
let bytes = b"content";
let blob_buf = BlobBuf {
@ -215,9 +216,14 @@ fn test_file() {
let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), None);
let fetch_response = fetch(&mut request, None);
let pool = CoreResourceThreadPool::new(1);
let pool_handle = Arc::new(pool);
let mut context = new_fetch_context(None, None, Some(Arc::downgrade(&pool_handle)));
let fetch_response = fetch_with_context(&mut request, &mut context);
// We should see an opaque-filtered response.
assert_eq!(fetch_response.response_type, ResponseType::Opaque);
assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 0);
let resp_body = fetch_response.body.lock().unwrap();
@ -676,7 +682,7 @@ fn test_fetch_with_hsts() {
state: Arc::new(HttpState::new(tls_config)),
user_agent: DEFAULT_USER_AGENT.into(),
devtools_chan: None,
filemanager: FileManager::new(create_embedder_proxy()),
filemanager: FileManager::new(create_embedder_proxy(), Weak::new()),
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
ResourceTimingType::Navigation,
@ -728,7 +734,7 @@ fn test_load_adds_host_to_hsts_list_when_url_is_https() {
state: Arc::new(HttpState::new(tls_config)),
user_agent: DEFAULT_USER_AGENT.into(),
devtools_chan: None,
filemanager: FileManager::new(create_embedder_proxy()),
filemanager: FileManager::new(create_embedder_proxy(), Weak::new()),
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
ResourceTimingType::Navigation,

View file

@ -6,6 +6,7 @@ use crate::create_embedder_proxy;
use embedder_traits::FilterPattern;
use ipc_channel::ipc;
use net::filemanager_thread::FileManager;
use net::resource_thread::CoreResourceThreadPool;
use net_traits::blob_url_store::BlobURLStoreError;
use net_traits::filemanager_thread::{
FileManagerThreadError, FileManagerThreadMsg, ReadFileProgress,
@ -14,10 +15,13 @@ use servo_config::set_pref;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::sync::Arc;
#[test]
fn test_filemanager() {
let filemanager = FileManager::new(create_embedder_proxy());
let pool = CoreResourceThreadPool::new(1);
let pool_handle = Arc::new(pool);
let filemanager = FileManager::new(create_embedder_proxy(), Arc::downgrade(&pool_handle));
set_pref!(dom.testing.html_input_element.select_files.enabled, true);
// Try to open a dummy file "components/net/tests/test.jpeg" in tree

View file

@ -562,7 +562,7 @@ fn test_load_doesnt_add_host_to_hsts_list_when_url_is_http_even_if_hsts_headers_
.pipeline_id(Some(TEST_PIPELINE_ID))
.build();
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
let response = fetch_with_context(&mut request, &mut context);
let _ = server.close();
@ -596,7 +596,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
};
let (server, url) = make_server(handler);
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);
@ -639,7 +639,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
};
let (server, url) = make_server(handler);
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
@ -685,7 +685,7 @@ fn test_load_sends_cookie_if_nonhttp() {
};
let (server, url) = make_server(handler);
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
@ -731,7 +731,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
};
let (server, url) = make_server(handler);
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);
@ -778,7 +778,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
};
let (server, url) = make_server(handler);
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);
@ -1180,7 +1180,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
let url_y = ServoUrl::parse(&format!("http://mozilla.org:{}/org/", port)).unwrap();
*shared_url_y_clone.lock().unwrap() = Some(url_y.clone());
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
let cookie_x = Cookie::new_wrapped(
@ -1290,7 +1290,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
.credentials_mode(CredentialsMode::Include)
.build();
let mut context = new_fetch_context(None, None);
let mut context = new_fetch_context(None, None, None);
let auth_entry = AuthCacheEntry {
user_name: "username".to_owned(),

View file

@ -33,6 +33,7 @@ use net::connector::{create_tls_config, ALPN_H2_H1};
use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::{self, CancellationListener, FetchContext};
use net::filemanager_thread::FileManager;
use net::resource_thread::CoreResourceThreadPool;
use net::test::HttpState;
use net_traits::request::Request;
use net_traits::response::Response;
@ -42,7 +43,7 @@ use servo_arc::Arc as ServoArc;
use servo_url::ServoUrl;
use std::net::TcpListener as StdTcpListener;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, Weak};
use tokio::net::TcpListener;
use tokio::reactor::Handle;
use tokio::runtime::Runtime;
@ -86,15 +87,17 @@ fn create_embedder_proxy() -> EmbedderProxy {
fn new_fetch_context(
dc: Option<Sender<DevtoolsControlMsg>>,
fc: Option<EmbedderProxy>,
pool_handle: Option<Weak<CoreResourceThreadPool>>,
) -> FetchContext {
let certs = resources::read_string(Resource::SSLCertificates);
let tls_config = create_tls_config(&certs, ALPN_H2_H1);
let sender = fc.unwrap_or_else(|| create_embedder_proxy());
FetchContext {
state: Arc::new(HttpState::new(tls_config)),
user_agent: DEFAULT_USER_AGENT.into(),
devtools_chan: dc,
filemanager: FileManager::new(sender),
filemanager: FileManager::new(sender, pool_handle.unwrap_or_else(|| Weak::new())),
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
ResourceTimingType::Navigation,
@ -113,7 +116,7 @@ impl FetchTaskTarget for FetchResponseCollector {
}
fn fetch(request: &mut Request, dc: Option<Sender<DevtoolsControlMsg>>) -> Response {
fetch_with_context(request, &mut new_fetch_context(dc, None))
fetch_with_context(request, &mut new_fetch_context(dc, None, None))
}
fn fetch_with_context(request: &mut Request, mut context: &mut FetchContext) -> Response {
@ -133,7 +136,7 @@ fn fetch_with_cors_cache(request: &mut Request, cache: &mut CorsCache) -> Respon
request,
cache,
&mut target,
&mut new_fetch_context(None, None),
&mut new_fetch_context(None, None, None),
);
receiver.recv().unwrap()