Commit 5e6e9bf2 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[fuchsia] Terminate WebRunner (and its Context) when no longer needed.

This change reduces load on system resources by terminating the
webrunner and its instance of the Context (aka browser process)
when the last Component channel is disconnected.

Change-Id: If667cfa7680e02519105d8303bd734235f6180f9
Reviewed-on: https://chromium-review.googlesource.com/1208715
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589058}
parent 7abb342d
......@@ -51,8 +51,12 @@ int main(int argc, char** argv) {
base::MessageLoopForIO message_loop;
auto web_context = CreateContext();
// Run until the WebContentRunner is ready to exit.
base::RunLoop run_loop;
webrunner::WebContentRunner runner(std::move(web_context));
webrunner::WebContentRunner runner(std::move(web_context),
run_loop.QuitClosure());
base::fuchsia::ServiceDirectory* directory =
base::fuchsia::ServiceDirectory::GetDefault();
......@@ -61,7 +65,6 @@ int main(int argc, char** argv) {
base::fuchsia::ScopedServiceBinding<fuchsia::sys::Runner> runner_binding(
directory, &runner);
// Quit the process after the app manager closes the Runner connection.
runner_binding.SetOnLastClientCallback(run_loop.QuitClosure());
// The RunLoop runs until all Components have been closed, at which point the
......
......@@ -16,9 +16,12 @@
namespace webrunner {
WebContentRunner::WebContentRunner(chromium::web::ContextPtr context)
: context_(std::move(context)) {
WebContentRunner::WebContentRunner(chromium::web::ContextPtr context,
base::OnceClosure on_idle_closure)
: context_(std::move(context)),
on_idle_closure_(std::move(on_idle_closure)) {
DCHECK(context_);
DCHECK(on_idle_closure_);
}
WebContentRunner::~WebContentRunner() = default;
......@@ -36,6 +39,11 @@ void WebContentRunner::StartComponent(
void WebContentRunner::DestroyComponent(ComponentControllerImpl* component) {
controllers_.erase(controllers_.find(component));
// Quit the RunLoop if there are no more connected clients.
if (controllers_.empty() && on_idle_closure_) {
std::move(on_idle_closure_).Run();
}
}
} // namespace webrunner
......@@ -24,7 +24,10 @@ class WebContentRunner : public fuchsia::sys::Runner {
public:
// |content|: Context (e.g. persisted profile storage) under which all web
// content launched through this Runner instance will be run.
explicit WebContentRunner(chromium::web::ContextPtr context);
// |on_idle_closure|: A callback which is invoked when the WebContentRunner
// has entered an idle state and may be safely torn down.
WebContentRunner(chromium::web::ContextPtr context,
base::OnceClosure on_idle_closure);
~WebContentRunner() override;
chromium::web::Context* context() { return context_.get(); }
......@@ -43,6 +46,7 @@ class WebContentRunner : public fuchsia::sys::Runner {
chromium::web::ContextPtr context_;
std::set<std::unique_ptr<ComponentControllerImpl>, base::UniquePtrComparator>
controllers_;
base::OnceClosure on_idle_closure_;
DISALLOW_COPY_AND_ASSIGN(WebContentRunner);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment