| OLD | NEW |
| 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.json.JSONArray; | 7 import org.json.JSONArray; |
| 8 import org.json.JSONException; | 8 import org.json.JSONException; |
| 9 import org.json.JSONObject; | 9 import org.json.JSONObject; |
| 10 | 10 |
| 11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
| 12 | 12 |
| 13 /** Class to represent a Host returned by {@link HostListLoader}. */ | 13 /** Class to represent a Host returned by {@link HostListLoader}. */ |
| 14 public class HostInfo { | 14 public class HostInfo { |
| 15 public final String name; | 15 public final String name; |
| 16 public final String id; | 16 public final String id; |
| 17 public final String jabberId; | 17 public final String jabberId; |
| 18 public final String publicKey; | 18 public final String publicKey; |
| 19 public final boolean isOnline; | 19 public final boolean isOnline; |
| 20 public final String hostOfflineReason; |
| 20 private final ArrayList<String> mTokenUrlPatterns; | 21 private final ArrayList<String> mTokenUrlPatterns; |
| 21 | 22 |
| 22 public HostInfo(String name, | 23 public HostInfo(String name, |
| 23 String id, | 24 String id, |
| 24 String jabberId, | 25 String jabberId, |
| 25 String publicKey, | 26 String publicKey, |
| 26 ArrayList<String> tokenUrlPatterns, | 27 ArrayList<String> tokenUrlPatterns, |
| 27 boolean isOnline) { | 28 boolean isOnline, |
| 29 String hostOfflineReason) { |
| 28 this.name = name; | 30 this.name = name; |
| 29 this.id = id; | 31 this.id = id; |
| 30 this.jabberId = jabberId; | 32 this.jabberId = jabberId; |
| 31 this.publicKey = publicKey; | 33 this.publicKey = publicKey; |
| 32 this.mTokenUrlPatterns = tokenUrlPatterns; | 34 this.mTokenUrlPatterns = tokenUrlPatterns; |
| 33 this.isOnline = isOnline; | 35 this.isOnline = isOnline; |
| 36 this.hostOfflineReason = hostOfflineReason; |
| 34 } | 37 } |
| 35 | 38 |
| 36 public ArrayList<String> getTokenUrlPatterns() { | 39 public ArrayList<String> getTokenUrlPatterns() { |
| 37 return new ArrayList<String>(mTokenUrlPatterns); | 40 return new ArrayList<String>(mTokenUrlPatterns); |
| 38 } | 41 } |
| 39 | 42 |
| 40 public static HostInfo create(JSONObject json) throws JSONException { | 43 public static HostInfo create(JSONObject json) throws JSONException { |
| 41 assert json != null; | 44 assert json != null; |
| 42 | 45 |
| 43 ArrayList<String> tokenUrlPatterns = new ArrayList<String>(); | 46 ArrayList<String> tokenUrlPatterns = new ArrayList<String>(); |
| 44 JSONArray jsonPatterns = json.optJSONArray("tokenUrlPatterns"); | 47 JSONArray jsonPatterns = json.optJSONArray("tokenUrlPatterns"); |
| 45 | 48 |
| 46 if (jsonPatterns != null) { | 49 if (jsonPatterns != null) { |
| 47 for (int i = 0; i < jsonPatterns.length(); i++) { | 50 for (int i = 0; i < jsonPatterns.length(); i++) { |
| 48 String pattern = jsonPatterns.getString(i); | 51 String pattern = jsonPatterns.getString(i); |
| 49 if (pattern != null && !pattern.isEmpty()) { | 52 if (pattern != null && !pattern.isEmpty()) { |
| 50 tokenUrlPatterns.add(pattern); | 53 tokenUrlPatterns.add(pattern); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 } | 56 } |
| 54 return new HostInfo( | 57 return new HostInfo( |
| 55 json.getString("hostName"), | 58 json.getString("hostName"), |
| 56 json.getString("hostId"), | 59 json.getString("hostId"), |
| 57 json.optString("jabberId"), | 60 json.optString("jabberId"), |
| 58 json.optString("publicKey"), | 61 json.optString("publicKey"), |
| 59 tokenUrlPatterns, | 62 tokenUrlPatterns, |
| 60 json.optString("status").equals("ONLINE")); | 63 json.optString("status").equals("ONLINE"), |
| 64 json.optString("hostOfflineReason")); |
| 61 } | 65 } |
| 62 } | 66 } |
| OLD | NEW |