From c44772050b49eee0432c00d44521c6916fca3048 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Wed, 7 Aug 2024 16:35:29 +0100 Subject: [PATCH] `ModelType` enum and `ModelTypeState` renamed This is in line with previous changes, where the prefix `Model` is being replaced with `Data`. This change corrects the name of types, variables, inclusion paths, and also renames shadow files. Chromium changes: https://chromium.googlesource.com/chromium/src/+/1f5656458d6879d589bc1568ee1dab13050d0fc5 commit 1f5656458d6879d589bc1568ee1dab13050d0fc5 Author: Mikel Astiz Date: Tue Aug 6 16:15:30 2024 +0000 [sync] Rename ModelTypeState to DataTypeState See linked bug for rationale. The proto is renamed without behavioral changes using the commands below. Note that some occurrences need to be excluded because they are database column names that would require a migration, which also means the patch needs careful review. git grep -l ModelTypeState | \ xargs rename 's/model_type_state/data_type_state/' git mv components/sync/protocol/model_type_state_helper_unittest.cc \ components/sync/protocol/data_type_state_helper_unittest.cc git add . tools/git/mass-rename.py git grep -l ModelTypeState | \ xargs sed -i 's/ModelTypeState/DataTypeState/g' git grep -l model_type_state | \ xargs sed -i 's/model_type_state/data_type_state/g' git grep -l _data_type_state | \ xargs sed -i -E 's/(autofill|history|plus_address_sync|typed_url)_data_type_state/\1_model_type_state/g' git cl format Some forward declaration orderings and includes were fixed manually. Change-Id: I97a371fee5c7688a5090cf034a0418b989f29862 Bug: 356649891 https://chromium.googlesource.com/chromium/src/+/209e0271904abe753d64602d165b791005a98905 commit 209e0271904abe753d64602d165b791005a98905 Author: Mikel Astiz Date: Tue Aug 6 09:13:48 2024 +0000 [sync] Rename enum ModelType to DataType (with temporary alias) Pure refactoring without behavioral changes. All occurrences of syncer::ModelType are about to be replaced with syncer::DataType, following the rationale in the linked bug. As a first step, the enum and some of the functions that come together with it are forked, in order to allow a gradual migration. The renames in Java code are bundled into this first patch as they aren't that many and they are harder to split. Change-Id: Ibeeabd0355ee2c86bdfd99b7002c95bc6a1f3ccf Bug: 356649891 --- .../sync/base/{model_type.cc => data_type.cc} | 9 ++++----- .../sync/base/{model_type.h => data_type.h} | 10 +++++----- ...del_type_unittest.cc => data_type_unittest.cc} | 12 ++++++------ .../components/sync/engine/data_type_registry.cc | 2 +- .../components/sync/engine/data_type_worker.h | 2 +- .../components/sync/model/metadata_batch.h | 8 ++++---- .../device_info_sync_bridge_unittest.cc | 15 +++++++-------- components/sync/engine/brave_data_type_worker.cc | 6 +++--- components/sync/engine/brave_data_type_worker.h | 4 ++-- .../engine/brave_data_type_worker_unittest.cc | 14 +++++++------- test/BUILD.gn | 2 +- 11 files changed, 41 insertions(+), 43 deletions(-) rename chromium_src/components/sync/base/{model_type.cc => data_type.cc} (70%) rename chromium_src/components/sync/base/{model_type.h => data_type.h} (74%) rename chromium_src/components/sync/base/{model_type_unittest.cc => data_type_unittest.cc} (67%) diff --git a/chromium_src/components/sync/base/model_type.cc b/chromium_src/components/sync/base/data_type.cc similarity index 70% rename from chromium_src/components/sync/base/model_type.cc rename to chromium_src/components/sync/base/data_type.cc index 5507e43be82..1a664d3a41b 100644 --- a/chromium_src/components/sync/base/model_type.cc +++ b/chromium_src/components/sync/base/data_type.cc @@ -1,17 +1,16 @@ /* Copyright (c) 2020 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #define EncryptableUserTypes EncryptableUserTypes_ChromiumImpl -#include "src/components/sync/base/model_type.cc" +#include "src/components/sync/base/data_type.cc" #undef EncryptableUserTypes - namespace syncer { -ModelTypeSet EncryptableUserTypes() { - ModelTypeSet encryptable_user_types = EncryptableUserTypes_ChromiumImpl(); +DataTypeSet EncryptableUserTypes() { + DataTypeSet encryptable_user_types = EncryptableUserTypes_ChromiumImpl(); // Brave sync has encryption setup ready when sync chain created encryptable_user_types.Put(DEVICE_INFO); encryptable_user_types.Put(HISTORY); diff --git a/chromium_src/components/sync/base/model_type.h b/chromium_src/components/sync/base/data_type.h similarity index 74% rename from chromium_src/components/sync/base/model_type.h rename to chromium_src/components/sync/base/data_type.h index 8cf19a3bfe0..18094b0e3f6 100644 --- a/chromium_src/components/sync/base/model_type.h +++ b/chromium_src/components/sync/base/data_type.h @@ -3,18 +3,18 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ +#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_DATA_TYPE_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_DATA_TYPE_H_ #define LowPriorityUserTypes LowPriorityUserTypes_ChromiumImpl -#include "src/components/sync/base/model_type.h" // IWYU pragma: export +#include "src/components/sync/base/data_type.h" // IWYU pragma: export #undef LowPriorityUserTypes namespace syncer { -constexpr ModelTypeSet LowPriorityUserTypes() { +constexpr DataTypeSet LowPriorityUserTypes() { auto low_priority_user_types = LowPriorityUserTypes_ChromiumImpl(); // Directives must be synced after history entities. If // history delete directives are processed before retrieving history upon @@ -29,4 +29,4 @@ constexpr ModelTypeSet LowPriorityUserTypes() { } // namespace syncer -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_MODEL_TYPE_H_ +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_DATA_TYPE_H_ diff --git a/chromium_src/components/sync/base/model_type_unittest.cc b/chromium_src/components/sync/base/data_type_unittest.cc similarity index 67% rename from chromium_src/components/sync/base/model_type_unittest.cc rename to chromium_src/components/sync/base/data_type_unittest.cc index efc2d66bd2e..de0e4944245 100644 --- a/chromium_src/components/sync/base/model_type_unittest.cc +++ b/chromium_src/components/sync/base/data_type_unittest.cc @@ -1,27 +1,27 @@ /* Copyright (c) 2020 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "src/components/sync/base/model_type_unittest.cc" +#include "src/components/sync/base/data_type_unittest.cc" namespace syncer { namespace { -TEST(ModelTypeTest, EncryptableUserTypes) { +TEST(DataTypeTest, EncryptableUserTypes) { EXPECT_TRUE(EncryptableUserTypes().Has(DEVICE_INFO)); EXPECT_TRUE(EncryptableUserTypes().Has(HISTORY)); } -TEST(ModelTypeTest, LowPriorityUserTypes) { +TEST(DataTypeTest, LowPriorityUserTypes) { EXPECT_TRUE(LowPriorityUserTypes().Has(HISTORY_DELETE_DIRECTIVES)); EXPECT_FALSE(LowPriorityUserTypes().Has(HISTORY)); EXPECT_TRUE(LowPriorityUserTypes().Has(USER_EVENTS)); } // This test is supposed to fail when sync types are increased/decreased -TEST(ModelTypeTest, ModelTypeCounts) { - EXPECT_EQ(static_cast(ModelTypeForHistograms::kMaxValue), 68); +TEST(DataTypeTest, DataTypeCounts) { + EXPECT_EQ(static_cast(DataTypeForHistograms::kMaxValue), 68); } } // namespace diff --git a/chromium_src/components/sync/engine/data_type_registry.cc b/chromium_src/components/sync/engine/data_type_registry.cc index d010f1ba64a..de6200d7539 100644 --- a/chromium_src/components/sync/engine/data_type_registry.cc +++ b/chromium_src/components/sync/engine/data_type_registry.cc @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/components/sync/engine/brave_data_type_worker.h" diff --git a/chromium_src/components/sync/engine/data_type_worker.h b/chromium_src/components/sync/engine/data_type_worker.h index 8fe63804eb4..b5ba463ac03 100644 --- a/chromium_src/components/sync/engine/data_type_worker.h +++ b/chromium_src/components/sync/engine/data_type_worker.h @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_DATA_TYPE_WORKER_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_DATA_TYPE_WORKER_H_ diff --git a/chromium_src/components/sync/model/metadata_batch.h b/chromium_src/components/sync/model/metadata_batch.h index 42e483d7464..e30d5f009e3 100644 --- a/chromium_src/components/sync/model/metadata_batch.h +++ b/chromium_src/components/sync/model/metadata_batch.h @@ -6,12 +6,12 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_MODEL_METADATA_BATCH_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_MODEL_METADATA_BATCH_H_ -#define SetModelTypeState \ - ClearProgressToken(); \ - void SetModelTypeState +#define SetDataTypeState \ + ClearProgressToken(); \ + void SetDataTypeState #include "src/components/sync/model/metadata_batch.h" // IWYU pragma: export -#undef SetModelTypeState +#undef SetDataTypeState #endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_MODEL_METADATA_BATCH_H_ diff --git a/chromium_src/components/sync_device_info/device_info_sync_bridge_unittest.cc b/chromium_src/components/sync_device_info/device_info_sync_bridge_unittest.cc index 9688a77ddd7..24b15460ff0 100644 --- a/chromium_src/components/sync_device_info/device_info_sync_bridge_unittest.cc +++ b/chromium_src/components/sync_device_info/device_info_sync_bridge_unittest.cc @@ -224,9 +224,9 @@ TEST_F(DeviceInfoSyncBridgeTest, BraveExpireOldEntriesUponStartup) { TEST_F(DeviceInfoSyncBridgeTest, BraveResetsProgressMarkerOnce) { const DeviceInfoSpecifics specifics = CreateLocalDeviceSpecifics(); - ModelTypeState model_type_state = StateWithEncryption("ekn"); - model_type_state.mutable_progress_marker()->set_token("ABC"); - WriteToStoreWithMetadata({specifics}, model_type_state); + DataTypeState data_type_state = StateWithEncryption("ekn"); + data_type_state.mutable_progress_marker()->set_token("ABC"); + WriteToStoreWithMetadata({specifics}, data_type_state); { base::RunLoop run_loop; @@ -238,9 +238,8 @@ TEST_F(DeviceInfoSyncBridgeTest, BraveResetsProgressMarkerOnce) { .WillOnce([&run_loop](std::unique_ptr batch) { // When model is loaded for the first time and the progress token // was set then the token should be reset - EXPECT_TRUE(batch->GetModelTypeState().has_progress_marker()); - EXPECT_FALSE( - batch->GetModelTypeState().progress_marker().has_token()); + EXPECT_TRUE(batch->GetDataTypeState().has_progress_marker()); + EXPECT_FALSE(batch->GetDataTypeState().progress_marker().has_token()); run_loop.Quit(); }); @@ -256,8 +255,8 @@ TEST_F(DeviceInfoSyncBridgeTest, BraveResetsProgressMarkerOnce) { .WillOnce([&run_loop](std::unique_ptr batch) { // When the progress token already was reset, then do not reset it // again - EXPECT_TRUE(batch->GetModelTypeState().has_progress_marker()); - EXPECT_TRUE(batch->GetModelTypeState().progress_marker().has_token()); + EXPECT_TRUE(batch->GetDataTypeState().has_progress_marker()); + EXPECT_TRUE(batch->GetDataTypeState().progress_marker().has_token()); run_loop.Quit(); }); run_loop.Run(); diff --git a/components/sync/engine/brave_data_type_worker.cc b/components/sync/engine/brave_data_type_worker.cc index ba8dff4fd1a..a12d930939e 100644 --- a/components/sync/engine/brave_data_type_worker.cc +++ b/components/sync/engine/brave_data_type_worker.cc @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include @@ -35,7 +35,7 @@ base::TimeDelta kMinimalTimeBetweenResetMarker = base::Minutes(30); BraveDataTypeWorker::BraveDataTypeWorker( ModelType type, - const sync_pb::ModelTypeState& initial_state, + const sync_pb::DataTypeState& initial_state, Cryptographer* cryptographer, bool encryption_enabled, PassphraseType passphrase_type, @@ -115,7 +115,7 @@ void BraveDataTypeWorker::ResetProgressMarker() { // P3A sample is 0 base::UmaHistogramExactLinear("Brave.Sync.ProgressTokenEverReset", 0, 1); last_reset_marker_time_ = base::Time::Now(); - model_type_state_.mutable_progress_marker()->clear_token(); + data_type_state_.mutable_progress_marker()->clear_token(); } } // namespace syncer diff --git a/components/sync/engine/brave_data_type_worker.h b/components/sync/engine/brave_data_type_worker.h index 8d5da9e7bd4..7c8ab846e1f 100644 --- a/components/sync/engine/brave_data_type_worker.h +++ b/components/sync/engine/brave_data_type_worker.h @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_COMPONENTS_SYNC_ENGINE_BRAVE_DATA_TYPE_WORKER_H_ #define BRAVE_COMPONENTS_SYNC_ENGINE_BRAVE_DATA_TYPE_WORKER_H_ @@ -33,7 +33,7 @@ FORWARD_DECLARE_TEST(BraveDataTypeWorkerTest, class BraveDataTypeWorker : public DataTypeWorker { public: BraveDataTypeWorker(ModelType type, - const sync_pb::ModelTypeState& initial_state, + const sync_pb::DataTypeState& initial_state, Cryptographer* cryptographer, bool encryption_enabled, PassphraseType passphrase_type, diff --git a/components/sync/engine/brave_data_type_worker_unittest.cc b/components/sync/engine/brave_data_type_worker_unittest.cc index c30873b940a..c95763d8a0a 100644 --- a/components/sync/engine/brave_data_type_worker_unittest.cc +++ b/components/sync/engine/brave_data_type_worker_unittest.cc @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include @@ -23,7 +23,7 @@ using base::subtle::TimeNowIgnoringOverride; using sync_pb::CommitResponse_ResponseType; using sync_pb::CommitResponse_ResponseType_CONFLICT; using sync_pb::CommitResponse_ResponseType_TRANSIENT_ERROR; -using sync_pb::ModelTypeState; +using sync_pb::DataTypeState; namespace syncer { @@ -35,21 +35,21 @@ class BraveDataTypeWorkerTest : public ::testing::Test { ~BraveDataTypeWorkerTest() override = default; void NormalInitialize() { - ModelTypeState initial_state; + DataTypeState initial_state; initial_state.mutable_progress_marker()->set_data_type_id( GetSpecificsFieldNumberFromModelType(model_type_)); initial_state.mutable_progress_marker()->set_token( "some_saved_progress_token"); initial_state.set_initial_sync_state( - sync_pb::ModelTypeState_InitialSyncState_INITIAL_SYNC_DONE); + sync_pb::DataTypeState_InitialSyncState_INITIAL_SYNC_DONE); InitializeWithState(model_type_, initial_state); nudge_handler()->ClearCounters(); } - void InitializeWithState(const ModelType type, const ModelTypeState& state) { + void InitializeWithState(const ModelType type, const DataTypeState& state) { DCHECK(!worker()); auto processor = std::make_unique(); @@ -73,11 +73,11 @@ class BraveDataTypeWorkerTest : public ::testing::Test { MockNudgeHandler* nudge_handler() { return &mock_nudge_handler_; } bool IsProgressMarkerEmpty() { - return worker()->model_type_state_.progress_marker().token().empty(); + return worker()->data_type_state_.progress_marker().token().empty(); } void FillProgressMarker() { - worker()->model_type_state_.mutable_progress_marker()->set_token("TOKEN1"); + worker()->data_type_state_.mutable_progress_marker()->set_token("TOKEN1"); } private: diff --git a/test/BUILD.gn b/test/BUILD.gn index 2c44d2e2c08..d6030301dda 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -141,7 +141,7 @@ test("brave_unit_tests") { "//chrome/browser/signin/test_signin_client_builder.h", "//components/domain_reliability/test_util.cc", "//components/domain_reliability/test_util.h", - "//components/sync/base/model_type_unittest.cc", + "//components/sync/base/data_type_unittest.cc", "//components/sync/engine/sync_scheduler_impl_unittest.cc", "//components/sync/service/sync_auth_manager_unittest.cc", "//components/sync_device_info/device_info_sync_bridge_unittest.cc",