From 4df5363858d2d2c8c8e1fb2914e072e0db40af56 Mon Sep 17 00:00:00 2001 From: cdesouza-chromium Date: Sat, 2 May 2026 00:52:35 +0100 Subject: [PATCH] [plaster] Migrate `DeviceInfo` override (#35958) This PR rewrites our overrides relating to `DeviceInfo` specifically into plaster. This involves dropping `BraveDeviceInfo` and implementing the functionality in terms of extending `DeviceInfo` Resolves https://github.com/brave/brave-browser/issues/55018 --- browser/sync/brave_sync_devices_android.cc | 1 - .../ui/webui/settings/brave_sync_handler.cc | 1 - .../sync_device_info/device_info.cc | 68 ++++++++++ .../components/sync_device_info/device_info.h | 14 ++ .../device_info_sync_bridge.cc | 12 +- .../device_info_sync_bridge.h | 3 +- .../sync_device_info/device_info_tracker.h | 10 +- .../fake_device_info_tracker.cc | 6 +- .../fake_device_info_tracker.h | 3 +- ...history_url_visit_data_fetcher_unittest.cc | 3 +- .../sync_device_info/brave_device_info.cc | 125 ------------------ .../sync_device_info/brave_device_info.h | 70 ---------- components/sync_device_info/sources.gni | 10 -- ios/browser/api/sync/brave_sync_worker.cc | 5 +- ios/browser/api/sync/brave_sync_worker.h | 3 +- ...components-sync_device_info-BUILD.gn.patch | 12 -- ...ents-sync_device_info-device_info.cc.patch | 24 ++++ ...nents-sync_device_info-device_info.h.patch | 32 ++++- ...isited_url_ranking-internal-BUILD.gn.patch | 12 -- .../sync_device_info/device_info.cc.toml | 27 ++++ .../sync_device_info/device_info.h.toml | 54 ++++++++ 21 files changed, 232 insertions(+), 263 deletions(-) create mode 100644 chromium_src/components/sync_device_info/device_info.cc create mode 100644 chromium_src/components/sync_device_info/device_info.h delete mode 100644 components/sync_device_info/brave_device_info.cc delete mode 100644 components/sync_device_info/brave_device_info.h delete mode 100644 components/sync_device_info/sources.gni delete mode 100644 patches/components-sync_device_info-BUILD.gn.patch create mode 100644 patches/components-sync_device_info-device_info.cc.patch delete mode 100644 patches/components-visited_url_ranking-internal-BUILD.gn.patch create mode 100644 rewrite/components/sync_device_info/device_info.cc.toml create mode 100644 rewrite/components/sync_device_info/device_info.h.toml diff --git a/browser/sync/brave_sync_devices_android.cc b/browser/sync/brave_sync_devices_android.cc index 713a27c371f..8db882f3ccf 100644 --- a/browser/sync/brave_sync_devices_android.cc +++ b/browser/sync/brave_sync_devices_android.cc @@ -16,7 +16,6 @@ #include "base/logging.h" #include "brave/components/brave_sync/sync_service_impl_helper.h" #include "brave/components/sync/service/brave_sync_service_impl.h" -#include "brave/components/sync_device_info/brave_device_info.h" #include "chrome/android/chrome_jni_headers/BraveSyncDevices_jni.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/sync/device_info_sync_service_factory.h" diff --git a/browser/ui/webui/settings/brave_sync_handler.cc b/browser/ui/webui/settings/brave_sync_handler.cc index f171eadf0ef..142690e95f9 100644 --- a/browser/ui/webui/settings/brave_sync_handler.cc +++ b/browser/ui/webui/settings/brave_sync_handler.cc @@ -23,7 +23,6 @@ #include "brave/components/brave_sync/sync_service_impl_helper.h" #include "brave/components/brave_sync/time_limited_words.h" #include "brave/components/sync/service/brave_sync_service_impl.h" -#include "brave/components/sync_device_info/brave_device_info.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/device_info_sync_service_factory.h" diff --git a/chromium_src/components/sync_device_info/device_info.cc b/chromium_src/components/sync_device_info/device_info.cc new file mode 100644 index 00000000000..833b10588bd --- /dev/null +++ b/chromium_src/components/sync_device_info/device_info.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2026 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 https://mozilla.org/MPL/2.0/. + +#include "base/values.h" + +#include + +namespace syncer { + +std::string DeviceInfo::GetOSString() const { + switch (os_type()) { + case OsType::kUnknown: + return "unknown"; + case OsType::kWindows: + return "win"; + case OsType::kMac: + return "mac"; + case OsType::kLinux: + return "linux"; + case OsType::kChromeOsAsh: + case OsType::kChromeOsLacros: + return "chrome_os"; + case OsType::kAndroid: + return "android"; + case OsType::kIOS: + return "ios"; + case OsType::kFuchsia: + return "fuchisa"; + } +} + +std::string DeviceInfo::GetDeviceTypeString() const { + switch (form_factor()) { + case FormFactor::kUnknown: + return "unknown"; + case FormFactor::kDesktop: + return "desktop_or_laptop"; + case FormFactor::kPhone: + return "phone"; + case FormFactor::kTablet: + return "tablet"; + case FormFactor::kAutomotive: + return "tablet"; + case FormFactor::kWearable: + return "tablet"; + case FormFactor::kTv: + return "tablet"; + } +} + +base::DictValue DeviceInfo::ToValue() const { + base::DictValue dict; + dict.Set("name", client_name()); + dict.Set("id", public_id()); + dict.Set("os", GetOSString()); + dict.Set("type", GetDeviceTypeString()); + dict.Set("chromeVersion", chrome_version()); + dict.Set("lastUpdatedTimestamp", + static_cast(last_updated_timestamp().ToTimeT())); + dict.Set("sendTabToSelfReceivingEnabled", + send_tab_to_self_receiving_enabled()); + dict.Set("hasSharingInfo", sharing_info().has_value()); + return dict; +} + +} // namespace syncer diff --git a/chromium_src/components/sync_device_info/device_info.h b/chromium_src/components/sync_device_info/device_info.h new file mode 100644 index 00000000000..924f4c3ade2 --- /dev/null +++ b/chromium_src/components/sync_device_info/device_info.h @@ -0,0 +1,14 @@ +// Copyright (c) 2026 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 https://mozilla.org/MPL/2.0/. + +#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ + +#include "base/values.h" + +// This header only exists to add `base/values.h` to the Chromium header. +#include // IWYU pragma: export + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ diff --git a/chromium_src/components/sync_device_info/device_info_sync_bridge.cc b/chromium_src/components/sync_device_info/device_info_sync_bridge.cc index 0b23f223ddc..500ef1bf2e6 100644 --- a/chromium_src/components/sync_device_info/device_info_sync_bridge.cc +++ b/chromium_src/components/sync_device_info/device_info_sync_bridge.cc @@ -6,7 +6,6 @@ #include "components/sync_device_info/device_info_sync_bridge.h" #include "base/logging.h" -#include "brave/components/sync_device_info/brave_device_info.h" #include "components/sync/base/deletion_origin.h" #include "components/sync_device_info/device_info_proto_enum_util.h" @@ -45,7 +44,7 @@ namespace { constexpr int kFailedAttemtpsToAckDeviceDelete = 5; -std::unique_ptr BraveSpecificsToModel( +std::unique_ptr BraveSpecificsToModel( const DeviceInfoSpecifics& specifics) { DataTypeSet data_types; for (const int field_number : @@ -59,7 +58,7 @@ std::unique_ptr BraveSpecificsToModel( } // The code is duplicated from SpecificsToModel by intent to avoid use of // extra patch - return std::make_unique( + return std::make_unique( specifics.cache_guid(), specifics.client_name(), specifics.chrome_version(), specifics.sync_user_agent(), ToDeviceInfoDeviceType(specifics.device_type()), @@ -77,6 +76,7 @@ std::unique_ptr BraveSpecificsToModel( specifics.invalidation_fields().instance_id_token(), data_types, SpecificsToAutoSignOutLastSigninTimestamp(specifics), specifics.feature_fields().desktop_to_ios_promo_receiving_enabled(), + SpecificsToDesktopToIOSPromoReceivingTypes(specifics), specifics.has_brave_fields() && specifics.brave_fields().has_is_self_delete_supported() && specifics.brave_fields().is_self_delete_supported()); @@ -120,11 +120,11 @@ void DeviceInfoSyncBridge::OnDeviceInfoDeleted(const std::string& client_id, } } -std::vector> +std::vector> DeviceInfoSyncBridge::GetAllBraveDeviceInfo() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); TRACE_EVENT0("sync", "DeviceInfoSyncBridge::GetAllBraveDeviceInfo"); - std::vector> list; + std::vector> list; for (const auto& data : all_data_) { list.push_back(BraveSpecificsToModel(data.second.specifics())); } @@ -156,7 +156,7 @@ void DeviceInfoSyncBridge::RefreshLocalDeviceInfoIfNeeded() { // translation unit, and the clang plugin wont allow the definition in the // header. This function has to provide a dead definition, otherwise there are // certain types of breakages that require patching upstream code. -std::vector> +std::vector> DeviceInfoTracker::GetAllBraveDeviceInfo() const { NOTREACHED() << "This function must be overriden"; } diff --git a/chromium_src/components/sync_device_info/device_info_sync_bridge.h b/chromium_src/components/sync_device_info/device_info_sync_bridge.h index 5480f3a90c0..5883a7716e4 100644 --- a/chromium_src/components/sync_device_info/device_info_sync_bridge.h +++ b/chromium_src/components/sync_device_info/device_info_sync_bridge.h @@ -6,13 +6,12 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_ -#include "brave/components/sync_device_info/brave_device_info.h" #include "components/sync_device_info/device_info_tracker.h" #define ForcePulseForTest \ DeleteDeviceInfo(const std::string& client_id, base::OnceClosure callback) \ override; \ - std::vector> GetAllBraveDeviceInfo() \ + std::vector> GetAllBraveDeviceInfo() \ const override; \ void ForcePulseForTest diff --git a/chromium_src/components/sync_device_info/device_info_tracker.h b/chromium_src/components/sync_device_info/device_info_tracker.h index 992d8707cba..5c251063dd1 100644 --- a/chromium_src/components/sync_device_info/device_info_tracker.h +++ b/chromium_src/components/sync_device_info/device_info_tracker.h @@ -8,17 +8,11 @@ #include "base/functional/callback.h" -namespace syncer { - -class BraveDeviceInfo; - -} // namespace syncer - #define ForcePulseForTest \ DeleteDeviceInfo(const std::string& client_id, base::OnceClosure callback) { \ } \ - virtual std::vector> \ - GetAllBraveDeviceInfo() const; \ + virtual std::vector> GetAllBraveDeviceInfo() \ + const; \ virtual void ForcePulseForTest #include // IWYU pragma: export diff --git a/chromium_src/components/sync_device_info/fake_device_info_tracker.cc b/chromium_src/components/sync_device_info/fake_device_info_tracker.cc index 8b284c69eb4..b3807bc2a9e 100644 --- a/chromium_src/components/sync_device_info/fake_device_info_tracker.cc +++ b/chromium_src/components/sync_device_info/fake_device_info_tracker.cc @@ -3,8 +3,6 @@ // 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/. -#include "brave/components/sync_device_info/brave_device_info.h" - #include namespace syncer { @@ -12,9 +10,9 @@ namespace syncer { void FakeDeviceInfoTracker::DeleteDeviceInfo(const std::string& client_id, base::OnceClosure callback) {} -std::vector> +std::vector> FakeDeviceInfoTracker::GetAllBraveDeviceInfo() const { - return std::vector>(); + return std::vector>(); } } // namespace syncer diff --git a/chromium_src/components/sync_device_info/fake_device_info_tracker.h b/chromium_src/components/sync_device_info/fake_device_info_tracker.h index c702d620b42..fb9525629cb 100644 --- a/chromium_src/components/sync_device_info/fake_device_info_tracker.h +++ b/chromium_src/components/sync_device_info/fake_device_info_tracker.h @@ -6,13 +6,12 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_FAKE_DEVICE_INFO_TRACKER_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_FAKE_DEVICE_INFO_TRACKER_H_ -#include "brave/components/sync_device_info/brave_device_info.h" #include "components/sync_device_info/device_info_tracker.h" #define ForcePulseForTest \ DeleteDeviceInfo(const std::string& client_id, base::OnceClosure callback) \ override; \ - std::vector> GetAllBraveDeviceInfo() \ + std::vector> GetAllBraveDeviceInfo() \ const override; \ void ForcePulseForTest diff --git a/chromium_src/components/visited_url_ranking/internal/history_url_visit_data_fetcher_unittest.cc b/chromium_src/components/visited_url_ranking/internal/history_url_visit_data_fetcher_unittest.cc index 63fb86cb8f2..53151cb422c 100644 --- a/chromium_src/components/visited_url_ranking/internal/history_url_visit_data_fetcher_unittest.cc +++ b/chromium_src/components/visited_url_ranking/internal/history_url_visit_data_fetcher_unittest.cc @@ -3,7 +3,6 @@ * 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/. */ -#include "brave/components/sync_device_info/brave_device_info.h" #include "components/history/core/browser/history_service.h" #include "components/sync_device_info/device_info_tracker.h" #include "testing/gmock/include/gmock/gmock.h" @@ -14,7 +13,7 @@ namespace syncer { class BraveDeviceInfoTracker : public syncer::DeviceInfoTracker { public: MOCK_CONST_METHOD0(GetAllBraveDeviceInfo, - std::vector>()); + std::vector>()); }; } // namespace syncer diff --git a/components/sync_device_info/brave_device_info.cc b/components/sync_device_info/brave_device_info.cc deleted file mode 100644 index 929e3a96647..00000000000 --- a/components/sync_device_info/brave_device_info.cc +++ /dev/null @@ -1,125 +0,0 @@ -/* 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/. */ - -#include "brave/components/sync_device_info/brave_device_info.h" - -#include - -#include "base/values.h" - -namespace syncer { - -BraveDeviceInfo::BraveDeviceInfo( - const std::string& guid, - const std::string& client_name, - const std::string& chrome_version, - const std::string& sync_user_agent, - const DeviceType device_type, - const OsType os_type, - const FormFactor form_factor, - const std::string& signin_scoped_device_id, - const std::string& manufacturer_name, - const std::string& model_name, - const std::string& full_hardware_class, - base::Time last_updated_timestamp, - base::TimeDelta pulse_interval, - bool send_tab_to_self_receiving_enabled, - SendTabReceivingType send_tab_to_self_receiving_type, - const std::optional& sharing_info, - const std::optional& paask_info, - const std::string& fcm_registration_token, - const DataTypeSet& interested_data_types, - std::optional floating_workspace_last_signin_timestamp, - bool desktop_to_ios_promo_receiving_enabled, - bool is_self_delete_supported) - : DeviceInfo(guid, - client_name, - chrome_version, - sync_user_agent, - device_type, - os_type, - form_factor, - signin_scoped_device_id, - manufacturer_name, - model_name, - full_hardware_class, - last_updated_timestamp, - pulse_interval, - send_tab_to_self_receiving_enabled, - send_tab_to_self_receiving_type, - sharing_info, - paask_info, - fcm_registration_token, - interested_data_types, - floating_workspace_last_signin_timestamp, - desktop_to_ios_promo_receiving_enabled), - is_self_delete_supported_(is_self_delete_supported) {} - -bool BraveDeviceInfo::is_self_delete_supported() const { - return is_self_delete_supported_; -} - -void BraveDeviceInfo::set_is_self_delete_supported( - bool is_self_delete_supported) { - is_self_delete_supported_ = is_self_delete_supported; -} - -std::string BraveDeviceInfo::GetOSString() const { - switch (os_type()) { - case OsType::kUnknown: - return "unknown"; - case OsType::kWindows: - return "win"; - case OsType::kMac: - return "mac"; - case OsType::kLinux: - return "linux"; - case OsType::kChromeOsAsh: - case OsType::kChromeOsLacros: - return "chrome_os"; - case OsType::kAndroid: - return "android"; - case OsType::kIOS: - return "ios"; - case OsType::kFuchsia: - return "fuchisa"; - } -} - -std::string BraveDeviceInfo::GetDeviceTypeString() const { - switch (form_factor()) { - case FormFactor::kUnknown: - return "unknown"; - case FormFactor::kDesktop: - return "desktop_or_laptop"; - case FormFactor::kPhone: - return "phone"; - case FormFactor::kTablet: - return "tablet"; - case FormFactor::kAutomotive: - return "tablet"; - case FormFactor::kWearable: - return "tablet"; - case FormFactor::kTv: - return "tablet"; - } -} - -base::DictValue BraveDeviceInfo::ToValue() const { - base::DictValue dict; - dict.Set("name", client_name()); - dict.Set("id", public_id()); - dict.Set("os", GetOSString()); - dict.Set("type", GetDeviceTypeString()); - dict.Set("chromeVersion", chrome_version()); - dict.Set("lastUpdatedTimestamp", - static_cast(last_updated_timestamp().ToTimeT())); - dict.Set("sendTabToSelfReceivingEnabled", - send_tab_to_self_receiving_enabled()); - dict.Set("hasSharingInfo", sharing_info().has_value()); - return dict; -} - -} // namespace syncer diff --git a/components/sync_device_info/brave_device_info.h b/components/sync_device_info/brave_device_info.h deleted file mode 100644 index 1675330812b..00000000000 --- a/components/sync_device_info/brave_device_info.h +++ /dev/null @@ -1,70 +0,0 @@ -/* 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/. */ - -#ifndef BRAVE_COMPONENTS_SYNC_DEVICE_INFO_BRAVE_DEVICE_INFO_H_ -#define BRAVE_COMPONENTS_SYNC_DEVICE_INFO_BRAVE_DEVICE_INFO_H_ - -#include -#include - -#include "base/time/time.h" -#include "components/sync/protocol/sync.pb.h" -#include "components/sync_device_info/device_info.h" - -namespace base { -class DictionaryValue; -} - -namespace syncer { - -class BraveDeviceInfo : public DeviceInfo { - public: - BraveDeviceInfo( - const std::string& guid, - const std::string& client_name, - const std::string& chrome_version, - const std::string& sync_user_agent, - const DeviceType device_type, - const OsType os_type, - const FormFactor form_factor, - const std::string& signin_scoped_device_id, - const std::string& manufacturer_name, - const std::string& model_name, - const std::string& full_hardware_class, - base::Time last_updated_timestamp, - base::TimeDelta pulse_interval, - bool send_tab_to_self_receiving_enabled, - SendTabReceivingType send_tab_to_self_receiving_type, - const std::optional& sharing_info, - const std::optional& paask_info, - const std::string& fcm_registration_token, - const DataTypeSet& interested_data_types, - std::optional floating_workspace_last_signin_timestamp, - bool desktop_to_ios_promo_receiving_enabled, - bool is_self_delete_supported); - BraveDeviceInfo(const BraveDeviceInfo&) = delete; - BraveDeviceInfo& operator=(const BraveDeviceInfo&) = delete; - ~BraveDeviceInfo() override {} - - bool is_self_delete_supported() const; - void set_is_self_delete_supported(bool is_self_delete_supported); - - // Gets the OS in string form. - std::string GetOSString() const; - - // Gets the device type in string form. - std::string GetDeviceTypeString() const; - - // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, - // which extension APIs can expose to third party apps. - base::DictValue ToValue() const; - - private: - bool is_self_delete_supported_; -}; - -} // namespace syncer - -#endif // BRAVE_COMPONENTS_SYNC_DEVICE_INFO_BRAVE_DEVICE_INFO_H_ diff --git a/components/sync_device_info/sources.gni b/components/sync_device_info/sources.gni deleted file mode 100644 index d9863c28300..00000000000 --- a/components/sync_device_info/sources.gni +++ /dev/null @@ -1,10 +0,0 @@ -# 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/. - -brave_components_sync_device_info_sources = [ - "//brave/components/sync_device_info/brave_device_info.cc", - "//brave/components/sync_device_info/brave_device_info.h", -] -brave_components_sync_device_info_deps = [] diff --git a/ios/browser/api/sync/brave_sync_worker.cc b/ios/browser/api/sync/brave_sync_worker.cc index a8c5a3a4ae0..58751f68cb9 100644 --- a/ios/browser/api/sync/brave_sync_worker.cc +++ b/ios/browser/api/sync/brave_sync_worker.cc @@ -24,7 +24,6 @@ #include "brave/components/brave_sync/sync_service_impl_helper.h" #include "brave/components/brave_sync/time_limited_words.h" #include "brave/components/sync/service/brave_sync_service_impl.h" -#include "brave/components/sync_device_info/brave_device_info.h" #include "components/sync/engine/sync_protocol_error.h" #include "components/sync/service/sync_service.h" #include "components/sync/service/sync_service_impl.h" @@ -122,14 +121,14 @@ const syncer::DeviceInfo* BraveSyncWorker::GetLocalDeviceInfo() { ->GetLocalDeviceInfo(); } -std::vector> +std::vector> BraveSyncWorker::GetDeviceList() { DCHECK_CURRENTLY_ON(web::WebThread::UI); auto* device_info_service = DeviceInfoSyncServiceFactory::GetForProfile(profile_); if (!device_info_service) { - return std::vector>(); + return std::vector>(); } syncer::DeviceInfoTracker* tracker = diff --git a/ios/browser/api/sync/brave_sync_worker.h b/ios/browser/api/sync/brave_sync_worker.h index 926fb94cab1..328c00fdc6a 100644 --- a/ios/browser/api/sync/brave_sync_worker.h +++ b/ios/browser/api/sync/brave_sync_worker.h @@ -27,7 +27,6 @@ struct SyncProtocolError; namespace syncer { class BraveSyncServiceImpl; class DeviceInfo; -class BraveDeviceInfo; class SyncServiceImpl; } // namespace syncer @@ -94,7 +93,7 @@ class BraveSyncWorker : public syncer::SyncServiceObserver { std::string GetTimeLimitedWordsFromWords(const std::string& words); std::string GetHexSeedFromQrCodeJson(const std::string& json); const syncer::DeviceInfo* GetLocalDeviceInfo(); - std::vector> GetDeviceList(); + std::vector> GetDeviceList(); bool CanSyncFeatureStart(); bool IsSyncFeatureActive(); bool IsInitialSyncFeatureSetupComplete(); diff --git a/patches/components-sync_device_info-BUILD.gn.patch b/patches/components-sync_device_info-BUILD.gn.patch deleted file mode 100644 index e2715c79ad8..00000000000 --- a/patches/components-sync_device_info-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync_device_info/BUILD.gn b/components/sync_device_info/BUILD.gn -index d2059cb12f6624702ede57f25f57df91a9a7b7ad..d2d21fc837c50cab1efbb259aba99b08f5f4ab40 100644 ---- a/components/sync_device_info/BUILD.gn -+++ b/components/sync_device_info/BUILD.gn -@@ -92,6 +92,7 @@ static_library("sync_device_info") { - if (is_win) { - sources += [ "local_device_info_util_win.cc" ] - } -+ import("//brave/components/sync_device_info/sources.gni") sources += brave_components_sync_device_info_sources deps += brave_components_sync_device_info_deps - } - - static_library("test_support") { diff --git a/patches/components-sync_device_info-device_info.cc.patch b/patches/components-sync_device_info-device_info.cc.patch new file mode 100644 index 00000000000..174f342a58a --- /dev/null +++ b/patches/components-sync_device_info-device_info.cc.patch @@ -0,0 +1,24 @@ +diff --git a/components/sync_device_info/device_info.cc b/components/sync_device_info/device_info.cc +index f828751332055e70fef223044da7dc6944f221a3..c578d1169cb46de6d8cfe3b18b717a7f20d3698c 100644 +--- a/components/sync_device_info/device_info.cc ++++ b/components/sync_device_info/device_info.cc +@@ -81,7 +81,8 @@ DeviceInfo::DeviceInfo( + std::optional auto_sign_out_last_signin_timestamp, + bool desktop_to_ios_promo_receiving_enabled, + const MobilePromoOnDesktopPromoTypeSet& +- desktop_to_ios_promo_receiving_types) ++ desktop_to_ios_promo_receiving_types, ++ bool is_self_delete_supported) + : guid_(guid), + client_name_(client_name), + chrome_version_(chrome_version), +@@ -105,7 +106,8 @@ DeviceInfo::DeviceInfo( + desktop_to_ios_promo_receiving_enabled_( + desktop_to_ios_promo_receiving_enabled), + desktop_to_ios_promo_receiving_types_( +- desktop_to_ios_promo_receiving_types) {} ++ desktop_to_ios_promo_receiving_types), ++ is_self_delete_supported_(is_self_delete_supported) {} + + DeviceInfo::~DeviceInfo() = default; + diff --git a/patches/components-sync_device_info-device_info.h.patch b/patches/components-sync_device_info-device_info.h.patch index 0952248c07d..7a1852e461b 100644 --- a/patches/components-sync_device_info-device_info.h.patch +++ b/patches/components-sync_device_info-device_info.h.patch @@ -1,12 +1,38 @@ diff --git a/components/sync_device_info/device_info.h b/components/sync_device_info/device_info.h -index 0de973ef3cfb970cfdbc773cc8be98ae6d384750..23f5d53a8e07152299850f6998abd9c08d164792 100644 +index 0de973ef3cfb970cfdbc773cc8be98ae6d384750..ee4159c9b15a0661067646a5169f93c1691052bc 100644 --- a/components/sync_device_info/device_info.h +++ b/components/sync_device_info/device_info.h -@@ -197,6 +197,7 @@ class DeviceInfo { +@@ -192,12 +192,24 @@ class DeviceInfo { + std::optional auto_sign_out_last_signin_timestamp, + bool desktop_to_ios_promo_receiving_enabled, + const MobilePromoOnDesktopPromoTypeSet& +- desktop_to_ios_promo_receiving_types = {}); ++ desktop_to_ios_promo_receiving_types = {}, ++ bool is_self_delete_supported = false); + DeviceInfo(const DeviceInfo&) = delete; DeviceInfo& operator=(const DeviceInfo&) = delete; -+ virtual ~DeviceInfo(); ++ bool is_self_delete_supported() const { return is_self_delete_supported_; } ++ void set_is_self_delete_supported(bool is_self_delete_supported) { ++ is_self_delete_supported_ = is_self_delete_supported; ++ } ++ // Gets the OS in string form. ++ std::string GetOSString() const; ++ // Gets the device type in string form. ++ std::string GetDeviceTypeString() const; ++ // Converts the DeviceInfo values to a JS friendly DictionaryValue, ++ // which extension APIs can expose to third party apps. ++ base::DictValue ToValue() const; // Sync specific unique identifier for the device. Note if a device + // is wiped and sync is set up again this id WILL be different. +@@ -372,6 +384,7 @@ class DeviceInfo { + // NOTE: when adding a member, don't forget to update + // |StoredDeviceInfoStillAccurate| in device_info_sync_bridge.cc or else + // changes in that member might not trigger uploads of updated DeviceInfos. ++ bool is_self_delete_supported_; + }; + + } // namespace syncer diff --git a/patches/components-visited_url_ranking-internal-BUILD.gn.patch b/patches/components-visited_url_ranking-internal-BUILD.gn.patch deleted file mode 100644 index 8e86daf5c41..00000000000 --- a/patches/components-visited_url_ranking-internal-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/visited_url_ranking/internal/BUILD.gn b/components/visited_url_ranking/internal/BUILD.gn -index 542534c5a23d5125c2ca7be315d9e4c6f14f72bc..e9d700aeb3bb2e327ffe3381fc1cf28e2287cde1 100644 ---- a/components/visited_url_ranking/internal/BUILD.gn -+++ b/components/visited_url_ranking/internal/BUILD.gn -@@ -120,6 +120,7 @@ source_set("test_support") { - "//testing/gmock", - "//testing/gtest", - ] -+ import("//brave/components/sync_device_info/sources.gni") sources += brave_components_sync_device_info_sources deps += brave_components_sync_device_info_deps - } - - source_set("unit_tests") { diff --git a/rewrite/components/sync_device_info/device_info.cc.toml b/rewrite/components/sync_device_info/device_info.cc.toml new file mode 100644 index 00000000000..240311f3d50 --- /dev/null +++ b/rewrite/components/sync_device_info/device_info.cc.toml @@ -0,0 +1,27 @@ +# Copyright (c) 2026 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 https://mozilla.org/MPL/2.0/. + +[[substitution]] +description = '''Add `is_self_delete_supported` to the ctor. + +This regex always adds the argument as the last one in the argument list. This +is used to initialise `is_self_delete_supported_`. +''' +re_pattern = '(DeviceInfo::DeviceInfo\(.*?)(\)\n\s+:)' +re_flags = ['DOTALL'] +replace = '''\1, + bool is_self_delete_supported\2''' +count = 1 + +[[substitution]] +description = '''Initialize `is_self_delete_supported_` in the constructor + +This always initialises `is_self_delete_supported_` as the last field. +''' +re_pattern = '(DeviceInfo::DeviceInfo\(.*?)( \{\})' +re_flags = ['DOTALL'] +replace = '''\1, + is_self_delete_supported_(is_self_delete_supported)\2''' +count = 1 diff --git a/rewrite/components/sync_device_info/device_info.h.toml b/rewrite/components/sync_device_info/device_info.h.toml new file mode 100644 index 00000000000..a2211e59d38 --- /dev/null +++ b/rewrite/components/sync_device_info/device_info.h.toml @@ -0,0 +1,54 @@ +# Copyright (c) 2026 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 https://mozilla.org/MPL/2.0/. + +[[substitution]] +description = '''Add is_self_delete_supported to the ctor arg list + +Adding `is_self_delete_supported` so it can be used to initialise +`is_self_delete_supported_`. + +This regex matches with the constructor declaration, by checking that there is +a `std::string` somewhere in the list, and adds `is_self_delete_supported` as +the last argument in the list. +''' +re_pattern = '(DeviceInfo\((?=[^)]*std::string).*?)(\);)' +re_flags = ['DOTALL'] +replace = '''\1, + bool is_self_delete_supported = false\2''' +count = 1 + +[[substitution]] +description = '''Add Brave-specific methods to DeviceInfo public interface + +Adding brave-specific methods to this type's interface. This methods used to +exist in Chromium, but they were dropped at some point, and then reinstated on +Brave. +''' +re_pattern = '(~DeviceInfo\(\);)' +replace = '''\1 + bool is_self_delete_supported() const { return is_self_delete_supported_; } + void set_is_self_delete_supported(bool is_self_delete_supported) { + is_self_delete_supported_ = is_self_delete_supported; + } + // Gets the OS in string form. + std::string GetOSString() const; + // Gets the device type in string form. + std::string GetDeviceTypeString() const; + // Converts the DeviceInfo values to a JS friendly DictionaryValue, + // which extension APIs can expose to third party apps. + base::DictValue ToValue() const;''' +count = 1 + +[[substitution]] +description = '''Add is_self_delete_supported_ as last member of DeviceInfo + +This replacement adds `is_self_delete_supported_` as the last member of +`DeviceInfo`. +''' +re_pattern = '(class DeviceInfo \{.*)(\n\};)' +re_flags = ['DOTALL'] +replace = '''\1 + bool is_self_delete_supported_;\2''' +count = 1