Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / test / host_info.cc
blob1370011a4a97871e8e603c35dd266c47758e7e15
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.
5 #include "remoting/protocol/authentication_method.h"
6 #include "remoting/test/host_info.h"
8 #include "base/logging.h"
10 namespace remoting {
11 namespace test {
13 HostInfo::HostInfo() {
16 HostInfo::~HostInfo() {
19 bool HostInfo::ParseHostInfo(const base::DictionaryValue& host_info) {
20 const base::ListValue* list_value = nullptr;
22 // Add TokenUrlPatterns to HostInfo.
23 if (host_info.GetList("tokenUrlPatterns", &list_value)) {
24 if (!list_value->empty()) {
25 for (base::Value* item : *list_value) {
26 std::string token_url_pattern;
27 if (!item->GetAsString(&token_url_pattern)) {
28 return false;
30 token_url_patterns.push_back(token_url_pattern);
35 std::string response_status;
36 host_info.GetString("status", &response_status);
37 if (response_status == "ONLINE") {
38 status = kHostStatusOnline;
39 } else if (response_status == "OFFLINE") {
40 status = kHostStatusOffline;
41 } else {
42 LOG(ERROR) << "Response Status is " << response_status;
43 return false;
46 if (!host_info.GetString("hostId", &host_id)) {
47 LOG(ERROR) << "hostId was not found in host_info";
48 return false;
51 if (!host_info.GetString("hostName", &host_name)) {
52 LOG(ERROR) << "hostName was not found in host_info";
53 return false;
56 if (!host_info.GetString("publicKey", &public_key)) {
57 LOG(ERROR) << "publicKey was not found for " << host_name;
58 return false;
61 // If the host entry was created but the host was never online, then the jid
62 // is never set.
63 if (!host_info.GetString("jabberId", &host_jid) &&
64 status == kHostStatusOnline) {
65 LOG(ERROR) << host_name << " is online but is missing a jabberId";
66 return false;
69 host_info.GetString("hostOfflineReason", &offline_reason);
71 return true;
74 bool HostInfo::IsReadyForConnection() const {
75 return !host_jid.empty() && status == kHostStatusOnline;
78 ConnectionSetupInfo HostInfo::GenerateConnectionSetupInfo(
79 const std::string& access_token,
80 const std::string& user_name,
81 const std::string& pin) const {
82 ConnectionSetupInfo connection_setup_info;
83 connection_setup_info.access_token = access_token;
84 connection_setup_info.host_id = host_id;
85 connection_setup_info.host_jid = host_jid;
86 connection_setup_info.host_name = host_name;
87 connection_setup_info.pin = pin;
88 connection_setup_info.public_key = public_key;
89 connection_setup_info.user_name = user_name;
91 connection_setup_info.auth_methods.push_back(
92 protocol::AuthenticationMethod::Spake2Pair());
93 connection_setup_info.auth_methods.push_back(
94 protocol::AuthenticationMethod::Spake2(
95 protocol::AuthenticationMethod::HashFunction::NONE));
96 connection_setup_info.auth_methods.push_back(
97 protocol::AuthenticationMethod::Spake2(
98 protocol::AuthenticationMethod::HashFunction::HMAC_SHA256));
99 connection_setup_info.auth_methods.push_back(
100 protocol::AuthenticationMethod::ThirdParty());
102 return connection_setup_info;
105 } // namespace test
106 } // namespace remoting