Chromium Code Reviews| Index: remoting/test/host_info.cc |
| diff --git a/remoting/test/host_info.cc b/remoting/test/host_info.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..678475202e08df6b6b1998abf9da1f2a9d5240b7 |
| --- /dev/null |
| +++ b/remoting/test/host_info.cc |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/test/host_info.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace remoting { |
| +namespace test { |
| + |
| +HostInfo::HostInfo() { |
| +} |
| + |
| +HostInfo::~HostInfo() { |
| +} |
| + |
| +bool HostInfo::ParseHostInfo(const base::DictionaryValue& host_info) { |
| + const base::ListValue* list_value = nullptr; |
| + |
| + // Add TokenUrlPatterns to HostInfo. |
| + if (host_info.GetList("tokenUrlPatterns", &list_value)) { |
| + int size = list_value->GetSize(); |
| + if (size > 0) { |
|
Sergey Ulanov
2015/07/09 01:25:29
if (!list_value->empty())
tonychun
2015/07/09 03:02:46
Done.
|
| + std::string token_url_pattern; |
| + for (int i = 0; i < size; ++i) { |
|
Sergey Ulanov
2015/07/09 01:25:29
iterate the list using iterator:
for (net::Value
tonychun
2015/07/09 03:02:46
Done.
|
| + list_value->GetString(i, &token_url_pattern); |
| + if (!token_url_pattern.empty()) { |
| + token_url_patterns.push_back(token_url_pattern); |
| + } |
| + } |
| + } |
| + } |
| + |
| + std::string response_status; |
| + host_info.GetString("status", &response_status); |
| + if (response_status == "ONLINE") { |
| + status = kHostStatusOnline; |
| + } else if (response_status == "OFFLINE") { |
| + status = kHostStatusOffline; |
| + } else { |
| + LOG(ERROR) << "Response Status is " << response_status; |
| + return false; |
| + } |
| + |
| + if (!host_info.GetString("hostId", &host_id)) { |
| + LOG(ERROR) << "hostId was not found in host_info"; |
| + return false; |
| + } |
| + |
| + if (!host_info.GetString("hostName", &host_name)) { |
| + LOG(ERROR) << "hostName was not found in host_info"; |
| + return false; |
| + } |
| + |
| + if (!host_info.GetString("publicKey", &public_key)) { |
| + LOG(ERROR) << "publicKey was not found for " << host_name; |
| + return false; |
| + } |
| + |
| + // If the host entry was created but the host was never online, then the jid |
| + // is never set. |
| + if (!host_info.GetString("jabberId", &host_jid)) { |
| + LOG(INFO) << "jabberId was not found for " << host_name; |
|
Sergey Ulanov
2015/07/09 20:15:14
Don't really need this message. JID is useless if
tonychun
2015/07/09 20:32:34
Done.
|
| + if (status == kHostStatusOnline) { |
| + LOG(ERROR) << host_name << " is online but is missing a jabberId"; |
| + return false; |
| + } |
| + } |
| + |
| + // If the host was never running or if it was started and it's still running, |
| + // then the hostOfflineReason will not be set. It is only set after the host |
| + // goes offline. |
| + if (!host_info.GetString("hostOfflineReason", &offline_reason)) { |
| + LOG(INFO) << "hostOfflineReason was not found for " << host_name; |
|
Sergey Ulanov
2015/07/09 20:15:14
I don't think you really need this - there will be
tonychun
2015/07/09 20:32:34
Done.
|
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace test |
| +} // namespace remoting |