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

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

Issue 1976853002: [Remoting Android] Refactor OAuth Token Fetching Code (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
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 android.os.Handler; 7 import android.os.Handler;
8 import android.os.HandlerThread; 8 import android.os.HandlerThread;
9 import android.os.Looper; 9 import android.os.Looper;
10 10
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 266 }
267 if (requestBody != null) { 267 if (requestBody != null) {
268 byte[] requestBytes = requestBody.getBytes("UTF-8"); 268 byte[] requestBytes = requestBody.getBytes("UTF-8");
269 OutputStream outStream = link.getOutputStream(); 269 OutputStream outStream = link.getOutputStream();
270 outStream.write(requestBytes); 270 outStream.write(requestBytes);
271 outStream.close(); 271 outStream.close();
272 } 272 }
273 273
274 // Listen for the server to respond. 274 // Listen for the server to respond.
275 int status = link.getResponseCode(); 275 int status = link.getResponseCode();
276 // TODO(yuweih): Turn this switch statement into range testing. e.g. 200-299 = OK.
276 switch (status) { 277 switch (status) {
277 case HttpURLConnection.HTTP_OK: // 200 278 case HttpURLConnection.HTTP_OK: // 200
279 case HttpURLConnection.HTTP_NO_CONTENT: // 204
278 break; 280 break;
279 case HttpURLConnection.HTTP_UNAUTHORIZED: // 401 281 case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
280 error = Error.AUTH_FAILED; 282 error = Error.AUTH_FAILED;
281 break; 283 break;
282 case HttpURLConnection.HTTP_BAD_GATEWAY: // 502 284 case HttpURLConnection.HTTP_BAD_GATEWAY: // 502
283 case HttpURLConnection.HTTP_UNAVAILABLE: // 503 285 case HttpURLConnection.HTTP_UNAVAILABLE: // 503
284 error = Error.SERVICE_UNAVAILABLE; 286 error = Error.SERVICE_UNAVAILABLE;
285 break; 287 break;
286 default: 288 default:
287 error = Error.UNKNOWN; 289 error = Error.UNKNOWN;
(...skipping 15 matching lines...) Expand all
303 throw new RuntimeException("Unexpected error while fetching host lis t: ", ex); 305 throw new RuntimeException("Unexpected error while fetching host lis t: ", ex);
304 } catch (IOException ex) { 306 } catch (IOException ex) {
305 return new Response(Error.NETWORK_ERROR, null); 307 return new Response(Error.NETWORK_ERROR, null);
306 } finally { 308 } finally {
307 if (link != null) { 309 if (link != null) {
308 link.disconnect(); 310 link.disconnect();
309 } 311 }
310 } 312 }
311 } 313 }
312 } 314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698