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