Commit 02cb2dcd authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[DeviceSync v2] Consolidate CryptAuth feature type files

- Merge redundant cryptauth_better_together_feature_types.cc/h into
  cryptauth_feature_type.cc/h.
- Change the strings from camelcase to uppercase-underscore format--the
  format the CryptAuth server uses.
- Add function to convert from multidevice::SoftwareFeature to a
  feature type string. This will be needed to build
  BatchSetFeatureStatuses requests.

Bug: 951969
Change-Id: I4e516b2790edbb5ca2c08261fec3f59f35ab4994
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834062
Commit-Queue: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701714}
parent 0b3478e9
...@@ -10,8 +10,6 @@ static_library("device_sync") { ...@@ -10,8 +10,6 @@ static_library("device_sync") {
"async_execution_time_metrics_logger.h", "async_execution_time_metrics_logger.h",
"cryptauth_api_call_flow.cc", "cryptauth_api_call_flow.cc",
"cryptauth_api_call_flow.h", "cryptauth_api_call_flow.h",
"cryptauth_better_together_feature_types.cc",
"cryptauth_better_together_feature_types.h",
"cryptauth_client.h", "cryptauth_client.h",
"cryptauth_client_impl.cc", "cryptauth_client_impl.cc",
"cryptauth_client_impl.h", "cryptauth_client_impl.h",
......
// Copyright 2019 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 "chromeos/services/device_sync/cryptauth_better_together_feature_types.h"
#include "base/logging.h"
#include "base/no_destructor.h"
namespace chromeos {
namespace device_sync {
const char kCryptAuthFeatureTypeBetterTogetherHostSupported[] =
"BETTER_TOGETHER_HOST_SUPPORTED";
const char kCryptAuthFeatureTypeBetterTogetherClientSupported[] =
"BETTER_TOGETHER_CLIENT_SUPPORTED";
const char kCryptAuthFeatureTypeEasyUnlockHostSupported[] =
"EASY_UNLOCK_HOST_SUPPORTED";
const char kCryptAuthFeatureTypeEasyUnlockClientSupported[] =
"EASY_UNLOCK_CLIENT_SUPPORTED";
const char kCryptAuthFeatureTypeMagicTetherHostSupported[] =
"MAGIC_TETHER_HOST_SUPPORTED";
const char kCryptAuthFeatureTypeMagicTetherClientSupported[] =
"MAGIC_TETHER_CLIENT_SUPPORTED";
const char kCryptAuthFeatureTypeSmsConnectHostSupported[] =
"SMS_CONNECT_HOST_SUPPORTED";
const char kCryptAuthFeatureTypeSmsConnectClientSupported[] =
"SMS_CONNECT_CLIENT_SUPPORTED";
const char kCryptAuthFeatureTypeBetterTogetherHostEnabled[] =
"BETTER_TOGETHER_HOST";
const char kCryptAuthFeatureTypeBetterTogetherClientEnabled[] =
"BETTER_TOGETHER_CLIENT";
const char kCryptAuthFeatureTypeEasyUnlockHostEnabled[] = "EASY_UNLOCK_HOST";
const char kCryptAuthFeatureTypeEasyUnlockClientEnabled[] =
"EASY_UNLOCK_CLIENT";
const char kCryptAuthFeatureTypeMagicTetherHostEnabled[] = "MAGIC_TETHER_HOST";
const char kCryptAuthFeatureTypeMagicTetherClientEnabled[] =
"MAGIC_TETHER_CLIENT";
const char kCryptAuthFeatureTypeSmsConnectHostEnabled[] = "SMS_CONNECT_HOST";
const char kCryptAuthFeatureTypeSmsConnectClientEnabled[] =
"SMS_CONNECT_CLIENT";
const base::flat_set<std::string>& GetBetterTogetherFeatureTypes() {
static const base::NoDestructor<base::flat_set<std::string>> feature_set([] {
return base::flat_set<std::string>{
kCryptAuthFeatureTypeBetterTogetherHostSupported,
kCryptAuthFeatureTypeBetterTogetherClientSupported,
kCryptAuthFeatureTypeEasyUnlockHostSupported,
kCryptAuthFeatureTypeEasyUnlockClientSupported,
kCryptAuthFeatureTypeMagicTetherHostSupported,
kCryptAuthFeatureTypeMagicTetherClientSupported,
kCryptAuthFeatureTypeSmsConnectHostSupported,
kCryptAuthFeatureTypeSmsConnectClientSupported,
kCryptAuthFeatureTypeBetterTogetherHostEnabled,
kCryptAuthFeatureTypeBetterTogetherClientEnabled,
kCryptAuthFeatureTypeEasyUnlockHostEnabled,
kCryptAuthFeatureTypeEasyUnlockClientEnabled,
kCryptAuthFeatureTypeMagicTetherHostEnabled,
kCryptAuthFeatureTypeMagicTetherClientEnabled,
kCryptAuthFeatureTypeSmsConnectHostEnabled,
kCryptAuthFeatureTypeSmsConnectClientEnabled};
}());
return *feature_set;
}
const base::flat_set<std::string>& GetSupportedBetterTogetherFeatureTypes() {
static const base::NoDestructor<base::flat_set<std::string>> supported_set(
[] {
return base::flat_set<std::string>{
kCryptAuthFeatureTypeBetterTogetherHostSupported,
kCryptAuthFeatureTypeBetterTogetherClientSupported,
kCryptAuthFeatureTypeEasyUnlockHostSupported,
kCryptAuthFeatureTypeEasyUnlockClientSupported,
kCryptAuthFeatureTypeMagicTetherHostSupported,
kCryptAuthFeatureTypeMagicTetherClientSupported,
kCryptAuthFeatureTypeSmsConnectHostSupported,
kCryptAuthFeatureTypeSmsConnectClientSupported};
}());
return *supported_set;
}
const base::flat_set<std::string>& GetEnabledBetterTogetherFeatureTypes() {
static const base::NoDestructor<base::flat_set<std::string>> enabled_set([] {
return base::flat_set<std::string>{
kCryptAuthFeatureTypeBetterTogetherHostEnabled,
kCryptAuthFeatureTypeBetterTogetherClientEnabled,
kCryptAuthFeatureTypeEasyUnlockHostEnabled,
kCryptAuthFeatureTypeEasyUnlockClientEnabled,
kCryptAuthFeatureTypeMagicTetherHostEnabled,
kCryptAuthFeatureTypeMagicTetherClientEnabled,
kCryptAuthFeatureTypeSmsConnectHostEnabled,
kCryptAuthFeatureTypeSmsConnectClientEnabled};
}());
return *enabled_set;
}
multidevice::SoftwareFeature BetterTogetherFeatureTypeStringToSoftwareFeature(
const std::string& feature_type_string) {
if (feature_type_string == kCryptAuthFeatureTypeBetterTogetherHostSupported ||
feature_type_string == kCryptAuthFeatureTypeBetterTogetherHostEnabled) {
return multidevice::SoftwareFeature::kBetterTogetherHost;
}
if (feature_type_string ==
kCryptAuthFeatureTypeBetterTogetherClientSupported ||
feature_type_string == kCryptAuthFeatureTypeBetterTogetherClientEnabled) {
return multidevice::SoftwareFeature::kBetterTogetherClient;
}
if (feature_type_string == kCryptAuthFeatureTypeEasyUnlockHostSupported ||
feature_type_string == kCryptAuthFeatureTypeEasyUnlockHostEnabled) {
return multidevice::SoftwareFeature::kSmartLockHost;
}
if (feature_type_string == kCryptAuthFeatureTypeEasyUnlockClientSupported ||
feature_type_string == kCryptAuthFeatureTypeEasyUnlockClientEnabled) {
return multidevice::SoftwareFeature::kSmartLockClient;
}
if (feature_type_string == kCryptAuthFeatureTypeMagicTetherHostSupported ||
feature_type_string == kCryptAuthFeatureTypeMagicTetherHostEnabled) {
return multidevice::SoftwareFeature::kInstantTetheringHost;
}
if (feature_type_string == kCryptAuthFeatureTypeMagicTetherClientSupported ||
feature_type_string == kCryptAuthFeatureTypeMagicTetherClientEnabled) {
return multidevice::SoftwareFeature::kInstantTetheringClient;
}
if (feature_type_string == kCryptAuthFeatureTypeSmsConnectHostSupported ||
feature_type_string == kCryptAuthFeatureTypeSmsConnectHostEnabled) {
return multidevice::SoftwareFeature::kMessagesForWebHost;
}
DCHECK(feature_type_string ==
kCryptAuthFeatureTypeSmsConnectClientSupported ||
feature_type_string == kCryptAuthFeatureTypeSmsConnectClientEnabled);
return multidevice::SoftwareFeature::kMessagesForWebClient;
}
} // namespace device_sync
} // namespace chromeos
// Copyright 2019 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.
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_BETTER_TOGETHER_FEATURE_TYPES_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_BETTER_TOGETHER_FEATURE_TYPES_H_
#include <string>
#include "base/containers/flat_set.h"
#include "chromeos/components/multidevice/software_feature.h"
namespace chromeos {
namespace device_sync {
// Strings used by CryptAuth to identify the supported and enabled states of
// BetterTogether features. They are used in the "feature_type(s)" fields of the
// DeviceSync v2 RPCs BatchNotifyGroupDevices, BatchGetFeatureStatuses, and
// BatchSetFeatureStatuses.
extern const char kCryptAuthFeatureTypeBetterTogetherHostSupported[];
extern const char kCryptAuthFeatureTypeBetterTogetherClientSupported[];
extern const char kCryptAuthFeatureTypeEasyUnlockHostSupported[];
extern const char kCryptAuthFeatureTypeEasyUnlockClientSupported[];
extern const char kCryptAuthFeatureTypeMagicTetherHostSupported[];
extern const char kCryptAuthFeatureTypeMagicTetherClientSupported[];
extern const char kCryptAuthFeatureTypeSmsConnectHostSupported[];
extern const char kCryptAuthFeatureTypeSmsConnectClientSupported[];
extern const char kCryptAuthFeatureTypeBetterTogetherHostEnabled[];
extern const char kCryptAuthFeatureTypeBetterTogetherClientEnabled[];
extern const char kCryptAuthFeatureTypeEasyUnlockHostEnabled[];
extern const char kCryptAuthFeatureTypeEasyUnlockClientEnabled[];
extern const char kCryptAuthFeatureTypeMagicTetherHostEnabled[];
extern const char kCryptAuthFeatureTypeMagicTetherClientEnabled[];
extern const char kCryptAuthFeatureTypeSmsConnectHostEnabled[];
extern const char kCryptAuthFeatureTypeSmsConnectClientEnabled[];
const base::flat_set<std::string>& GetBetterTogetherFeatureTypes();
const base::flat_set<std::string>& GetSupportedBetterTogetherFeatureTypes();
const base::flat_set<std::string>& GetEnabledBetterTogetherFeatureTypes();
multidevice::SoftwareFeature BetterTogetherFeatureTypeStringToSoftwareFeature(
const std::string& feature_type_string);
} // namespace device_sync
} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_CRYPTAUTH_BETTER_TOGETHER_FEATURE_TYPES_H_
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "chromeos/components/multidevice/logging/logging.h" #include "chromeos/components/multidevice/logging/logging.h"
#include "chromeos/components/multidevice/software_feature.h" #include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/components/multidevice/software_feature_state.h" #include "chromeos/components/multidevice/software_feature_state.h"
#include "chromeos/services/device_sync/cryptauth_better_together_feature_types.h"
#include "chromeos/services/device_sync/cryptauth_client.h" #include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/cryptauth_key_bundle.h" #include "chromeos/services/device_sync/cryptauth_key_bundle.h"
#include "chromeos/services/device_sync/device_sync_type_converters.h" #include "chromeos/services/device_sync/device_sync_type_converters.h"
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "chromeos/components/multidevice/software_feature.h" #include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/components/multidevice/software_feature_state.h" #include "chromeos/components/multidevice/software_feature_state.h"
#include "chromeos/services/device_sync/async_execution_time_metrics_logger.h" #include "chromeos/services/device_sync/async_execution_time_metrics_logger.h"
#include "chromeos/services/device_sync/cryptauth_better_together_feature_types.h"
#include "chromeos/services/device_sync/cryptauth_client.h" #include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/cryptauth_feature_type.h"
namespace chromeos { namespace chromeos {
...@@ -80,7 +80,7 @@ ConvertFeatureStatusesToSoftwareFeatureMap( ...@@ -80,7 +80,7 @@ ConvertFeatureStatusesToSoftwareFeatureMap(
feature_statuses) { feature_statuses) {
// TODO(https://crbug.com/936273): Add metrics to track unknown feature type // TODO(https://crbug.com/936273): Add metrics to track unknown feature type
// occurrences. // occurrences.
if (!base::Contains(GetBetterTogetherFeatureTypes(), if (!base::Contains(GetCryptAuthFeatureTypeStrings(),
status.feature_type())) { status.feature_type())) {
PA_LOG(ERROR) << "Unknown feature type: " << status.feature_type(); PA_LOG(ERROR) << "Unknown feature type: " << status.feature_type();
*did_non_fatal_error_occur = true; *did_non_fatal_error_occur = true;
...@@ -88,16 +88,16 @@ ConvertFeatureStatusesToSoftwareFeatureMap( ...@@ -88,16 +88,16 @@ ConvertFeatureStatusesToSoftwareFeatureMap(
} }
multidevice::SoftwareFeature feature = multidevice::SoftwareFeature feature =
BetterTogetherFeatureTypeStringToSoftwareFeature(status.feature_type()); CryptAuthFeatureTypeStringToSoftwareFeature(status.feature_type());
if (base::Contains(GetSupportedBetterTogetherFeatureTypes(), if (base::Contains(GetSupportedCryptAuthFeatureTypeStrings(),
status.feature_type()) && status.feature_type()) &&
status.enabled()) { status.enabled()) {
marked_supported.insert(feature); marked_supported.insert(feature);
continue; continue;
} }
if (base::Contains(GetEnabledBetterTogetherFeatureTypes(), if (base::Contains(GetEnabledCryptAuthFeatureTypeStrings(),
status.feature_type()) && status.feature_type()) &&
status.enabled()) { status.enabled()) {
marked_enabled.insert(feature); marked_enabled.insert(feature);
...@@ -184,8 +184,8 @@ void CryptAuthFeatureStatusGetterImpl::OnAttemptStarted( ...@@ -184,8 +184,8 @@ void CryptAuthFeatureStatusGetterImpl::OnAttemptStarted(
cryptauthv2::BatchGetFeatureStatusesRequest request; cryptauthv2::BatchGetFeatureStatusesRequest request;
request.mutable_context()->CopyFrom(request_context); request.mutable_context()->CopyFrom(request_context);
*request.mutable_device_ids() = {device_ids.begin(), device_ids.end()}; *request.mutable_device_ids() = {device_ids.begin(), device_ids.end()};
*request.mutable_feature_types() = {GetBetterTogetherFeatureTypes().begin(), *request.mutable_feature_types() = {GetCryptAuthFeatureTypeStrings().begin(),
GetBetterTogetherFeatureTypes().end()}; GetCryptAuthFeatureTypeStrings().end()};
start_get_feature_statuses_timestamp_ = base::TimeTicks::Now(); start_get_feature_statuses_timestamp_ = base::TimeTicks::Now();
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
#include "base/timer/mock_timer.h" #include "base/timer/mock_timer.h"
#include "chromeos/components/multidevice/software_feature.h" #include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/components/multidevice/software_feature_state.h" #include "chromeos/components/multidevice/software_feature_state.h"
#include "chromeos/services/device_sync/cryptauth_better_together_feature_types.h"
#include "chromeos/services/device_sync/cryptauth_client.h" #include "chromeos/services/device_sync/cryptauth_client.h"
#include "chromeos/services/device_sync/cryptauth_device.h" #include "chromeos/services/device_sync/cryptauth_device.h"
#include "chromeos/services/device_sync/cryptauth_device_sync_result.h" #include "chromeos/services/device_sync/cryptauth_device_sync_result.h"
#include "chromeos/services/device_sync/cryptauth_feature_type.h"
#include "chromeos/services/device_sync/cryptauth_key_bundle.h" #include "chromeos/services/device_sync/cryptauth_key_bundle.h"
#include "chromeos/services/device_sync/cryptauth_v2_device_sync_test_devices.h" #include "chromeos/services/device_sync/cryptauth_v2_device_sync_test_devices.h"
#include "chromeos/services/device_sync/mock_cryptauth_client.h" #include "chromeos/services/device_sync/mock_cryptauth_client.h"
...@@ -64,10 +64,10 @@ cryptauthv2::DeviceFeatureStatus ConvertDeviceToDeviceFeatureStatus( ...@@ -64,10 +64,10 @@ cryptauthv2::DeviceFeatureStatus ConvertDeviceToDeviceFeatureStatus(
device_feature_status.set_device_id(device.instance_id()); device_feature_status.set_device_id(device.instance_id());
for (const std::string& feature_type : feature_types) { for (const std::string& feature_type : feature_types) {
bool is_supported_feature_type = bool is_supported_feature_type =
base::Contains(GetSupportedBetterTogetherFeatureTypes(), feature_type); base::Contains(GetSupportedCryptAuthFeatureTypeStrings(), feature_type);
const auto it = device.feature_states.find( const auto it = device.feature_states.find(
BetterTogetherFeatureTypeStringToSoftwareFeature(feature_type)); CryptAuthFeatureTypeStringToSoftwareFeature(feature_type));
bool is_supported = bool is_supported =
it != device.feature_states.end() && it != device.feature_states.end() &&
it->second != multidevice::SoftwareFeatureState::kNotSupported; it->second != multidevice::SoftwareFeatureState::kNotSupported;
...@@ -80,8 +80,8 @@ cryptauthv2::DeviceFeatureStatus ConvertDeviceToDeviceFeatureStatus( ...@@ -80,8 +80,8 @@ cryptauthv2::DeviceFeatureStatus ConvertDeviceToDeviceFeatureStatus(
if (is_supported_feature_type) { if (is_supported_feature_type) {
feature_status->set_enabled(is_supported); feature_status->set_enabled(is_supported);
} else { } else {
EXPECT_TRUE( EXPECT_TRUE(base::Contains(GetEnabledCryptAuthFeatureTypeStrings(),
base::Contains(GetEnabledBetterTogetherFeatureTypes(), feature_type)); feature_type));
feature_status->set_enabled(is_enabled); feature_status->set_enabled(is_enabled);
} }
} }
...@@ -148,7 +148,7 @@ class DeviceSyncCryptAuthFeatureStatusGetterImplTest ...@@ -148,7 +148,7 @@ class DeviceSyncCryptAuthFeatureStatusGetterImplTest
base::flat_set<std::string>( base::flat_set<std::string>(
batch_get_feature_statuses_request_->device_ids().begin(), batch_get_feature_statuses_request_->device_ids().begin(),
batch_get_feature_statuses_request_->device_ids().end())); batch_get_feature_statuses_request_->device_ids().end()));
EXPECT_EQ(GetBetterTogetherFeatureTypes(), EXPECT_EQ(GetCryptAuthFeatureTypeStrings(),
base::flat_set<std::string>( base::flat_set<std::string>(
batch_get_feature_statuses_request_->feature_types().begin(), batch_get_feature_statuses_request_->feature_types().begin(),
batch_get_feature_statuses_request_->feature_types().end())); batch_get_feature_statuses_request_->feature_types().end()));
...@@ -245,7 +245,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, Success) { ...@@ -245,7 +245,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, Success) {
VerifyBatchGetFeatureStatusesRequest(GetAllTestDeviceIds()); VerifyBatchGetFeatureStatusesRequest(GetAllTestDeviceIds());
SendCorrectBatchGetFeatureStatusesResponse(GetAllTestDeviceIds(), SendCorrectBatchGetFeatureStatusesResponse(GetAllTestDeviceIds(),
GetBetterTogetherFeatureTypes()); GetCryptAuthFeatureTypeStrings());
VerifyGetFeatureStatuesResult( VerifyGetFeatureStatuesResult(
GetAllTestDeviceIds(), CryptAuthDeviceSyncResult::ResultCode::kSuccess); GetAllTestDeviceIds(), CryptAuthDeviceSyncResult::ResultCode::kSuccess);
...@@ -262,7 +262,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -262,7 +262,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
// Include an unknown feature type string in the response. The unknown feature // Include an unknown feature type string in the response. The unknown feature
// type should be ignored. // type should be ignored.
cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus( cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus(
GetLocalDeviceForTest(), GetBetterTogetherFeatureTypes()); GetLocalDeviceForTest(), GetCryptAuthFeatureTypeStrings());
status.add_feature_statuses()->set_feature_type("Unknown_feature_type"); status.add_feature_statuses()->set_feature_type("Unknown_feature_type");
cryptauthv2::BatchGetFeatureStatusesResponse response; cryptauthv2::BatchGetFeatureStatusesResponse response;
...@@ -283,7 +283,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -283,7 +283,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
VerifyBatchGetFeatureStatusesRequest(device_ids); VerifyBatchGetFeatureStatusesRequest(device_ids);
cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus( cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus(
GetLocalDeviceForTest(), GetBetterTogetherFeatureTypes()); GetLocalDeviceForTest(), GetCryptAuthFeatureTypeStrings());
// The BetterTogether host feature is not supported for the local device. // The BetterTogether host feature is not supported for the local device.
EXPECT_EQ(multidevice::SoftwareFeatureState::kNotSupported, EXPECT_EQ(multidevice::SoftwareFeatureState::kNotSupported,
...@@ -293,26 +293,28 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -293,26 +293,28 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
->second); ->second);
// Ensure that BetterTogether host is marked as not supported in the response. // Ensure that BetterTogether host is marked as not supported in the response.
auto beto_host_supported_it = auto beto_host_supported_it = std::find_if(
std::find_if(status.mutable_feature_statuses()->begin(), status.mutable_feature_statuses()->begin(),
status.mutable_feature_statuses()->end(), status.mutable_feature_statuses()->end(),
[](const cryptauthv2::DeviceFeatureStatus::FeatureStatus& [](const cryptauthv2::DeviceFeatureStatus::FeatureStatus&
feature_status) { feature_status) {
return feature_status.feature_type() == return feature_status.feature_type() ==
kCryptAuthFeatureTypeBetterTogetherHostSupported; CryptAuthFeatureTypeToString(
}); CryptAuthFeatureType::kBetterTogetherHostSupported);
});
EXPECT_FALSE(beto_host_supported_it->enabled()); EXPECT_FALSE(beto_host_supported_it->enabled());
// Erroneously mark the BetterTogether host feature state as enabled in the // Erroneously mark the BetterTogether host feature state as enabled in the
// response though it is not supported. // response though it is not supported.
auto beto_host_enabled_it = auto beto_host_enabled_it = std::find_if(
std::find_if(status.mutable_feature_statuses()->begin(), status.mutable_feature_statuses()->begin(),
status.mutable_feature_statuses()->end(), status.mutable_feature_statuses()->end(),
[](const cryptauthv2::DeviceFeatureStatus::FeatureStatus& [](const cryptauthv2::DeviceFeatureStatus::FeatureStatus&
feature_status) { feature_status) {
return feature_status.feature_type() == return feature_status.feature_type() ==
kCryptAuthFeatureTypeBetterTogetherHostEnabled; CryptAuthFeatureTypeToString(
}); CryptAuthFeatureType::kBetterTogetherHostEnabled);
});
beto_host_enabled_it->set_enabled(true); beto_host_enabled_it->set_enabled(true);
cryptauthv2::BatchGetFeatureStatusesResponse response; cryptauthv2::BatchGetFeatureStatusesResponse response;
...@@ -337,7 +339,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -337,7 +339,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
// Include features statuses for unrequested devices. These extra devices // Include features statuses for unrequested devices. These extra devices
// should be ignored. // should be ignored.
SendCorrectBatchGetFeatureStatusesResponse(GetAllTestDeviceIds(), SendCorrectBatchGetFeatureStatusesResponse(GetAllTestDeviceIds(),
GetBetterTogetherFeatureTypes()); GetCryptAuthFeatureTypeStrings());
VerifyGetFeatureStatuesResult( VerifyGetFeatureStatuesResult(
requested_device_ids, requested_device_ids,
...@@ -355,7 +357,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -355,7 +357,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
// Send duplicate local device entries in the response. These duplicate // Send duplicate local device entries in the response. These duplicate
// entries should be ignored. // entries should be ignored.
cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus( cryptauthv2::DeviceFeatureStatus status = ConvertDeviceToDeviceFeatureStatus(
GetLocalDeviceForTest(), GetBetterTogetherFeatureTypes()); GetLocalDeviceForTest(), GetCryptAuthFeatureTypeStrings());
cryptauthv2::BatchGetFeatureStatusesResponse response; cryptauthv2::BatchGetFeatureStatusesResponse response;
response.add_device_feature_statuses()->CopyFrom(status); response.add_device_feature_statuses()->CopyFrom(status);
response.add_device_feature_statuses()->CopyFrom(status); response.add_device_feature_statuses()->CopyFrom(status);
...@@ -376,7 +378,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest, ...@@ -376,7 +378,7 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusGetterImplTest,
base::flat_set<std::string> returned_device_ids = { base::flat_set<std::string> returned_device_ids = {
GetLocalDeviceMetadataPacketForTest().device_id()}; GetLocalDeviceMetadataPacketForTest().device_id()};
SendCorrectBatchGetFeatureStatusesResponse(returned_device_ids, SendCorrectBatchGetFeatureStatusesResponse(returned_device_ids,
GetBetterTogetherFeatureTypes()); GetCryptAuthFeatureTypeStrings());
VerifyGetFeatureStatuesResult( VerifyGetFeatureStatuesResult(
returned_device_ids, returned_device_ids,
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "base/containers/flat_set.h"
#include "base/optional.h" #include "base/optional.h"
#include "chromeos/components/multidevice/software_feature.h"
namespace chromeos { namespace chromeos {
...@@ -23,11 +25,11 @@ namespace device_sync { ...@@ -23,11 +25,11 @@ namespace device_sync {
// supported but not enabled: // supported but not enabled:
// [ // [
// message FeatureStatus { // message FeatureStatus {
// string feature_type = "BetterTogetherHostSupported"; // string feature_type = "BETTER_TOGETHER_HOST_SUPPORTED";
// bool enabled = true; // bool enabled = true;
// }, // },
// message FeatureStatus { // message FeatureStatus {
// string feature_type = "BetterTogetherHostEnabled"; // string feature_type = "BETTER_TOGETHER_HOST";
// bool enabled = false; // bool enabled = false;
// } // }
// ] // ]
...@@ -60,18 +62,29 @@ enum class CryptAuthFeatureType { ...@@ -60,18 +62,29 @@ enum class CryptAuthFeatureType {
kSmsConnectClientEnabled, kSmsConnectClientEnabled,
}; };
// Uniquely maps each enum value to a string used in the protos and understood // Uniquely maps each CryptAuthFeatureType enum value to a string used in the
// by CryptAuth. // protos and understood by CryptAuth.
std::string CryptAuthFeatureTypeToString( const char* CryptAuthFeatureTypeToString(CryptAuthFeatureType feature_type);
const CryptAuthFeatureType& feature_type);
// Uniquely maps each SoftwareFeature enum value to a string used in the protos
// and understood by CryptAuth.
const char* SoftwareFeatureToEnabledCryptAuthFeatureTypeString(
multidevice::SoftwareFeature software_feature);
// Returns null if |feature_type_string| does not map to a known // Returns null if |feature_type_string| does not map to a known
// CryptAuthFeatureType. // CryptAuthFeatureType.
base::Optional<CryptAuthFeatureType> CryptAuthFeatureTypeFromString( base::Optional<CryptAuthFeatureType> CryptAuthFeatureTypeFromString(
const std::string& feature_type_string); const std::string& feature_type_string);
multidevice::SoftwareFeature CryptAuthFeatureTypeStringToSoftwareFeature(
const std::string& feature_type_string);
const base::flat_set<std::string>& GetCryptAuthFeatureTypeStrings();
const base::flat_set<std::string>& GetSupportedCryptAuthFeatureTypeStrings();
const base::flat_set<std::string>& GetEnabledCryptAuthFeatureTypeStrings();
std::ostream& operator<<(std::ostream& stream, std::ostream& operator<<(std::ostream& stream,
const CryptAuthFeatureType& feature_type); CryptAuthFeatureType feature_type);
} // namespace device_sync } // namespace device_sync
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment