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

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

Issue 1968283002: Implementing Host List Context Menu and Delete Feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/HostListManager.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/HostListManager.java b/remoting/android/java/src/org/chromium/chromoting/HostListManager.java
index 64fb6658cbc830d48a6b8fa1e18725b7b9721eed..5f37a9d314d8bf94e732b079b2dd79e3887e5541 100644
--- a/remoting/android/java/src/org/chromium/chromoting/HostListManager.java
+++ b/remoting/android/java/src/org/chromium/chromoting/HostListManager.java
@@ -34,12 +34,18 @@ public class HostListManager {
UNKNOWN,
}
+ public enum RequestType {
+ RETRIEVE_HOST_LIST,
+ UPDATE_HOST,
+ DELETE_HOST
+ }
+
/** Callback for receiving the host list, or getting notified of an error. */
public interface Callback {
void onHostListReceived(HostInfo[] response);
void onHostUpdated();
void onHostDeleted();
- void onError(Error error);
+ void onError(RequestType type, Error error);
}
/**
@@ -101,7 +107,7 @@ public class HostListManager {
private void doRetrieveHostList(String authToken, Callback callback) {
Response response = sendRequest(authToken, HOST_LIST_PATH, "GET", null, null);
if (response.error != null) {
- postError(callback, response.error);
+ postError(callback, RequestType.RETRIEVE_HOST_LIST, response.error);
return;
}
@@ -128,7 +134,7 @@ public class HostListManager {
} catch (JSONException ex) {
// Logging the exception stack trace may be too spammy.
Log.e(TAG, "Error parsing host list response: %s", ex.getMessage());
- postError(callback, Error.UNEXPECTED_RESPONSE);
+ postError(callback, RequestType.RETRIEVE_HOST_LIST, Error.UNEXPECTED_RESPONSE);
return;
}
@@ -148,17 +154,17 @@ public class HostListManager {
* Updates a host on the background thread. On success, callback.onHostUpdated() will be called,
* otherwise callback.onError() will be called with an error-code describing the failure.
*/
- public void putHost(final String authToken, final String hostId, final String hostName,
+ public void updateHost(final String authToken, final String hostId, final String hostName,
final String publicKey, final Callback callback) {
runOnNetworkThread(new Runnable() {
@Override
public void run() {
- doPutHost(authToken, hostId, hostName, publicKey, callback);
+ doUpdateHost(authToken, hostId, hostName, publicKey, callback);
}
});
}
- private void doPutHost(String authToken, String hostId, String hostName, String publicKey,
+ private void doUpdateHost(String authToken, String hostId, String hostName, String publicKey,
final Callback callback) {
String requestJson;
try {
@@ -171,13 +177,13 @@ public class HostListManager {
requestJson = request.toString();
} catch (JSONException ex) {
Log.e(TAG, "Error creating put host JSON string: %s", ex.getMessage());
- postError(callback, Error.UNKNOWN);
+ postError(callback, RequestType.UPDATE_HOST, Error.UNKNOWN);
return;
}
Response response = sendRequest(authToken, HOST_LIST_PATH + '/' + hostId, "PUT",
"application/json", requestJson);
if (response.error != null) {
- postError(callback, response.error);
+ postError(callback, RequestType.UPDATE_HOST, response.error);
} else {
mMainThread.post(new Runnable() {
@Override
@@ -206,7 +212,7 @@ public class HostListManager {
Response response = sendRequest(authToken, HOST_LIST_PATH + '/' + hostId, "DELETE",
null, null);
if (response.error != null) {
- postError(callback, response.error);
+ postError(callback, RequestType.DELETE_HOST, response.error);
} else {
mMainThread.post(new Runnable() {
@Override
@@ -218,13 +224,11 @@ public class HostListManager {
}
/** Posts error to callback on main thread. */
- private void postError(Callback callback, Error error) {
- final Callback callbackFinal = callback;
- final Error errorFinal = error;
+ private void postError(final Callback callback, final RequestType type, final Error error) {
mMainThread.post(new Runnable() {
@Override
public void run() {
- callbackFinal.onError(errorFinal);
+ callback.onError(type, error);
}
});
}
@@ -275,6 +279,7 @@ public class HostListManager {
int status = link.getResponseCode();
switch (status) {
case HttpURLConnection.HTTP_OK: // 200
+ case HttpURLConnection.HTTP_NO_CONTENT: // 204
break;
case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
error = Error.AUTH_FAILED;

Powered by Google App Engine
This is Rietveld 408576698