Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uprefactor(net): removes direct ui invocation from filemgr thread #20480
Conversation
highfive
commented
Mar 30, 2018
|
Heads up! This PR modifies the following files:
|
|
|
|
I see you call |
|
@paulrouget I just give a quick try (open tfd for single / multiple dialog, check if it unblocks main) on linux / windows / macOS, and all platform seems working as expected. (Does not block / no immediate panic or unexpected behavior). |
|
Could we short-circuit the constellation and directly use the embedder channel (EmbedderProxy)? |
| @@ -141,6 +142,8 @@ pub enum EmbedderMsg { | |||
| LoadComplete(TopLevelBrowsingContextId), | |||
| /// A pipeline panicked. First string is the reason, second one is the backtrace. | |||
| Panic(TopLevelBrowsingContextId, String, Option<String>), | |||
| /// Open file dialog to select files | |||
This comment has been minimized.
This comment has been minimized.
| ui: &UI) | ||
| where UI: UIProvider, | ||
| { | ||
| #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 3, 2018
Contributor
I don't think we have to make a distinction between the platforms here. Let send a message to the embedder no matter the platform, and let the embedder decide what to do depending on the platform.
| @@ -1076,6 +1077,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> | |||
| FromCompositorMsg::SetCursor(cursor) => { | |||
| self.handle_set_cursor_msg(cursor) | |||
| } | |||
| FromCompositorMsg::OpenFileSelectDialog(patterns, multiple_files, sender) => { | |||
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 3, 2018
Contributor
Having to use FromCompositorMsg is unfortunate. Maybe a Request::Script might be better? Or even its own type of request.
@paulrouget I haven't tried but it may possible, mostly I tried follow steps in original issue #20428 's |
|
So far, only the constellation talks to the embedder via EmbedderMsg. So maybe let's keep it the way you did. |
|
@paulrouget appreciate for feedback, I tried to update PR as suggested
If there are things need to be corrected, I'll update per suggestions. |
c45873d
to
61a2b73
|
Sorry. Was away for a while. I'll look at this again soon. |
|
no worries. |
|
I had a quick chat with @cbrewster and we agree that it's fine if the script thread has access to the EmbedderProxy. We could short-circuit the constellation. |
|
So I'd really like to see how that would work if we were to share the embedder proxy with the script thread. Sorry, changed my mind again :| |
| @@ -141,6 +142,8 @@ pub enum EmbedderMsg { | |||
| LoadComplete(TopLevelBrowsingContextId), | |||
| /// A pipeline panicked. First string is the reason, second one is the backtrace. | |||
| Panic(TopLevelBrowsingContextId, String, Option<String>), | |||
| /// Open file dialog to select files. Set boolean flag to true allows to select multiple files. | |||
| GetSelectedFiles(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>), | |||
This comment has been minimized.
This comment has been minimized.
| self.embedder_proxy.send(msg); | ||
| } | ||
| } | ||
| } |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 10, 2018
Contributor
If we are forwarding a message, maybe we want to keep the same name.
Also, I talked to @cbrewster and we agree that maybe it's better to give access to the EmbedderProxy to each script thread.
| fn platform_get_selected_files(_patterns: Vec<FilterPattern>, | ||
| _multiple_files: bool, | ||
| sender: IpcSender<Option<Vec<String>>>) { | ||
| sender.send(None); |
This comment has been minimized.
This comment has been minimized.
|
I'll try to update short-curcuit as suggested. Due to personal schedules I may need some time to wrap things up, once done will ping via @-mention here. |
fcb7bcc
to
c9b656f
|
@paulrouget Updated PR as suggested,
|
|
This feels a lot better! I think we made the right decision to use the embedder proxy. A few neats and then I think we good to go. Thank you. |
| @@ -546,7 +546,8 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> | |||
| STF: ScriptThreadFactory<Message=Message> | |||
| { | |||
| /// Create a new constellation thread. | |||
| pub fn start(state: InitialConstellationState) -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) { | |||
| pub fn start(state: InitialConstellationState) | |||
| -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) { | |||
This comment has been minimized.
This comment has been minimized.
| thread::Builder::new().name("select files".to_owned()).spawn(move || { | ||
| store.select_files(filter, sender, origin, opt_test_paths, ui); | ||
| store.select_files(filter, sender, origin, opt_test_paths, embedder ); |
This comment has been minimized.
This comment has been minimized.
| embedder_proxy: EmbedderProxy) -> Option<Vec<String>> { | ||
| if opts::get().headless { | ||
| return None; | ||
| } |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 16, 2018
Contributor
Can you let the embedder take the decision to return None when we run in headless mode?
This comment has been minimized.
This comment has been minimized.
| ui: &UI) | ||
| where UI: UIProvider, | ||
| { | ||
| fn get_selected_files(&self, |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 16, 2018
Contributor
Neat: Maybe rename get_selected_files to query_files_from_embedder.
| [[test]] | ||
| name = "main" | ||
| path = "tests/main.rs" | ||
|
|
This comment has been minimized.
This comment has been minimized.
| @@ -118,7 +118,8 @@ fn test_fetch_blob() { | |||
| use ipc_channel::ipc; | |||
| use net_traits::blob_url_store::BlobBuf; | |||
|
|
|||
| let context = new_fetch_context(None); | |||
| //let (sender, _receiver) = ipc::channel().unwrap(); | |||
This comment has been minimized.
This comment has been minimized.
| #[test] | ||
| fn test_filemanager() { | ||
| let filemanager = FileManager::new(); | ||
| let filemanager = FileManager::new(create_embedder_proxy()); | ||
| PREFS.set("dom.testing.htmlinputelement.select_files.enabled", PrefValue::Boolean(true)); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
kwonoj
Apr 16, 2018
Author
Contributor
Previously there was mock UI provider in filemanager thread does inject test files instead (https://github.com/servo/servo/pull/20480/files#diff-5a65a0caa6da8aa6e23da0a4101c6a86L19) regardless of testing prefs. Now changed code path removes UI provider from thread and always asks to embedder message, so setting up test to mock fixture for file selection.
| pub enum FileManagerMsg { | ||
| /// Requesting to open file select dialog | ||
| OpenFileSelectDialog(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>) | ||
| } |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 16, 2018
Contributor
I might have missed something, but is that message actually used somewhere?
This comment has been minimized.
This comment has been minimized.
kwonoj
Apr 16, 2018
Author
Contributor
No, I guess it's my mistake leftover while refactoring. Thanks for catching.
| let msg = EmbedderMsg::SelectFiles(patterns, multiple_files, ipc_sender); | ||
|
|
||
| embedder_proxy.send(msg); | ||
| ipc_receiver.recv().unwrap() |
This comment has been minimized.
This comment has been minimized.
paulrouget
Apr 16, 2018
Contributor
Catch the error here:
match ipc_receiver.recv() {
Err(e) => warn!("Failed to receive files from emebdder ({}).", e),
...
}
|
|
|
@bors-servo r=paulrouget |
|
|
refactor(net): removes direct ui invocation from filemgr thread <!-- Please describe your changes on the following line: --> - relates to #20428. This PR tries to refactor `net::filemanager_thread` implementation, removes direct ui-related code invocation but ask constellation. I believe overall organization might need to be refactored still as I took my own liberty to wire up dots and dots between components, which could be non-recommended practices. Probably point of review / need to be updated are 1. Communication between components Currently it's wired as like below: ``` +----------------+ +---------------+ +---------+ | | constellationMsg | | embedderMsg | | | filemgr_thread +------------------->+ constellation +------------->+ browser | | | | | | | +-----+----------+ +---------------+ +----+----+ ^ | +-------------------------------------------------------------------+ filelist: Vec(String) ``` - is this feasible approach? - does organization of message / fn (where to put consteallation / embedder msg & fns) are legit? 2. Removal of `filemanger_thread::UIProvider` - As filemanager_thread no longer need to aware actual ui, this PR removes `UIProvider` completely and let invoke tinyfiledialog directly in message listener. Maybe UIProvider itself still being needed? 3. Overall fn organization - To reduce duplicated code it takes single msg with boolean flag to distinguish selecting multiple files, may feasible / or better to create explicit paths between two. 4. Invoking tfd in a separate thread - This was mainly to align behavior to previous implentation, where tfd was invoked inside of filemanager_thread so does not block main. It may possibly just let block instead. and of course, a lot of other codes need to follow better practices. --- <!-- 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 #20428 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ - Manually verified file picker `<input type=files>` can pick up files. <!-- 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/20480) <!-- Reviewable:end -->
|
|
kwonoj commentedMar 30, 2018
•
edited
This PR tries to refactor
net::filemanager_threadimplementation, removes direct ui-related code invocation but ask constellation. I believe overall organization might need to be refactored still as I took my own liberty to wire up dots and dots between components, which could be non-recommended practices.Probably point of review / need to be updated are
Currently it's wired as like below:
filemanger_thread::UIProviderUIProvidercompletely and let invoke tinyfiledialog directly in message listener. Maybe UIProvider itself still being needed?and of course, a lot of other codes need to follow better practices.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errors<input type=files>can pick up files.This change is