OLD | NEW |
---|---|
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 Loading... | |
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 preferences.putString(prefName, recents[i]); | 329 preferences.putString(prefName, recents[i]); |
329 } | 330 } |
330 | 331 |
331 preferences.apply(); | 332 preferences.apply(); |
332 } | 333 } |
333 | 334 |
334 /** Called when the activity is finally finished. */ | 335 /** Called when the activity is finally finished. */ |
335 @Override | 336 @Override |
336 public void onDestroy() { | 337 public void onDestroy() { |
337 super.onDestroy(); | 338 super.onDestroy(); |
338 JniInterface.disconnectFromHost(); | |
339 mAccountSwitcher.destroy(); | 339 mAccountSwitcher.destroy(); |
340 if (Client.getClient() != null) { | |
341 Client.getClient().destroy(); | |
Sergey Ulanov
2016/01/30 01:03:23
keep the Client object created in connectToHost()
Lambros
2016/02/03 22:57:43
I'm not sure we should be disconnecting anyway in
| |
342 } | |
340 } | 343 } |
341 | 344 |
342 /** Called when a child Activity exits and sends a result back to this Activ ity. */ | 345 /** Called when a child Activity exits and sends a result back to this Activ ity. */ |
343 @Override | 346 @Override |
344 public void onActivityResult(int requestCode, int resultCode, Intent data) { | 347 public void onActivityResult(int requestCode, int resultCode, Intent data) { |
345 mAccountSwitcher.onActivityResult(requestCode, resultCode, data); | 348 mAccountSwitcher.onActivityResult(requestCode, resultCode, data); |
346 | 349 |
347 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR OR) { | 350 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR OR) { |
348 if (resultCode == RESULT_OK) { | 351 if (resultCode == RESULT_OK) { |
349 // User gave OAuth permission to this app (or recovered from any OAuth failure), | 352 // 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 Loading... | |
423 HostInfo host = mHosts[index]; | 426 HostInfo host = mHosts[index]; |
424 if (host.isOnline) { | 427 if (host.isOnline) { |
425 connectToHost(host); | 428 connectToHost(host); |
426 } else { | 429 } else { |
427 String tooltip = host.getHostOfflineReasonText(this); | 430 String tooltip = host.getHostOfflineReasonText(this); |
428 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); | 431 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); |
429 } | 432 } |
430 } | 433 } |
431 | 434 |
432 private void connectToHost(HostInfo host) { | 435 private void connectToHost(HostInfo host) { |
436 if (Client.getClient() != null) { | |
437 Client.getClient().destroy(); | |
438 } | |
439 | |
440 final Client client = new Client(); | |
433 mProgressIndicator = ProgressDialog.show( | 441 mProgressIndicator = ProgressDialog.show( |
434 this, | 442 this, |
435 host.name, | 443 host.name, |
436 getString(R.string.footer_connecting), | 444 getString(R.string.footer_connecting), |
437 true, | 445 true, |
438 true, | 446 true, |
439 new DialogInterface.OnCancelListener() { | 447 new DialogInterface.OnCancelListener() { |
440 @Override | 448 @Override |
441 public void onCancel(DialogInterface dialog) { | 449 public void onCancel(DialogInterface dialog) { |
442 JniInterface.disconnectFromHost(); | 450 client.destroy(); |
443 } | 451 } |
444 }); | 452 }); |
445 SessionConnector connector = new SessionConnector(this, this, mHostListL oader); | 453 SessionConnector connector = new SessionConnector(client, this, this, mH ostListLoader); |
446 mAuthenticator = new SessionAuthenticator(this, host); | 454 mAuthenticator = new SessionAuthenticator(this, client, host); |
447 connector.connectToHost(mAccount, mToken, host, mAuthenticator); | 455 connector.connectToHost(mAccount, mToken, host, mAuthenticator); |
448 } | 456 } |
449 | 457 |
450 private void refreshHostList() { | 458 private void refreshHostList() { |
451 if (mWaitingForAuthToken) { | 459 if (mWaitingForAuthToken) { |
452 return; | 460 return; |
453 } | 461 } |
454 | 462 |
455 mTriedNewAuthToken = false; | 463 mTriedNewAuthToken = false; |
456 setHostListProgressVisible(true); | 464 setHostListProgressVisible(true); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 // Unreachable, but required by Google Java style and findbugs. | 614 // Unreachable, but required by Google Java style and findbugs. |
607 assert false : "Unreached"; | 615 assert false : "Unreached"; |
608 } | 616 } |
609 | 617 |
610 if (dismissProgress && mProgressIndicator != null) { | 618 if (dismissProgress && mProgressIndicator != null) { |
611 mProgressIndicator.dismiss(); | 619 mProgressIndicator.dismiss(); |
612 mProgressIndicator = null; | 620 mProgressIndicator = null; |
613 } | 621 } |
614 } | 622 } |
615 } | 623 } |
OLD | NEW |