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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.app.ProgressDialog; 9 import android.app.ProgressDialog;
10 import android.content.DialogInterface; 10 import android.content.DialogInterface;
(...skipping 18 matching lines...) Expand all
29 import android.widget.LinearLayout; 29 import android.widget.LinearLayout;
30 import android.widget.ListView; 30 import android.widget.ListView;
31 import android.widget.Toast; 31 import android.widget.Toast;
32 32
33 import org.chromium.base.ApiCompatibilityUtils; 33 import org.chromium.base.ApiCompatibilityUtils;
34 import org.chromium.base.Log; 34 import org.chromium.base.Log;
35 import org.chromium.chromoting.accountswitcher.AccountSwitcher; 35 import org.chromium.chromoting.accountswitcher.AccountSwitcher;
36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; 36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory;
37 import org.chromium.chromoting.help.HelpContext; 37 import org.chromium.chromoting.help.HelpContext;
38 import org.chromium.chromoting.help.HelpSingleton; 38 import org.chromium.chromoting.help.HelpSingleton;
39 import org.chromium.chromoting.jni.Client;
39 import org.chromium.chromoting.jni.ConnectionListener; 40 import org.chromium.chromoting.jni.ConnectionListener;
40 import org.chromium.chromoting.jni.JniInterface; 41 import org.chromium.chromoting.jni.JniInterface;
41 42
42 import java.util.ArrayList; 43 import java.util.ArrayList;
43 import java.util.Arrays; 44 import java.util.Arrays;
44 45
45 /** 46 /**
46 * The user interface for querying and displaying a user's host list from the di rectory server. It 47 * The user interface for querying and displaying a user's host list from the di rectory server. It
47 * also requests and renews authentication tokens using the system account manag er. 48 * also requests and renews authentication tokens using the system account manag er.
48 */ 49 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 * while a token is being fetched. 111 * while a token is being fetched.
111 */ 112 */
112 private boolean mWaitingForAuthToken = false; 113 private boolean mWaitingForAuthToken = false;
113 114
114 private DrawerLayout mDrawerLayout; 115 private DrawerLayout mDrawerLayout;
115 116
116 private ActionBarDrawerToggle mDrawerToggle; 117 private ActionBarDrawerToggle mDrawerToggle;
117 118
118 private AccountSwitcher mAccountSwitcher; 119 private AccountSwitcher mAccountSwitcher;
119 120
121 /** The currently-connected Client, if any. */
122 private Client mClient;
123
120 /** Shows a warning explaining that a Google account is required, then close s the activity. */ 124 /** Shows a warning explaining that a Google account is required, then close s the activity. */
121 private void showNoAccountsDialog() { 125 private void showNoAccountsDialog() {
122 AlertDialog.Builder builder = new AlertDialog.Builder(this); 126 AlertDialog.Builder builder = new AlertDialog.Builder(this);
123 builder.setMessage(R.string.noaccounts_message); 127 builder.setMessage(R.string.noaccounts_message);
124 builder.setPositiveButton(R.string.noaccounts_add_account, 128 builder.setPositiveButton(R.string.noaccounts_add_account,
125 new DialogInterface.OnClickListener() { 129 new DialogInterface.OnClickListener() {
126 @SuppressLint("InlinedApi") 130 @SuppressLint("InlinedApi")
127 @Override 131 @Override
128 public void onClick(DialogInterface dialog, int id) { 132 public void onClick(DialogInterface dialog, int id) {
129 Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT); 133 Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 preferences.putString(prefName, recents[i]); 346 preferences.putString(prefName, recents[i]);
343 } 347 }
344 348
345 preferences.apply(); 349 preferences.apply();
346 } 350 }
347 351
348 /** Called when the activity is finally finished. */ 352 /** Called when the activity is finally finished. */
349 @Override 353 @Override
350 public void onDestroy() { 354 public void onDestroy() {
351 super.onDestroy(); 355 super.onDestroy();
352 JniInterface.disconnectFromHost();
353 mAccountSwitcher.destroy(); 356 mAccountSwitcher.destroy();
357
358 // TODO(lambroslambrou): Determine whether we really need to tear down t he connection here,
359 // so we can remove this code.
360 if (mClient != null) {
361 mClient.destroy();
362 mClient = null;
363 }
354 } 364 }
355 365
356 /** Called when a child Activity exits and sends a result back to this Activ ity. */ 366 /** Called when a child Activity exits and sends a result back to this Activ ity. */
357 @Override 367 @Override
358 public void onActivityResult(int requestCode, int resultCode, Intent data) { 368 public void onActivityResult(int requestCode, int resultCode, Intent data) {
359 mAccountSwitcher.onActivityResult(requestCode, resultCode, data); 369 mAccountSwitcher.onActivityResult(requestCode, resultCode, data);
360 370
361 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR OR) { 371 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR OR) {
362 if (resultCode == RESULT_OK) { 372 if (resultCode == RESULT_OK) {
363 // User gave OAuth permission to this app (or recovered from any OAuth failure), 373 // User gave OAuth permission to this app (or recovered from any OAuth failure),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 HostInfo host = mHosts[index]; 447 HostInfo host = mHosts[index];
438 if (host.isOnline) { 448 if (host.isOnline) {
439 connectToHost(host); 449 connectToHost(host);
440 } else { 450 } else {
441 String tooltip = host.getHostOfflineReasonText(this); 451 String tooltip = host.getHostOfflineReasonText(this);
442 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); 452 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show();
443 } 453 }
444 } 454 }
445 455
446 private void connectToHost(HostInfo host) { 456 private void connectToHost(HostInfo host) {
457 if (mClient != null) {
458 mClient.destroy();
459 }
460
461 mClient = new Client();
447 mProgressIndicator = ProgressDialog.show( 462 mProgressIndicator = ProgressDialog.show(
448 this, 463 this,
449 host.name, 464 host.name,
450 getString(R.string.footer_connecting), 465 getString(R.string.footer_connecting),
451 true, 466 true,
452 true, 467 true,
453 new DialogInterface.OnCancelListener() { 468 new DialogInterface.OnCancelListener() {
454 @Override 469 @Override
455 public void onCancel(DialogInterface dialog) { 470 public void onCancel(DialogInterface dialog) {
456 JniInterface.disconnectFromHost(); 471 if (mClient != null) {
472 mClient.destroy();
473 mClient = null;
474 }
457 } 475 }
458 }); 476 });
459 SessionConnector connector = new SessionConnector(this, this, mHostListL oader); 477
460 mAuthenticator = new SessionAuthenticator(this, host); 478 SessionConnector connector = new SessionConnector(mClient, this, this, m HostListLoader);
479 mAuthenticator = new SessionAuthenticator(this, mClient, host);
461 connector.connectToHost(mAccount, mToken, host, mAuthenticator, 480 connector.connectToHost(mAccount, mToken, host, mAuthenticator,
462 getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_F LAGS, "")); 481 getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_F LAGS, ""));
463 } 482 }
464 483
465 private void refreshHostList() { 484 private void refreshHostList() {
466 if (mWaitingForAuthToken) { 485 if (mWaitingForAuthToken) {
467 return; 486 return;
468 } 487 }
469 488
470 mTriedNewAuthToken = false; 489 mTriedNewAuthToken = false;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // Unreachable, but required by Google Java style and findbugs. 640 // Unreachable, but required by Google Java style and findbugs.
622 assert false : "Unreached"; 641 assert false : "Unreached";
623 } 642 }
624 643
625 if (dismissProgress && mProgressIndicator != null) { 644 if (dismissProgress && mProgressIndicator != null) {
626 mProgressIndicator.dismiss(); 645 mProgressIndicator.dismiss();
627 mProgressIndicator = null; 646 mProgressIndicator = null;
628 } 647 }
629 } 648 }
630 } 649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698