Index: remoting/client/jni/chromoting_jni_runtime.cc |
diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc |
index 60a8128e6b3ad2734a5a9a8670b4d75fe6bc11a5..358cba4270965293e0e679734c0e1fd47594c751 100644 |
--- a/remoting/client/jni/chromoting_jni_runtime.cc |
+++ b/remoting/client/jni/chromoting_jni_runtime.cc |
@@ -27,6 +27,10 @@ namespace { |
const int kBytesPerPixel = 4; |
+remoting::ChromotingJniInstance* GetSession() { |
Sergey Ulanov
2014/07/24 02:47:02
nit: Move this inside the remoting namespace below
Lambros
2014/07/26 00:42:35
Removed.
|
+ return remoting::ChromotingJniRuntime::GetInstance()->session(); |
+} |
+ |
} // namespace |
namespace remoting { |
@@ -97,13 +101,17 @@ static void AuthenticationResponse(JNIEnv* env, |
jstring pin, |
jboolean createPair, |
jstring deviceName) { |
- remoting::ChromotingJniRuntime::GetInstance()->session()->ProvideSecret( |
- ConvertJavaStringToUTF8(env, pin).c_str(), createPair, |
- ConvertJavaStringToUTF8(env, deviceName)); |
+ if (GetSession()) { |
Sergey Ulanov
2014/07/24 02:47:02
I think it's better to check that the session in J
Lambros
2014/07/26 00:42:35
Done.
|
+ GetSession()->ProvideSecret( |
+ ConvertJavaStringToUTF8(env, pin).c_str(), createPair, |
+ ConvertJavaStringToUTF8(env, deviceName)); |
+ } |
} |
static void ScheduleRedraw(JNIEnv* env, jclass clazz) { |
- remoting::ChromotingJniRuntime::GetInstance()->session()->RedrawDesktop(); |
+ if (GetSession()) { |
+ GetSession()->RedrawDesktop(); |
+ } |
} |
static void SendMouseEvent(JNIEnv* env, |
@@ -115,45 +123,55 @@ static void SendMouseEvent(JNIEnv* env, |
// Button must be within the bounds of the MouseEvent_MouseButton enum. |
DCHECK(whichButton >= 0 && whichButton < 5); |
- remoting::ChromotingJniRuntime::GetInstance()->session()->SendMouseEvent( |
- x, y, |
- static_cast<remoting::protocol::MouseEvent_MouseButton>(whichButton), |
- buttonDown); |
+ if (GetSession()) { |
+ GetSession()->SendMouseEvent( |
+ x, y, |
+ static_cast<remoting::protocol::MouseEvent_MouseButton>(whichButton), |
+ buttonDown); |
+ } |
} |
static void SendMouseWheelEvent(JNIEnv* env, |
jclass clazz, |
jint delta_x, |
jint delta_y) { |
- remoting::ChromotingJniRuntime::GetInstance()->session()->SendMouseWheelEvent( |
- delta_x, delta_y); |
+ if (GetSession()) { |
+ GetSession()->SendMouseWheelEvent(delta_x, delta_y); |
+ } |
} |
static jboolean SendKeyEvent(JNIEnv* env, |
- jclass clazz, |
- jint keyCode, |
- jboolean keyDown) { |
- return remoting::ChromotingJniRuntime::GetInstance()->session()->SendKeyEvent( |
- keyCode, keyDown); |
+ jclass clazz, |
+ jint keyCode, |
+ jboolean keyDown) { |
+ if (GetSession()) { |
+ return GetSession()->SendKeyEvent(keyCode, keyDown); |
+ } else { |
+ return false; |
+ } |
} |
static void SendTextEvent(JNIEnv* env, |
jclass clazz, |
jstring text) { |
- remoting::ChromotingJniRuntime::GetInstance()->session()->SendTextEvent( |
- ConvertJavaStringToUTF8(env, text)); |
+ if (GetSession()) { |
+ GetSession()->SendTextEvent(ConvertJavaStringToUTF8(env, text)); |
+ } |
} |
static void OnThirdPartyTokenFetched(JNIEnv* env, |
jclass clazz, |
jstring token, |
jstring shared_secret) { |
- ChromotingJniRuntime* runtime = remoting::ChromotingJniRuntime::GetInstance(); |
- runtime->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
- &ChromotingJniInstance::HandleOnThirdPartyTokenFetched, |
- runtime->session(), |
- ConvertJavaStringToUTF8(env, token), |
- ConvertJavaStringToUTF8(env, shared_secret))); |
+ if (GetSession()) { |
+ ChromotingJniRuntime* runtime = |
+ remoting::ChromotingJniRuntime::GetInstance(); |
+ runtime->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
+ &ChromotingJniInstance::HandleOnThirdPartyTokenFetched, |
+ runtime->session(), |
+ ConvertJavaStringToUTF8(env, token), |
+ ConvertJavaStringToUTF8(env, shared_secret))); |
+ } |
} |
// ChromotingJniRuntime implementation. |
@@ -209,12 +227,12 @@ ChromotingJniRuntime::~ChromotingJniRuntime() { |
} |
void ChromotingJniRuntime::ConnectToHost(const char* username, |
- const char* auth_token, |
- const char* host_jid, |
- const char* host_id, |
- const char* host_pubkey, |
- const char* pairing_id, |
- const char* pairing_secret) { |
+ const char* auth_token, |
+ const char* host_jid, |
+ const char* host_id, |
+ const char* host_pubkey, |
+ const char* pairing_id, |
+ const char* pairing_secret) { |
DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
DCHECK(!session_); |
session_ = new ChromotingJniInstance(this, |
@@ -240,6 +258,16 @@ void ChromotingJniRuntime::ReportConnectionStatus( |
protocol::ErrorCode error) { |
DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
+ switch (state) { |
+ case protocol::ConnectionToHost::CLOSED: |
+ case protocol::ConnectionToHost::FAILED: |
+ // If the session has become disconnected, ensure that |session_| gets |
+ // cleaned up. |
+ DisconnectFromHost(); |
Sergey Ulanov
2014/07/24 02:47:02
Can the Java layer call Disconnect() when the host
Lambros
2014/07/26 00:42:35
Done.
|
+ break; |
+ default: |
+ break; |
+ } |
JNIEnv* env = base::android::AttachCurrentThread(); |
Java_JniInterface_reportConnectionStatus(env, state, error); |
} |