Chromium Code Reviews| Index: components/spellcheck/browser/spellchecker_session_bridge_android.cc |
| diff --git a/components/spellcheck/browser/spellchecker_session_bridge_android.cc b/components/spellcheck/browser/spellchecker_session_bridge_android.cc |
| index a34425de098444ed442fa300d9765559c830c7e4..245bc61f3f7ea584a365f52f88212ebd3f510172 100644 |
| --- a/components/spellcheck/browser/spellchecker_session_bridge_android.cc |
| +++ b/components/spellcheck/browser/spellchecker_session_bridge_android.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/android/jni_string.h" |
| #include "components/spellcheck/common/spellcheck_messages.h" |
| #include "components/spellcheck/common/spellcheck_result.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "jni/SpellCheckerSessionBridge_jni.h" |
| @@ -20,7 +21,11 @@ SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) |
| : render_process_id_(render_process_id), |
| java_object_initialization_failed_(false) {} |
| -SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {} |
| +SpellCheckerSessionBridge::~SpellCheckerSessionBridge() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + // Clean-up java side to avoid any stale JNI callbacks. |
| + DisconnectSession(); |
| +} |
| // static |
| bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) { |
| @@ -101,7 +106,15 @@ void SpellCheckerSessionBridge::ProcessSpellCheckResults( |
| } |
| void SpellCheckerSessionBridge::DisconnectSession() { |
|
Tobias Sargeant
2016/09/30 14:13:21
If there's an active request at this point that we
timvolodine
2016/09/30 14:46:00
Don't think we need to send an (empty?) IPC in the
|
| - java_object_.Reset(); |
| + // Needs to be executed on the same thread as the RequestTextCheck and |
| + // ProcessSpellCheckResults methods, which is the UI thread. |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + |
| + if (!java_object_.is_null()) { |
| + Java_SpellCheckerSessionBridge_disconnect( |
| + base::android::AttachCurrentThread(), java_object_); |
| + java_object_.Reset(); |
| + } |
| } |
| SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( |