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

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

Issue 633703004: Android Chromoting: Don't include API key with Directory request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove client_id/client_secret from request Created 6 years, 2 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 | « no previous file | 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 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 import android.util.Log; 10 import android.util.Log;
11 11
12 import org.chromium.chromoting.jni.JniInterface;
13 import org.json.JSONArray; 12 import org.json.JSONArray;
14 import org.json.JSONException; 13 import org.json.JSONException;
15 import org.json.JSONObject; 14 import org.json.JSONObject;
16 15
17 import java.io.IOException; 16 import java.io.IOException;
18 import java.net.HttpURLConnection; 17 import java.net.HttpURLConnection;
19 import java.net.MalformedURLException; 18 import java.net.MalformedURLException;
20 import java.net.URL; 19 import java.net.URL;
21 import java.util.ArrayList; 20 import java.util.ArrayList;
22 import java.util.Collections; 21 import java.util.Collections;
(...skipping 12 matching lines...) Expand all
35 } 34 }
36 35
37 /** Callback for receiving the host list, or getting notified of an error. * / 36 /** Callback for receiving the host list, or getting notified of an error. * /
38 public interface Callback { 37 public interface Callback {
39 void onHostListReceived(HostInfo[] hosts); 38 void onHostListReceived(HostInfo[] hosts);
40 void onError(Error error); 39 void onError(Error error);
41 } 40 }
42 41
43 /** Path from which to download a user's host list JSON object. */ 42 /** Path from which to download a user's host list JSON object. */
44 private static final String HOST_LIST_PATH = 43 private static final String HOST_LIST_PATH =
45 "https://www.googleapis.com/chromoting/v1/@me/hosts?key="; 44 "https://www.googleapis.com/chromoting/v1/@me/hosts";
46 45
47 /** Callback handler to be used for network operations. */ 46 /** Callback handler to be used for network operations. */
48 private Handler mNetworkThread; 47 private Handler mNetworkThread;
49 48
50 /** Handler for main thread. */ 49 /** Handler for main thread. */
51 private Handler mMainThread; 50 private Handler mMainThread;
52 51
53 public HostListLoader() { 52 public HostListLoader() {
54 // Thread responsible for downloading the host list. 53 // Thread responsible for downloading the host list.
55 54
(...skipping 23 matching lines...) Expand all
79 public void run() { 78 public void run() {
80 doRetrieveHostList(authTokenFinal, callbackFinal); 79 doRetrieveHostList(authTokenFinal, callbackFinal);
81 } 80 }
82 }); 81 });
83 } 82 }
84 83
85 private void doRetrieveHostList(String authToken, Callback callback) { 84 private void doRetrieveHostList(String authToken, Callback callback) {
86 HttpURLConnection link = null; 85 HttpURLConnection link = null;
87 String response = null; 86 String response = null;
88 try { 87 try {
89 link = (HttpURLConnection) 88 link = (HttpURLConnection) new URL(HOST_LIST_PATH).openConnection();
90 new URL(HOST_LIST_PATH + JniInterface.nativeGetApiKey()).ope nConnection();
91 link.addRequestProperty("client_id", JniInterface.nativeGetClientId( ));
92 link.addRequestProperty("client_secret", JniInterface.nativeGetClien tSecret());
93 link.setRequestProperty("Authorization", "OAuth " + authToken); 89 link.setRequestProperty("Authorization", "OAuth " + authToken);
94 90
95 // Listen for the server to respond. 91 // Listen for the server to respond.
96 int status = link.getResponseCode(); 92 int status = link.getResponseCode();
97 switch (status) { 93 switch (status) {
98 case HttpURLConnection.HTTP_OK: // 200 94 case HttpURLConnection.HTTP_OK: // 200
99 break; 95 break;
100 case HttpURLConnection.HTTP_UNAUTHORIZED: // 401 96 case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
101 postError(callback, Error.AUTH_FAILED); 97 postError(callback, Error.AUTH_FAILED);
102 return; 98 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 return a.isOnline ? -1 : 1; 184 return a.isOnline ? -1 : 1;
189 } 185 }
190 String aName = a.name.toUpperCase(Locale.getDefault()); 186 String aName = a.name.toUpperCase(Locale.getDefault());
191 String bName = b.name.toUpperCase(Locale.getDefault()); 187 String bName = b.name.toUpperCase(Locale.getDefault());
192 return aName.compareTo(bName); 188 return aName.compareTo(bName);
193 } 189 }
194 }; 190 };
195 Collections.sort(hosts, hostComparator); 191 Collections.sort(hosts, hostComparator);
196 } 192 }
197 } 193 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698