Auto merge of #23520 - oneturkmen:net-remove-opts-get, r=jdm

Net: removed opts::get() usage

<!-- Please describe your changes on the following line: -->
Removed usage of opts::get() in components/net.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix *partially* #22854 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because these are cleanup/refactoring changes.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23520)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-06-07 12:34:23 -04:00 committed by GitHub
commit 626c431e06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 10 deletions

View file

@ -34,7 +34,6 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::mem::{Report, ReportKind, ReportsChan};
use profile_traits::time::ProfilerChan;
use serde::{Deserialize, Serialize};
use servo_config::opts;
use servo_url::ServoUrl;
use std::borrow::{Cow, ToOwned};
use std::collections::HashMap;
@ -54,6 +53,7 @@ pub fn new_resource_threads(
mem_profiler_chan: MemProfilerChan,
embedder_proxy: EmbedderProxy,
config_dir: Option<PathBuf>,
certificate_path: Option<String>,
) -> (ResourceThreads, ResourceThreads) {
let (public_core, private_core) = new_core_resource_thread(
user_agent,
@ -62,6 +62,7 @@ pub fn new_resource_threads(
mem_profiler_chan,
embedder_proxy,
config_dir.clone(),
certificate_path,
);
let storage: IpcSender<StorageThreadMsg> = StorageThreadFactory::new(config_dir);
(
@ -78,6 +79,7 @@ pub fn new_core_resource_thread(
mem_profiler_chan: MemProfilerChan,
embedder_proxy: EmbedderProxy,
config_dir: Option<PathBuf>,
certificate_path: Option<String>,
) -> (CoreResourceThread, CoreResourceThread) {
let (public_setup_chan, public_setup_port) = ipc::channel().unwrap();
let (private_setup_chan, private_setup_port) = ipc::channel().unwrap();
@ -91,11 +93,13 @@ pub fn new_core_resource_thread(
devtools_chan,
time_profiler_chan,
embedder_proxy,
certificate_path.clone(),
);
let mut channel_manager = ResourceChannelManager {
resource_manager: resource_manager,
config_dir: config_dir,
resource_manager,
config_dir,
certificate_path,
};
mem_profiler_chan.run_with_memory_reporting(
@ -112,9 +116,13 @@ pub fn new_core_resource_thread(
struct ResourceChannelManager {
resource_manager: CoreResourceManager,
config_dir: Option<PathBuf>,
certificate_path: Option<String>,
}
fn create_http_states(config_dir: Option<&Path>) -> (Arc<HttpState>, Arc<HttpState>) {
fn create_http_states(
config_dir: Option<&Path>,
certificate_path: Option<String>,
) -> (Arc<HttpState>, Arc<HttpState>) {
let mut hsts_list = HstsList::from_servo_preload();
let mut auth_cache = AuthCache::new();
let http_cache = HttpCache::new();
@ -125,7 +133,7 @@ fn create_http_states(config_dir: Option<&Path>) -> (Arc<HttpState>, Arc<HttpSta
read_json_from_file(&mut cookie_jar, config_dir, "cookie_jar.json");
}
let certs = match opts::get().certificate_path {
let certs = match certificate_path {
Some(ref path) => fs::read_to_string(path).expect("Couldn't not find certificate file"),
None => resources::read_string(Resource::SSLCertificates),
};
@ -154,8 +162,10 @@ impl ResourceChannelManager {
private_receiver: IpcReceiver<CoreResourceMsg>,
memory_reporter: IpcReceiver<ReportsChan>,
) {
let (public_http_state, private_http_state) =
create_http_states(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),
self.certificate_path.clone(),
);
let mut rx_set = IpcReceiverSet::new().unwrap();
let private_id = rx_set.add(private_receiver).unwrap();
@ -407,6 +417,7 @@ pub struct CoreResourceManager {
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
filemanager: FileManager,
fetch_pool: rayon::ThreadPool,
certificate_path: Option<String>,
}
impl CoreResourceManager {
@ -415,6 +426,7 @@ impl CoreResourceManager {
devtools_channel: Option<Sender<DevtoolsControlMsg>>,
_profiler_chan: ProfilerChan,
embedder_proxy: EmbedderProxy,
certificate_path: Option<String>,
) -> CoreResourceManager {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(16)
@ -426,6 +438,7 @@ impl CoreResourceManager {
swmanager_chan: None,
filemanager: FileManager::new(embedder_proxy),
fetch_pool: pool,
certificate_path,
}
}
@ -500,6 +513,12 @@ impl CoreResourceManager {
action_receiver: IpcReceiver<WebSocketDomAction>,
http_state: &Arc<HttpState>,
) {
websocket_loader::init(request, event_sender, action_receiver, http_state.clone());
websocket_loader::init(
request,
event_sender,
action_receiver,
http_state.clone(),
self.certificate_path.clone(),
);
}
}

View file

@ -27,6 +27,7 @@ fn test_exit() {
MemProfilerChan(mtx),
create_embedder_proxy(),
None,
None,
);
resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap();
receiver.recv().unwrap();

View file

@ -16,7 +16,6 @@ use net_traits::request::{RequestBuilder, RequestMode};
use net_traits::{CookieSource, MessageData};
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
use openssl::ssl::SslStream;
use servo_config::opts;
use servo_url::ServoUrl;
use std::fs;
use std::sync::atomic::{AtomicBool, Ordering};
@ -40,6 +39,7 @@ struct Client<'a> {
resource_url: &'a ServoUrl,
event_sender: &'a IpcSender<WebSocketNetworkEvent>,
protocol_in_use: Option<String>,
certificate_path: Option<String>,
}
impl<'a> Factory for Client<'a> {
@ -153,7 +153,7 @@ impl<'a> Handler for Client<'a> {
stream: TcpStream,
url: &Url,
) -> WebSocketResult<SslStream<TcpStream>> {
let certs = match opts::get().certificate_path {
let certs = match self.certificate_path {
Some(ref path) => fs::read_to_string(path).expect("Couldn't not find certificate file"),
None => resources::read_string(Resource::SSLCertificates),
};
@ -178,6 +178,7 @@ pub fn init(
resource_event_sender: IpcSender<WebSocketNetworkEvent>,
dom_action_receiver: IpcReceiver<WebSocketDomAction>,
http_state: Arc<HttpState>,
certificate_path: Option<String>,
) {
thread::Builder::new()
.name(format!("WebSocket connection to {}", req_builder.url))
@ -229,6 +230,7 @@ pub fn init(
resource_url: &req_builder.url,
event_sender: &resource_event_sender,
protocol_in_use: None,
certificate_path,
};
let mut ws = WebSocket::new(client).unwrap();

View file

@ -631,6 +631,7 @@ fn create_constellation(
mem_profiler_chan.clone(),
embedder_proxy.clone(),
config_dir,
opts.certificate_path.clone(),
);
let font_cache_thread = FontCacheThread::new(
public_resource_threads.sender(),