| 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 HostInfo::HostInfo(const HostInfo& other) = default; |
| 13 |
| 14 HostInfo::~HostInfo() {} |
| 15 |
| 16 bool HostInfo::ParseHostInfo(const base::DictionaryValue& host_info) { |
| 17 const base::ListValue* list_value = nullptr; |
| 18 |
| 19 // Add TokenUrlPatterns to HostInfo. |
| 20 if (host_info.GetList("tokenUrlPatterns", &list_value)) { |
| 21 if (!list_value->empty()) { |
| 22 for (const auto& item : *list_value) { |
| 23 std::string token_url_pattern; |
| 24 if (!item->GetAsString(&token_url_pattern)) { |
| 25 return false; |
| 26 } |
| 27 token_url_patterns.push_back(token_url_pattern); |
| 28 } |
| 29 } |
| 30 } |
| 31 |
| 32 std::string response_status; |
| 33 host_info.GetString("status", &response_status); |
| 34 if (response_status == "ONLINE") { |
| 35 status = kHostStatusOnline; |
| 36 } else if (response_status == "OFFLINE") { |
| 37 status = kHostStatusOffline; |
| 38 } else { |
| 39 LOG(ERROR) << "Response Status is " << response_status; |
| 40 return false; |
| 41 } |
| 42 |
| 43 if (!host_info.GetString("hostId", &host_id)) { |
| 44 LOG(ERROR) << "hostId was not found in host_info"; |
| 45 return false; |
| 46 } |
| 47 |
| 48 if (!host_info.GetString("hostName", &host_name)) { |
| 49 LOG(ERROR) << "hostName was not found in host_info"; |
| 50 return false; |
| 51 } |
| 52 |
| 53 if (!host_info.GetString("publicKey", &public_key)) { |
| 54 LOG(ERROR) << "publicKey was not found for " << host_name; |
| 55 return false; |
| 56 } |
| 57 |
| 58 // If the host entry was created but the host was never online, then the jid |
| 59 // is never set. |
| 60 if (!host_info.GetString("jabberId", &host_jid) && |
| 61 status == kHostStatusOnline) { |
| 62 LOG(ERROR) << host_name << " is online but is missing a jabberId"; |
| 63 return false; |
| 64 } |
| 65 |
| 66 host_info.GetString("hostOfflineReason", &offline_reason); |
| 67 |
| 68 return true; |
| 69 } |
| 70 |
| 71 bool HostInfo::IsReadyForConnection() const { |
| 72 return !host_jid.empty() && status == kHostStatusOnline; |
| 73 } |
| 74 |
| 75 } // namespace remoting |
| OLD | NEW |