Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: remoting/android/java/src/org/chromium/chromoting/Chromoting.java

Issue 1537183002: Refactor Chromoting JNI code to use jni/Client (Java changes only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress FindBugs warning Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/Chromoting.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
index a10a17f43925f270b5305a27a3ee3f23d1865f13..f53926c37c75c294b40accc15849d6382199a722 100644
--- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
+++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
@@ -36,6 +36,7 @@ import org.chromium.chromoting.accountswitcher.AccountSwitcher;
import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory;
import org.chromium.chromoting.help.HelpContext;
import org.chromium.chromoting.help.HelpSingleton;
+import org.chromium.chromoting.jni.Client;
import org.chromium.chromoting.jni.ConnectionListener;
import org.chromium.chromoting.jni.JniInterface;
@@ -117,6 +118,9 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
private AccountSwitcher mAccountSwitcher;
+ /** The currently-connected Client, if any. */
+ private Client mClient;
+
/** Shows a warning explaining that a Google account is required, then closes the activity. */
private void showNoAccountsDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -349,8 +353,14 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
@Override
public void onDestroy() {
super.onDestroy();
- JniInterface.disconnectFromHost();
mAccountSwitcher.destroy();
+
+ // TODO(lambroslambrou): Determine whether we really need to tear down the connection here,
+ // so we can remove this code.
+ if (mClient != null) {
+ mClient.destroy();
+ mClient = null;
+ }
}
/** Called when a child Activity exits and sends a result back to this Activity. */
@@ -444,6 +454,11 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
}
private void connectToHost(HostInfo host) {
+ if (mClient != null) {
+ mClient.destroy();
+ }
+
+ mClient = new Client();
mProgressIndicator = ProgressDialog.show(
this,
host.name,
@@ -453,11 +468,15 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
- JniInterface.disconnectFromHost();
+ if (mClient != null) {
+ mClient.destroy();
+ mClient = null;
+ }
}
});
- SessionConnector connector = new SessionConnector(this, this, mHostListLoader);
- mAuthenticator = new SessionAuthenticator(this, host);
+
+ SessionConnector connector = new SessionConnector(mClient, this, this, mHostListLoader);
+ mAuthenticator = new SessionAuthenticator(this, mClient, host);
connector.connectToHost(mAccount, mToken, host, mAuthenticator,
getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_FLAGS, ""));
}

Powered by Google App Engine
This is Rietveld 408576698