Skip to content

Commit

Permalink
make resource_thread talk to sw-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
creativcoder committed Jul 18, 2016
1 parent 1e6293e commit eff3e01
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 108 deletions.
44 changes: 3 additions & 41 deletions components/constellation/constellation.rs
Expand Up @@ -35,7 +35,7 @@ use net_traits::bluetooth_thread::BluetoothMethodMsg;
use net_traits::filemanager_thread::FileManagerThreadMsg;
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::storage_thread::StorageThreadMsg;
use net_traits::{self, ResourceThreads, IpcSend, CustomResponseMediator, CoreResourceMsg};
use net_traits::{self, ResourceThreads, IpcSend};
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use pipeline::{ChildProcess, InitialPipelineState, Pipeline};
use profile_traits::mem;
Expand Down Expand Up @@ -98,9 +98,6 @@ pub struct Constellation<Message, LTF, STF> {
/// Receives messages from scripts.
script_receiver: Receiver<FromScriptMsg>,

/// Receive messages from resource thread
resource_receiver: Receiver<CustomResponseMediator>,

/// Receives messages from the compositor
compositor_receiver: Receiver<FromCompositorMsg>,

Expand Down Expand Up @@ -440,13 +437,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let (ipc_panic_sender, ipc_panic_receiver) = ipc::channel().expect("ipc channel failure");
let panic_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_panic_receiver);

let (resource_ipc_sender, resource_ipc_receiver) = ipc::channel().expect("ipc channel failure");
let resource_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(resource_ipc_receiver);

state.public_resource_threads.sender()
.send(CoreResourceMsg::NetworkMediator(resource_ipc_sender))
.expect("network sender sending failure");

let swmanager_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(swmanager_receiver);

let mut constellation: Constellation<Message, LTF, STF> = Constellation {
Expand All @@ -467,7 +457,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
swmanager_chan: None,
swmanager_receiver: swmanager_receiver,
swmanager_sender: sw_mgr_clone,
resource_receiver: resource_receiver,
pipelines: HashMap::new(),
frames: HashMap::new(),
subpage_map: HashMap::new(),
Expand Down Expand Up @@ -638,8 +627,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Compositor(FromCompositorMsg),
Layout(FromLayoutMsg),
Panic(PanicMsg),
FromSWManager(SWManagerMsg),
FromResource(CustomResponseMediator),
FromSWManager(SWManagerMsg)
}

// Get one incoming request.
Expand All @@ -659,7 +647,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let receiver_from_layout = &self.layout_receiver;
let receiver_from_panic = &self.panic_receiver;
let receiver_from_swmanager = &self.swmanager_receiver;
let receiver_from_resource = &self.resource_receiver;
select! {
msg = receiver_from_script.recv() =>
Request::Script(msg.expect("Unexpected script channel panic in constellation")),
Expand All @@ -670,9 +657,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
msg = receiver_from_panic.recv() =>
Request::Panic(msg.expect("Unexpected panic channel panic in constellation")),
msg = receiver_from_swmanager.recv() =>
Request::FromSWManager(msg.expect("Unexpected panic channel panic in constellation")),
msg = receiver_from_resource.recv() =>
Request::FromResource(msg.expect("Unexpected panic channel panic in constellation"))
Request::FromSWManager(msg.expect("Unexpected panic channel panic in constellation"))
}
};

Expand All @@ -692,9 +677,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Request::FromSWManager(message) => {
self.handle_request_from_swmanager(message);
}
Request::FromResource(message) => {
self.handle_request_from_resource(message);
}
}
}

Expand All @@ -707,14 +689,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}

fn handle_request_from_resource(&self, mediator: CustomResponseMediator) {
if let Some(ref mgr) = self.swmanager_chan {
let _ = mgr.send(ServiceWorkerMsg::ActivateWorker(mediator));
} else {
warn!("activation request to service worker manager failed");
}
}

fn handle_request_from_compositor(&mut self, message: FromCompositorMsg) {
match message {
FromCompositorMsg::Exit => {
Expand Down Expand Up @@ -985,10 +959,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
FromScriptMsg::GetScrollOffset(pid, lid, send) => {
self.compositor_proxy.send(ToCompositorMsg::GetScrollOffset(pid, lid, send));
}
FromScriptMsg::NetworkRequest(mediator) => {
debug!("activation request for service worker received");
self.handle_activate_worker(mediator);
}
FromScriptMsg::RegisterServiceWorker(scope_things, scope) => {
debug!("constellation got store registration scope message");
self.handle_register_serviceworker(scope_things, scope);
Expand Down Expand Up @@ -1028,14 +998,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}

fn handle_activate_worker(&self, mediator: CustomResponseMediator) {
if let Some(ref mgr) = self.swmanager_chan {
let _ = mgr.send(ServiceWorkerMsg::ActivateWorker(mediator));
} else {
warn!("activation request to service worker manager failed");
}
}

fn handle_exit(&mut self) {
// TODO: add a timer, which forces shutdown if threads aren't responsive.
if self.shutting_down { return; }
Expand Down
11 changes: 7 additions & 4 deletions components/constellation/pipeline.rs
Expand Up @@ -19,13 +19,13 @@ use layers::geometry::DevicePixel;
use layout_traits::LayoutThreadFactory;
use msg::constellation_msg::{FrameId, FrameType, LoadData, PanicMsg, PipelineId};
use msg::constellation_msg::{PipelineNamespaceId, SubpageId};
use net_traits::ResourceThreads;
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use net_traits::image_cache_thread::ImageCacheThread;
use net_traits::{ResourceThreads, IpcSend};
use profile_traits::mem as profile_mem;
use profile_traits::time;
use script_traits::{ConstellationControlMsg, InitialScriptState, MozBrowserEvent};
use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg, SWManagerMsg};
use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg, SWManagerMsg, SWManagerSenders};
use script_traits::{ScriptThreadFactory, TimerEventRequest, WindowSizeData};
use std::collections::HashMap;
use std::io::Error as IOError;
Expand Down Expand Up @@ -551,7 +551,10 @@ impl UnprivilegedPipelineContent {
self.prefs.clone()
}

pub fn swmanager_chan(&self) -> IpcSender<SWManagerMsg> {
self.swmanager_thread.clone()
pub fn swmanager_senders(&self) -> SWManagerSenders {
SWManagerSenders {
swmanager_sender: self.swmanager_thread.clone(),
resource_sender: self.resource_threads.sender()
}
}
}
14 changes: 7 additions & 7 deletions components/net/http_loader.rs
Expand Up @@ -59,7 +59,7 @@ pub fn factory(user_agent: String,
http_state: HttpState,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
profiler_chan: ProfilerChan,
constellation_chan: Option<IpcSender<CustomResponseMediator>>,
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
connector: Arc<Pool<Connector>>)
-> Box<FnBox(LoadData,
LoadConsumer,
Expand All @@ -79,7 +79,7 @@ pub fn factory(user_agent: String,
connector,
http_state,
devtools_chan,
constellation_chan,
swmanager_chan,
cancel_listener,
user_agent)
})
Expand Down Expand Up @@ -133,7 +133,7 @@ fn load_for_consumer(load_data: LoadData,
connector: Arc<Pool<Connector>>,
http_state: HttpState,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
constellation_chan: Option<IpcSender<CustomResponseMediator>>,
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
cancel_listener: CancellationListener,
user_agent: String) {
let factory = NetworkHttpRequestFactory {
Expand All @@ -143,7 +143,7 @@ fn load_for_consumer(load_data: LoadData,
let ui_provider = TFDProvider;
match load(&load_data, &ui_provider, &http_state,
devtools_chan, &factory,
user_agent, &cancel_listener, constellation_chan) {
user_agent, &cancel_listener, swmanager_chan) {
Err(error) => {
match error.error {
LoadErrorType::ConnectionAborted { .. } => unreachable!(),
Expand Down Expand Up @@ -864,7 +864,7 @@ pub fn load<A, B>(load_data: &LoadData,
request_factory: &HttpRequestFactory<R=A>,
user_agent: String,
cancel_listener: &CancellationListener,
constellation_chan: Option<IpcSender<CustomResponseMediator>>)
swmanager_chan: Option<IpcSender<CustomResponseMediator>>)
-> Result<StreamedResponse, LoadError> where A: HttpRequest + 'static, B: UIProvider {
let max_redirects = PREFS.get("network.http.redirection-limit").as_i64().unwrap() as u32;
let mut iters = 0;
Expand All @@ -886,9 +886,9 @@ pub fn load<A, B>(load_data: &LoadData,
response_chan: msg_sender,
load_url: doc_url.clone()
};
if let Some(sender) = constellation_chan {
if let Some(sender) = swmanager_chan {
let _ = sender.send(response_mediator);
if let Ok(Some(custom_response)) = msg_receiver.try_recv() {
if let Ok(Some(custom_response)) = msg_receiver.recv() {
let metadata = Metadata::default(doc_url.clone());
let readable_response = to_readable_response(custom_response);
return StreamedResponse::from_http_response(box readable_response, metadata);
Expand Down
8 changes: 4 additions & 4 deletions components/net/resource_thread.rs
Expand Up @@ -280,7 +280,7 @@ impl ResourceChannelManager {
consumer.send(cookie_jar.cookies_for_url(&url, source)).unwrap();
}
CoreResourceMsg::NetworkMediator(mediator_chan) => {
self.resource_manager.constellation_chan = Some(mediator_chan)
self.resource_manager.swmanager_chan = Some(mediator_chan)
}
CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => {
let mut cookie_jar = group.cookie_jar.write().unwrap();
Expand Down Expand Up @@ -459,7 +459,7 @@ pub struct CoreResourceManager {
user_agent: String,
mime_classifier: Arc<MimeClassifier>,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
constellation_chan: Option<IpcSender<CustomResponseMediator>>,
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
profiler_chan: ProfilerChan,
filemanager_chan: IpcSender<FileManagerThreadMsg>,
cancel_load_map: HashMap<ResourceId, Sender<()>>,
Expand All @@ -475,7 +475,7 @@ impl CoreResourceManager {
user_agent: user_agent,
mime_classifier: Arc::new(MimeClassifier::new()),
devtools_chan: devtools_channel,
constellation_chan: None,
swmanager_chan: None,
profiler_chan: profiler_chan,
filemanager_chan: filemanager_chan,
cancel_load_map: HashMap::new(),
Expand Down Expand Up @@ -547,7 +547,7 @@ impl CoreResourceManager {
http_state,
self.devtools_chan.clone(),
self.profiler_chan.clone(),
self.constellation_chan.clone(),
self.swmanager_chan.clone(),
resource_grp.connector.clone())
},
"data" => from_factory(data_loader::factory),
Expand Down
7 changes: 3 additions & 4 deletions components/script/lib.rs
Expand Up @@ -114,9 +114,8 @@ mod unpremultiplytable;
mod webdriver_handlers;

use dom::bindings::codegen::RegisterBindings;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{Handle, JSContext, JSObject, SetDOMProxyInformation};
use script_traits::SWManagerMsg;
use script_traits::SWManagerSenders;
use serviceworker_manager::ServiceWorkerManager;
use std::ptr;
use util::opts;
Expand Down Expand Up @@ -163,13 +162,13 @@ fn perform_platform_specific_initialization() {
fn perform_platform_specific_initialization() {}

#[allow(unsafe_code)]
pub fn init(from_swmanager_sender: IpcSender<SWManagerMsg>) {
pub fn init(sw_senders: SWManagerSenders) {
unsafe {
SetDOMProxyInformation(ptr::null(), 0, Some(script_thread::shadow_check_callback));
}

// Spawn the service worker manager passing the constellation sender
ServiceWorkerManager::spawn_manager(from_swmanager_sender);
ServiceWorkerManager::spawn_manager(sw_senders);

// Create the global vtables used by the (generated) DOM
// bindings to implement JS proxies.
Expand Down

0 comments on commit eff3e01

Please sign in to comment.