Commit d0a1c9e3 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[Spellchecker] Clear RequestTextCheckCallback safely in case Java object initialization fails

Mojo doesn't allow removing an uncalled mojo callback while the message pipe is
still open.

On Android, SpellCheckerSessionBridge::RequestTextCheck() discards an incoming
request if it fails to initialize the Java object. In this case, this patch replies
the request with empty result so Mojo requirements are ensured.

Bug: 848483
Change-Id: Ic4e1528dd65d152ad522aa3eb49c76f90a4e66b9
Reviewed-on: https://chromium-review.googlesource.com/1093962Reviewed-by: default avatarRachel Blum <groby@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567813}
parent aaa348eb
...@@ -38,6 +38,12 @@ void SpellCheckerSessionBridge::RequestTextCheck( ...@@ -38,6 +38,12 @@ void SpellCheckerSessionBridge::RequestTextCheck(
const base::string16& text, const base::string16& text,
RequestTextCheckCallback callback) { RequestTextCheckCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// This allows us to discard |callback| safely in case it's not run due to
// failures in initialization of |java_object_|.
std::unique_ptr<SpellingRequest> incoming_request =
std::make_unique<SpellingRequest>(text, std::move(callback));
// SpellCheckerSessionBridge#create() will return null if spell checker // SpellCheckerSessionBridge#create() will return null if spell checker
// service is unavailable. // service is unavailable.
if (java_object_initialization_failed_) { if (java_object_initialization_failed_) {
...@@ -71,11 +77,11 @@ void SpellCheckerSessionBridge::RequestTextCheck( ...@@ -71,11 +77,11 @@ void SpellCheckerSessionBridge::RequestTextCheck(
// If multiple requests arrive during one active request, only the most // If multiple requests arrive during one active request, only the most
// recent request will run (the others get overwritten). // recent request will run (the others get overwritten).
if (active_request_) { if (active_request_) {
pending_request_.reset(new SpellingRequest(text, std::move(callback))); pending_request_ = std::move(incoming_request);
return; return;
} }
active_request_.reset(new SpellingRequest(text, std::move(callback))); active_request_ = std::move(incoming_request);
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_SpellCheckerSessionBridge_requestTextCheck( Java_SpellCheckerSessionBridge_requestTextCheck(
......
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