Commit 85169666 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[DeviceSync v2] Add FeatureStatusChange enum to DeviceSync mojo service

This CL prepares the way for the addition of SetFeatureStatus() to the
DeviceSync mojo service. See http://crrev/c/1831010.

Bug: 951969
Change-Id: I488984c741ed7050bef2a78163ef6e93f7aee2b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895887Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Josh Nohle <nohle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712711}
parent b4b4ccb9
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos") assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos")
static_library("feature_status_change") {
sources = [
"feature_status_change.h",
]
}
static_library("device_sync") { static_library("device_sync") {
sources = [ sources = [
"async_execution_time_metrics_logger.cc", "async_execution_time_metrics_logger.cc",
...@@ -135,6 +141,7 @@ static_library("device_sync") { ...@@ -135,6 +141,7 @@ static_library("device_sync") {
] ]
public_deps = [ public_deps = [
":feature_status_change",
"//chromeos/components/multidevice", "//chromeos/components/multidevice",
"//chromeos/components/multidevice/logging", "//chromeos/components/multidevice/logging",
"//chromeos/services/device_sync/public/mojom", "//chromeos/services/device_sync/public/mojom",
...@@ -271,6 +278,7 @@ source_set("unit_tests") { ...@@ -271,6 +278,7 @@ source_set("unit_tests") {
deps = [ deps = [
":device_sync", ":device_sync",
":feature_status_change",
":test_support", ":test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/components/multidevice/software_feature.h" #include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/services/device_sync/feature_status_change.h"
#include "chromeos/services/device_sync/network_request_error.h" #include "chromeos/services/device_sync/network_request_error.h"
namespace chromeos { namespace chromeos {
...@@ -23,20 +24,6 @@ namespace device_sync { ...@@ -23,20 +24,6 @@ namespace device_sync {
// with the CryptAuth v1 DeviceSync interface. // with the CryptAuth v1 DeviceSync interface.
class CryptAuthFeatureStatusSetter { class CryptAuthFeatureStatusSetter {
public: public:
enum class FeatureStatusChange {
// Enables a feature on a device and disables the feature on all other
// devices associated with the account.
kEnableExclusively,
// Enables a feature on a device; other devices on the account are
// unaffected.
kEnableNonExclusively,
// Disables a feature on a device; other devices on the account are
// unaffected.
kDisable
};
CryptAuthFeatureStatusSetter() = default; CryptAuthFeatureStatusSetter() = default;
virtual ~CryptAuthFeatureStatusSetter() = default; virtual ~CryptAuthFeatureStatusSetter() = default;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/components/multidevice/software_feature.h" #include "chromeos/components/multidevice/software_feature.h"
#include "chromeos/services/device_sync/cryptauth_feature_status_setter.h" #include "chromeos/services/device_sync/cryptauth_feature_status_setter.h"
#include "chromeos/services/device_sync/feature_status_change.h"
#include "chromeos/services/device_sync/network_request_error.h" #include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/proto/cryptauth_client_app_metadata.pb.h" #include "chromeos/services/device_sync/proto/cryptauth_client_app_metadata.pb.h"
#include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h" #include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#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/fake_cryptauth_gcm_manager.h" #include "chromeos/services/device_sync/fake_cryptauth_gcm_manager.h"
#include "chromeos/services/device_sync/feature_status_change.h"
#include "chromeos/services/device_sync/mock_cryptauth_client.h" #include "chromeos/services/device_sync/mock_cryptauth_client.h"
#include "chromeos/services/device_sync/network_request_error.h" #include "chromeos/services/device_sync/network_request_error.h"
#include "chromeos/services/device_sync/proto/cryptauth_client_app_metadata.pb.h" #include "chromeos/services/device_sync/proto/cryptauth_client_app_metadata.pb.h"
...@@ -153,10 +154,9 @@ class DeviceSyncCryptAuthFeatureStatusSetterImplTest ...@@ -153,10 +154,9 @@ class DeviceSyncCryptAuthFeatureStatusSetterImplTest
.WillByDefault(testing::Return(kAccessTokenUsed)); .WillByDefault(testing::Return(kAccessTokenUsed));
} }
void SetFeatureStatus( void SetFeatureStatus(const std::string& device_id,
const std::string& device_id, multidevice::SoftwareFeature feature,
multidevice::SoftwareFeature feature, FeatureStatusChange status_change) {
CryptAuthFeatureStatusSetter::FeatureStatusChange status_change) {
feature_status_setter_->SetFeatureStatus( feature_status_setter_->SetFeatureStatus(
device_id, feature, status_change, device_id, feature, status_change,
base::BindOnce(&DeviceSyncCryptAuthFeatureStatusSetterImplTest:: base::BindOnce(&DeviceSyncCryptAuthFeatureStatusSetterImplTest::
...@@ -286,22 +286,21 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusSetterImplTest, Test) { ...@@ -286,22 +286,21 @@ TEST_F(DeviceSyncCryptAuthFeatureStatusSetterImplTest, Test) {
// sequentially. // sequentially.
SetFeatureStatus("device_id_1", SetFeatureStatus("device_id_1",
multidevice::SoftwareFeature::kSmartLockClient, multidevice::SoftwareFeature::kSmartLockClient,
CryptAuthFeatureStatusSetter::FeatureStatusChange::kDisable); FeatureStatusChange::kDisable);
SetFeatureStatus( SetFeatureStatus("device_id_2",
"device_id_2", multidevice::SoftwareFeature::kInstantTetheringHost, multidevice::SoftwareFeature::kInstantTetheringHost,
CryptAuthFeatureStatusSetter::FeatureStatusChange::kEnableNonExclusively); FeatureStatusChange::kEnableNonExclusively);
SetFeatureStatus( SetFeatureStatus("device_id_3", multidevice::SoftwareFeature::kSmartLockHost,
"device_id_3", multidevice::SoftwareFeature::kSmartLockHost, FeatureStatusChange::kEnableExclusively);
CryptAuthFeatureStatusSetter::FeatureStatusChange::kEnableExclusively);
SetFeatureStatus("device_id_4", SetFeatureStatus("device_id_4",
multidevice::SoftwareFeature::kInstantTetheringClient, multidevice::SoftwareFeature::kInstantTetheringClient,
CryptAuthFeatureStatusSetter::FeatureStatusChange::kDisable); FeatureStatusChange::kDisable);
SetFeatureStatus("device_id_5", SetFeatureStatus("device_id_5",
multidevice::SoftwareFeature::kInstantTetheringClient, multidevice::SoftwareFeature::kInstantTetheringClient,
CryptAuthFeatureStatusSetter::FeatureStatusChange::kDisable); FeatureStatusChange::kDisable);
SetFeatureStatus( SetFeatureStatus("device_id_6",
"device_id_6", multidevice::SoftwareFeature::kBetterTogetherHost, multidevice::SoftwareFeature::kBetterTogetherHost,
CryptAuthFeatureStatusSetter::FeatureStatusChange::kEnableNonExclusively); FeatureStatusChange::kEnableNonExclusively);
// base::nullopt indicates a success. // base::nullopt indicates a success.
std::vector<base::Optional<NetworkRequestError>> expected_results; std::vector<base::Optional<NetworkRequestError>> expected_results;
......
// 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_FEATURE_STATUS_CHANGE_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_FEATURE_STATUS_CHANGE_H_
namespace chromeos {
namespace device_sync {
// The target status change for a device's SoftwareFeature.
enum class FeatureStatusChange {
// Enables a feature on a device and disables the feature on all other devices
// associated with the account.
kEnableExclusively = 0,
// Enables a feature on a device; other devices on the account are unaffected.
kEnableNonExclusively = 1,
// Disables a feature on a device; other devices on the account are
// unaffected.
kDisable = 2
};
} // namespace device_sync
} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FEATURE_STATUS_CHANGE_H_
...@@ -26,6 +26,8 @@ source_set("unit_tests") { ...@@ -26,6 +26,8 @@ source_set("unit_tests") {
":mojom", ":mojom",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//chromeos/services/device_sync:feature_status_change",
"//chromeos/services/device_sync/proto",
"//mojo/public/cpp/test_support:test_utils", "//mojo/public/cpp/test_support:test_utils",
"//testing/gtest", "//testing/gtest",
] ]
......
...@@ -42,6 +42,20 @@ enum NetworkRequestResult { ...@@ -42,6 +42,20 @@ enum NetworkRequestResult {
kUnknown kUnknown
}; };
enum FeatureStatusChange {
// Enables a feature on a device and disables the feature on all other
// devices associated with the account.
kEnableExclusively,
// Enables a feature on a device; other devices on the account are
// unaffected.
kEnableNonExclusively,
// Disables a feature on a device; other devices on the account are
// unaffected.
kDisable
};
struct FindEligibleDevicesResponse { struct FindEligibleDevicesResponse {
array<chromeos.multidevice.mojom.RemoteDevice> eligible_devices; array<chromeos.multidevice.mojom.RemoteDevice> eligible_devices;
array<chromeos.multidevice.mojom.RemoteDevice> ineligible_devices; array<chromeos.multidevice.mojom.RemoteDevice> ineligible_devices;
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
mojom = "//chromeos/services/device_sync/public/mojom/device_sync.mojom" mojom = "//chromeos/services/device_sync/public/mojom/device_sync.mojom"
public_headers = public_headers = [
[ "//chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h" ] "//chromeos/services/device_sync/feature_status_change.h",
"//chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h",
]
traits_headers = [ traits_headers = [
"//chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h", "//chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h",
...@@ -16,4 +18,12 @@ sources = [ ...@@ -16,4 +18,12 @@ sources = [
"//chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h", "//chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h",
] ]
type_mappings = [ "chromeos.device_sync.mojom.ConnectivityStatus=cryptauthv2::ConnectivityStatus" ] public_deps = [
"//chromeos/services/device_sync:feature_status_change",
"//chromeos/services/device_sync/proto",
]
type_mappings = [
"chromeos.device_sync.mojom.ConnectivityStatus=cryptauthv2::ConnectivityStatus",
"chromeos.device_sync.mojom.FeatureStatusChange=chromeos::device_sync::FeatureStatusChange",
]
...@@ -43,4 +43,41 @@ bool EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus, ...@@ -43,4 +43,41 @@ bool EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus,
return false; return false;
} }
chromeos::device_sync::mojom::FeatureStatusChange
EnumTraits<chromeos::device_sync::mojom::FeatureStatusChange,
chromeos::device_sync::FeatureStatusChange>::
ToMojom(chromeos::device_sync::FeatureStatusChange input) {
switch (input) {
case chromeos::device_sync::FeatureStatusChange::kEnableExclusively:
return chromeos::device_sync::mojom::FeatureStatusChange::
kEnableExclusively;
case chromeos::device_sync::FeatureStatusChange::kEnableNonExclusively:
return chromeos::device_sync::mojom::FeatureStatusChange::
kEnableNonExclusively;
case chromeos::device_sync::FeatureStatusChange::kDisable:
return chromeos::device_sync::mojom::FeatureStatusChange::kDisable;
}
}
bool EnumTraits<chromeos::device_sync::mojom::FeatureStatusChange,
chromeos::device_sync::FeatureStatusChange>::
FromMojom(chromeos::device_sync::mojom::FeatureStatusChange input,
chromeos::device_sync::FeatureStatusChange* out) {
switch (input) {
case chromeos::device_sync::mojom::FeatureStatusChange::kEnableExclusively:
*out = chromeos::device_sync::FeatureStatusChange::kEnableExclusively;
return true;
case chromeos::device_sync::mojom::FeatureStatusChange::
kEnableNonExclusively:
*out = chromeos::device_sync::FeatureStatusChange::kEnableNonExclusively;
return true;
case chromeos::device_sync::mojom::FeatureStatusChange::kDisable:
*out = chromeos::device_sync::FeatureStatusChange::kDisable;
return true;
}
NOTREACHED();
return false;
}
} // namespace mojo } // namespace mojo
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_ #ifndef CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_ #define CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_
#include "chromeos/services/device_sync/feature_status_change.h"
#include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h" #include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h" #include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
#include "mojo/public/cpp/bindings/enum_traits.h" #include "mojo/public/cpp/bindings/enum_traits.h"
namespace mojo { namespace mojo {
template <> template <>
class EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus, class EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus,
cryptauthv2::ConnectivityStatus> { cryptauthv2::ConnectivityStatus> {
...@@ -20,6 +22,16 @@ class EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus, ...@@ -20,6 +22,16 @@ class EnumTraits<chromeos::device_sync::mojom::ConnectivityStatus,
cryptauthv2::ConnectivityStatus* out); cryptauthv2::ConnectivityStatus* out);
}; };
template <>
class EnumTraits<chromeos::device_sync::mojom::FeatureStatusChange,
chromeos::device_sync::FeatureStatusChange> {
public:
static chromeos::device_sync::mojom::FeatureStatusChange ToMojom(
chromeos::device_sync::FeatureStatusChange input);
static bool FromMojom(chromeos::device_sync::mojom::FeatureStatusChange input,
chromeos::device_sync::FeatureStatusChange* out);
};
} // namespace mojo } // namespace mojo
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_ #endif // CHROMEOS_SERVICES_DEVICE_SYNC_PUBLIC_MOJOM_DEVICE_SYNC_MOJOM_TRAITS_H_
\ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h" #include "chromeos/services/device_sync/public/mojom/device_sync_mojom_traits.h"
#include "chromeos/services/device_sync/feature_status_change.h"
#include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h" #include "chromeos/services/device_sync/proto/cryptauth_devicesync.pb.h"
#include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h" #include "chromeos/services/device_sync/public/mojom/device_sync.mojom.h"
#include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/cpp/test_support/test_utils.h"
...@@ -27,3 +28,25 @@ TEST(DeviceSyncMojomTraitsTest, ConnectivityStatus) { ...@@ -27,3 +28,25 @@ TEST(DeviceSyncMojomTraitsTest, ConnectivityStatus) {
EXPECT_EQ(status_in, status_out); EXPECT_EQ(status_in, status_out);
} }
} }
TEST(DeviceSyncMojomTraitsTest, FeatureStatusChange) {
static constexpr chromeos::device_sync::FeatureStatusChange
kTestFeatureStatusChanges[] = {
chromeos::device_sync::FeatureStatusChange::kEnableExclusively,
chromeos::device_sync::FeatureStatusChange::kEnableNonExclusively,
chromeos::device_sync::FeatureStatusChange::kDisable};
for (auto status_in : kTestFeatureStatusChanges) {
chromeos::device_sync::FeatureStatusChange status_out;
chromeos::device_sync::mojom::FeatureStatusChange serialized_status =
mojo::EnumTraits<
chromeos::device_sync::mojom::FeatureStatusChange,
chromeos::device_sync::FeatureStatusChange>::ToMojom(status_in);
ASSERT_TRUE(
(mojo::EnumTraits<chromeos::device_sync::mojom::FeatureStatusChange,
chromeos::device_sync::FeatureStatusChange>::
FromMojom(serialized_status, &status_out)));
EXPECT_EQ(status_in, status_out);
}
}
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