| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/ios/facade/host_info.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace remoting { |
| 10 |
| 11 HostInfo::HostInfo() {} |
| 12 |
| 13 HostInfo::HostInfo(const HostInfo& other) = default; |
| 14 |
| 15 HostInfo::~HostInfo() {} |
| 16 |
| 17 bool HostInfo::ParseHostInfo(const base::DictionaryValue& host_info) { |
| 18 const base::ListValue* list_value = nullptr; |
| 19 |
| 20 // Add TokenUrlPatterns to HostInfo. |
| 21 if (host_info.GetList("tokenUrlPatterns", &list_value)) { |
| 22 if (!list_value->empty()) { |
| 23 for (const auto& item : *list_value) { |
| 24 std::string token_url_pattern; |
| 25 if (!item->GetAsString(&token_url_pattern)) { |
| 26 return false; |
| 27 } |
| 28 token_url_patterns.push_back(token_url_pattern); |
| 29 } |
| 30 } |
| 31 } |
| 32 |
| 33 std::string response_status; |
| 34 host_info.GetString("status", &response_status); |
| 35 if (response_status == "ONLINE") { |
| 36 status = kHostStatusOnline; |
| 37 } else if (response_status == "OFFLINE") { |
| 38 status = kHostStatusOffline; |
| 39 } else { |
| 40 LOG(ERROR) << "Unknown response status: " << response_status; |
| 41 return false; |
| 42 } |
| 43 |
| 44 if (!host_info.GetString("hostId", &host_id)) { |
| 45 LOG(ERROR) << "hostId was not found in host_info"; |
| 46 return false; |
| 47 } |
| 48 |
| 49 if (!host_info.GetString("hostName", &host_name)) { |
| 50 LOG(ERROR) << "hostName was not found in host_info"; |
| 51 return false; |
| 52 } |
| 53 |
| 54 if (!host_info.GetString("publicKey", &public_key)) { |
| 55 LOG(ERROR) << "publicKey was not found for " << host_name; |
| 56 return false; |
| 57 } |
| 58 |
| 59 // If the host entry was created but the host was never online, then the jid |
| 60 // is never set. |
| 61 if (!host_info.GetString("jabberId", &host_jid) && |
| 62 status == kHostStatusOnline) { |
| 63 LOG(ERROR) << host_name << " is online but is missing a jabberId"; |
| 64 return false; |
| 65 } |
| 66 |
| 67 host_info.GetString("hostOfflineReason", &offline_reason); |
| 68 |
| 69 return true; |
| 70 } |
| 71 |
| 72 bool HostInfo::IsReadyForConnection() const { |
| 73 return !host_jid.empty() && status == kHostStatusOnline; |
| 74 } |
| 75 |
| 76 } // namespace remoting |
| OLD | NEW |