Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/spellcheck/browser/spellchecker_session_bridge_android.h" | 5 #include "components/spellcheck/browser/spellchecker_session_bridge_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "components/spellcheck/common/spellcheck_messages.h" | 12 #include "components/spellcheck/common/spellcheck_messages.h" |
| 13 #include "components/spellcheck/common/spellcheck_result.h" | 13 #include "components/spellcheck/common/spellcheck_result.h" |
| 14 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "jni/SpellCheckerSessionBridge_jni.h" | 16 #include "jni/SpellCheckerSessionBridge_jni.h" |
| 16 | 17 |
| 17 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
| 18 | 19 |
| 19 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) | 20 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) |
| 20 : render_process_id_(render_process_id), | 21 : render_process_id_(render_process_id), |
| 21 java_object_initialization_failed_(false) {} | 22 java_object_initialization_failed_(false) {} |
| 22 | 23 |
| 23 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {} | 24 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() { |
| 25 // Needs to be destroyed on the same thread as the RequestTextCheck and | |
| 26 // ProcessSpellCheckResults are executed, which is the UI thread. | |
| 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 28 | |
| 29 if (!java_object_.is_null()) { | |
| 30 Java_SpellCheckerSessionBridge_disconnect( | |
| 31 base::android::AttachCurrentThread(), java_object_); | |
| 32 } | |
| 33 } | |
| 24 | 34 |
| 25 // static | 35 // static |
| 26 bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) { | 36 bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) { |
| 27 return RegisterNativesImpl(env); | 37 return RegisterNativesImpl(env); |
| 28 } | 38 } |
| 29 | 39 |
| 30 void SpellCheckerSessionBridge::RequestTextCheck(int route_id, | 40 void SpellCheckerSessionBridge::RequestTextCheck(int route_id, |
| 31 int identifier, | 41 int identifier, |
| 32 const base::string16& text) { | 42 const base::string16& text) { |
| 33 // SpellCheckerSessionBridge#create() will return null if spell checker | 43 // SpellCheckerSessionBridge#create() will return null if spell checker |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 content::RenderProcessHost* sender = | 95 content::RenderProcessHost* sender = |
| 86 content::RenderProcessHost::FromID(render_process_id_); | 96 content::RenderProcessHost::FromID(render_process_id_); |
| 87 | 97 |
| 88 if (sender != nullptr) { | 98 if (sender != nullptr) { |
| 89 sender->Send(new SpellCheckMsg_RespondTextCheck( | 99 sender->Send(new SpellCheckMsg_RespondTextCheck( |
| 90 active_request_->route_id, active_request_->identifier, | 100 active_request_->route_id, active_request_->identifier, |
| 91 active_request_->text, results)); | 101 active_request_->text, results)); |
| 92 } | 102 } |
| 93 | 103 |
| 94 active_request_ = std::move(pending_request_); | 104 active_request_ = std::move(pending_request_); |
| 95 if (active_request_) { | 105 if (active_request_) { |
|
Tobias Sargeant
2016/09/30 09:18:57
This should handle java_object_ being null. If it'
timvolodine
2016/09/30 13:57:54
I guess the reconnect part is 'on demand' in Reque
| |
| 96 JNIEnv* env = base::android::AttachCurrentThread(); | 106 JNIEnv* env = base::android::AttachCurrentThread(); |
| 97 Java_SpellCheckerSessionBridge_requestTextCheck( | 107 Java_SpellCheckerSessionBridge_requestTextCheck( |
| 98 env, java_object_, | 108 env, java_object_, |
| 99 base::android::ConvertUTF16ToJavaString(env, active_request_->text)); | 109 base::android::ConvertUTF16ToJavaString(env, active_request_->text)); |
| 100 } | 110 } |
| 101 } | 111 } |
| 102 | 112 |
| 103 void SpellCheckerSessionBridge::DisconnectSession() { | 113 void SpellCheckerSessionBridge::DisconnectSession() { |
| 104 java_object_.Reset(); | 114 java_object_.Reset(); |
|
Tobias Sargeant
2016/09/30 09:18:58
This also needs to call Java_SpellCheckerSessionBr
timvolodine
2016/09/30 13:57:55
yes sounds right, thanks for catching this. if we
| |
| 105 } | 115 } |
| 106 | 116 |
| 107 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( | 117 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( |
| 108 int route_id, | 118 int route_id, |
| 109 int identifier, | 119 int identifier, |
| 110 const base::string16& text) | 120 const base::string16& text) |
| 111 : route_id(route_id), identifier(identifier), text(text) {} | 121 : route_id(route_id), identifier(identifier), text(text) {} |
| 112 | 122 |
| 113 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} | 123 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} |
| OLD | NEW |