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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/SessionConnector.java

Issue 1948793002: Implement HostListManager by Refactoring HostListLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's feedback Created 4 years, 7 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
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/HostListManager.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 org.chromium.chromoting.jni.Client; 7 import org.chromium.chromoting.jni.Client;
8 import org.chromium.chromoting.jni.ConnectionListener; 8 import org.chromium.chromoting.jni.ConnectionListener;
9 9
10 /** 10 /**
11 * This class manages making a connection to a host, with logic for reloading th e host list and 11 * This class manages making a connection to a host, with logic for reloading th e host list and
12 * retrying the connection in the case of a stale host JID. 12 * retrying the connection in the case of a stale host JID.
13 */ 13 */
14 public class SessionConnector implements ConnectionListener, HostListLoader.Call back { 14 public class SessionConnector implements ConnectionListener, HostListManager.Cal lback {
15 private Client mClient; 15 private Client mClient;
16 private ConnectionListener mConnectionListener; 16 private ConnectionListener mConnectionListener;
17 private HostListLoader.Callback mHostListCallback; 17 private HostListManager.Callback mHostListCallback;
18 private HostListLoader mHostListLoader; 18 private HostListManager mHostListManager;
19 private SessionAuthenticator mAuthenticator; 19 private SessionAuthenticator mAuthenticator;
20 20
21 private String mAccountName; 21 private String mAccountName;
22 private String mAuthToken; 22 private String mAuthToken;
23 23
24 /* HostInfo for the host we are connecting to. */ 24 /* HostInfo for the host we are connecting to. */
25 private HostInfo mHost; 25 private HostInfo mHost;
26 26
27 private String mFlags; 27 private String mFlags;
28 28
29 /** 29 /**
30 * Tracks whether the connection has been established. Auto-reloading and re connecting should 30 * Tracks whether the connection has been established. Auto-reloading and re connecting should
31 * only happen if connection has not yet occurred. 31 * only happen if connection has not yet occurred.
32 */ 32 */
33 private boolean mWasConnected; 33 private boolean mWasConnected;
34 private boolean mTriedReloadingHostList; 34 private boolean mTriedReloadingHostList;
35 35
36 /** 36 /**
37 * @param connectionListener Object to be notified on connection success/fai lure. 37 * @param connectionListener Object to be notified on connection success/fai lure.
38 * @param hostListCallback Object to be notified whenever the host list is r eloaded. 38 * @param hostListCallback Object to be notified whenever the host list is r eloaded.
39 * @param hostListLoader The object used for reloading the host list. 39 * @param hostListManager The object used for reloading the host list.
40 */ 40 */
41 public SessionConnector(Client client, ConnectionListener connectionListener , 41 public SessionConnector(Client client, ConnectionListener connectionListener ,
42 HostListLoader.Callback hostListCallback, HostListLoader hostListLoa der) { 42 HostListManager.Callback hostListCallback, HostListManager hostListM anager) {
43 mClient = client; 43 mClient = client;
44 mConnectionListener = connectionListener; 44 mConnectionListener = connectionListener;
45 mHostListCallback = hostListCallback; 45 mHostListCallback = hostListCallback;
46 mHostListLoader = hostListLoader; 46 mHostListManager = hostListManager;
47 } 47 }
48 48
49 /** Initiates a connection to the host. */ 49 /** Initiates a connection to the host. */
50 public void connectToHost(String accountName, String authToken, HostInfo hos t, 50 public void connectToHost(String accountName, String authToken, HostInfo hos t,
51 SessionAuthenticator authenticator, String flags) { 51 SessionAuthenticator authenticator, String flags) {
52 mAccountName = accountName; 52 mAccountName = accountName;
53 mAuthToken = authToken; 53 mAuthToken = authToken;
54 mHost = host; 54 mHost = host;
55 mAuthenticator = authenticator; 55 mAuthenticator = authenticator;
56 mFlags = flags; 56 mFlags = flags;
(...skipping 12 matching lines...) Expand all
69 mClient.connectToHost(mAccountName, mAuthToken, mHost.jabberId, mHost.id , 69 mClient.connectToHost(mAccountName, mAuthToken, mHost.jabberId, mHost.id ,
70 mHost.publicKey, mAuthenticator, mFlags, this); 70 mHost.publicKey, mAuthenticator, mFlags, this);
71 } 71 }
72 72
73 private static boolean hostIncomplete(HostInfo host) { 73 private static boolean hostIncomplete(HostInfo host) {
74 return host.jabberId.isEmpty() || host.publicKey.isEmpty(); 74 return host.jabberId.isEmpty() || host.publicKey.isEmpty();
75 } 75 }
76 76
77 private void reloadHostListAndConnect() { 77 private void reloadHostListAndConnect() {
78 mTriedReloadingHostList = true; 78 mTriedReloadingHostList = true;
79 mHostListLoader.retrieveHostList(mAuthToken, this); 79 mHostListManager.retrieveHostList(mAuthToken, this);
80 } 80 }
81 81
82 @Override 82 @Override
83 public void onConnectionState(ConnectionListener.State state, ConnectionList ener.Error error) { 83 public void onConnectionState(ConnectionListener.State state, ConnectionList ener.Error error) {
84 switch (state) { 84 switch (state) {
85 case CONNECTED: 85 case CONNECTED:
86 mWasConnected = true; 86 mWasConnected = true;
87 break; 87 break;
88 case FAILED: 88 case FAILED:
89 // The host is offline, which may mean the JID is out of date, s o refresh the host 89 // The host is offline, which may mean the JID is out of date, s o refresh the host
(...skipping 29 matching lines...) Expand all
119 // unchanged, so report connection error to the client. 119 // unchanged, so report connection error to the client.
120 mConnectionListener.onConnectionState(ConnectionListener.State.FAILE D, 120 mConnectionListener.onConnectionState(ConnectionListener.State.FAILE D,
121 ConnectionListener.Error.PEER_IS_OFFLINE); 121 ConnectionListener.Error.PEER_IS_OFFLINE);
122 } else { 122 } else {
123 mHost = foundHost; 123 mHost = foundHost;
124 doConnect(); 124 doConnect();
125 } 125 }
126 } 126 }
127 127
128 @Override 128 @Override
129 public void onError(HostListLoader.Error error) { 129 public void onHostUpdated() {
130 // Not implemented Yet.
131 }
132
133 @Override
134 public void onHostDeleted() {
135 // Not implemented Yet.
136 }
137
138 @Override
139 public void onError(HostListManager.Error error) {
130 // Connection failed and reloading the host list also failed, so report the connection 140 // Connection failed and reloading the host list also failed, so report the connection
131 // error. 141 // error.
132 mConnectionListener.onConnectionState(ConnectionListener.State.FAILED, 142 mConnectionListener.onConnectionState(ConnectionListener.State.FAILED,
133 ConnectionListener.Error.PEER_IS_OFFLINE); 143 ConnectionListener.Error.PEER_IS_OFFLINE);
134 144
135 // Notify the caller that the host list failed to load, so the UI is upd ated accordingly. 145 // Notify the caller that the host list failed to load, so the UI is upd ated accordingly.
136 // The currently-displayed host list is not likely to be valid any more. 146 // The currently-displayed host list is not likely to be valid any more.
137 mHostListCallback.onError(error); 147 mHostListCallback.onError(error);
138 } 148 }
139 } 149 }
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/HostListManager.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698