Commit 148e6caa authored by Shengfa Lin's avatar Shengfa Lin Committed by Commit Bot

[chromedriver] Gracefully shutdown to save user data

If user data needs to be saved after shut down, call Chrome DevTools Protocol
browser.close. If browser.close failed, call KillProcess.
Do not call closeWebview when only one window left.

Bug: chromedriver:3370
Change-Id: I9022500332e0f971d9535ae2117c88f577144c5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283057Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Shengfa Lin <shengfa@google.com>
Cr-Commit-Position: refs/heads/master@{#786344}
parent 437f51e8
......@@ -196,7 +196,19 @@ Status ChromeDesktopImpl::QuitImpl() {
bool kill_gracefully = !user_data_dir_.IsValid();
// If the Chrome session is being run with --log-net-log, send SIGTERM first
// to allow Chrome to write out all the net logs to the log path.
kill_gracefully |= command_.HasSwitch("log-net-log");
kill_gracefully = kill_gracefully || command_.HasSwitch("log-net-log");
if (kill_gracefully) {
Status status = devtools_websocket_client_->ConnectIfNecessary();
if (status.IsOk()) {
status = devtools_websocket_client_->SendCommandAndIgnoreResponse(
"Browser.close", base::DictionaryValue());
// If status is not okay, we will try the old method of KillProcess
if (status.IsOk() && process_.WaitForExitWithTimeout(
base::TimeDelta::FromSeconds(10), nullptr))
return status;
}
}
if (!KillProcess(process_, kill_gracefully))
return Status(kUnknownError,
base::StringPrintf("cannot kill %s", kBrowserShortName));
......
......@@ -682,16 +682,20 @@ Status ExecuteClose(Session* session,
return Status(kUnexpectedAlertOpen, "{Alert text : " + alert_text + "}");
}
status = session->chrome->CloseWebView(web_view->GetId());
if (status.IsError())
return status;
if (!is_last_web_view) {
status = session->chrome->CloseWebView(web_view->GetId());
if (status.IsError())
return status;
status = ExecuteGetWindowHandles(session, base::DictionaryValue(), value);
if ((status.code() == kChromeNotReachable && is_last_web_view) ||
(status.IsOk() && (*value)->GetList().empty())) {
// If the only open window was closed, close is the same as calling "quit".
status = ExecuteGetWindowHandles(session, base::DictionaryValue(), value);
if (status.IsError())
return status;
} else {
// If there is only one open window, close is the same as calling "quit".
session->quit = true;
return session->chrome->Quit();
status = session->chrome->Quit();
if (status.IsOk())
value->reset(new base::ListValue());
}
return status;
......
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