[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
This commit is contained in:
cdesouza-chromium
2026-05-02 00:52:35 +01:00
committed by GitHub
parent a1bb07bf14
commit 4df5363858
21 changed files with 232 additions and 263 deletions
@@ -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"
@@ -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"
@@ -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 <components/sync_device_info/device_info.cc>
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<int>(last_updated_timestamp().ToTimeT()));
dict.Set("sendTabToSelfReceivingEnabled",
send_tab_to_self_receiving_enabled());
dict.Set("hasSharingInfo", sharing_info().has_value());
return dict;
}
} // namespace syncer
@@ -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 <components/sync_device_info/device_info.h> // IWYU pragma: export
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
@@ -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<BraveDeviceInfo> BraveSpecificsToModel(
std::unique_ptr<DeviceInfo> BraveSpecificsToModel(
const DeviceInfoSpecifics& specifics) {
DataTypeSet data_types;
for (const int field_number :
@@ -59,7 +58,7 @@ std::unique_ptr<BraveDeviceInfo> BraveSpecificsToModel(
}
// The code is duplicated from SpecificsToModel by intent to avoid use of
// extra patch
return std::make_unique<BraveDeviceInfo>(
return std::make_unique<DeviceInfo>(
specifics.cache_guid(), specifics.client_name(),
specifics.chrome_version(), specifics.sync_user_agent(),
ToDeviceInfoDeviceType(specifics.device_type()),
@@ -77,6 +76,7 @@ std::unique_ptr<BraveDeviceInfo> 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::unique_ptr<BraveDeviceInfo>>
std::vector<std::unique_ptr<DeviceInfo>>
DeviceInfoSyncBridge::GetAllBraveDeviceInfo() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
TRACE_EVENT0("sync", "DeviceInfoSyncBridge::GetAllBraveDeviceInfo");
std::vector<std::unique_ptr<BraveDeviceInfo>> list;
std::vector<std::unique_ptr<DeviceInfo>> 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::unique_ptr<BraveDeviceInfo>>
std::vector<std::unique_ptr<DeviceInfo>>
DeviceInfoTracker::GetAllBraveDeviceInfo() const {
NOTREACHED() << "This function must be overriden";
}
@@ -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<std::unique_ptr<BraveDeviceInfo>> GetAllBraveDeviceInfo() \
std::vector<std::unique_ptr<DeviceInfo>> GetAllBraveDeviceInfo() \
const override; \
void ForcePulseForTest
@@ -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<std::unique_ptr<BraveDeviceInfo>> \
GetAllBraveDeviceInfo() const; \
virtual std::vector<std::unique_ptr<DeviceInfo>> GetAllBraveDeviceInfo() \
const; \
virtual void ForcePulseForTest
#include <components/sync_device_info/device_info_tracker.h> // IWYU pragma: export
@@ -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 <components/sync_device_info/fake_device_info_tracker.cc>
namespace syncer {
@@ -12,9 +10,9 @@ namespace syncer {
void FakeDeviceInfoTracker::DeleteDeviceInfo(const std::string& client_id,
base::OnceClosure callback) {}
std::vector<std::unique_ptr<BraveDeviceInfo>>
std::vector<std::unique_ptr<DeviceInfo>>
FakeDeviceInfoTracker::GetAllBraveDeviceInfo() const {
return std::vector<std::unique_ptr<BraveDeviceInfo>>();
return std::vector<std::unique_ptr<DeviceInfo>>();
}
} // namespace syncer
@@ -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<std::unique_ptr<BraveDeviceInfo>> GetAllBraveDeviceInfo() \
std::vector<std::unique_ptr<DeviceInfo>> GetAllBraveDeviceInfo() \
const override; \
void ForcePulseForTest
@@ -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::unique_ptr<BraveDeviceInfo>>());
std::vector<std::unique_ptr<DeviceInfo>>());
};
} // namespace syncer
@@ -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 <optional>
#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<DeviceInfo::SharingInfo>& sharing_info,
const std::optional<PhoneAsASecurityKeyInfo>& paask_info,
const std::string& fcm_registration_token,
const DataTypeSet& interested_data_types,
std::optional<base::Time> 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<int>(last_updated_timestamp().ToTimeT()));
dict.Set("sendTabToSelfReceivingEnabled",
send_tab_to_self_receiving_enabled());
dict.Set("hasSharingInfo", sharing_info().has_value());
return dict;
}
} // namespace syncer
@@ -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 <optional>
#include <string>
#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<DeviceInfo::SharingInfo>& sharing_info,
const std::optional<PhoneAsASecurityKeyInfo>& paask_info,
const std::string& fcm_registration_token,
const DataTypeSet& interested_data_types,
std::optional<base::Time> 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_
-10
View File
@@ -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 = []
+2 -3
View File
@@ -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::unique_ptr<syncer::BraveDeviceInfo>>
std::vector<std::unique_ptr<syncer::DeviceInfo>>
BraveSyncWorker::GetDeviceList() {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
auto* device_info_service =
DeviceInfoSyncServiceFactory::GetForProfile(profile_);
if (!device_info_service) {
return std::vector<std::unique_ptr<syncer::BraveDeviceInfo>>();
return std::vector<std::unique_ptr<syncer::DeviceInfo>>();
}
syncer::DeviceInfoTracker* tracker =
+1 -2
View File
@@ -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<std::unique_ptr<syncer::BraveDeviceInfo>> GetDeviceList();
std::vector<std::unique_ptr<syncer::DeviceInfo>> GetDeviceList();
bool CanSyncFeatureStart();
bool IsSyncFeatureActive();
bool IsInitialSyncFeatureSetupComplete();
@@ -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") {
@@ -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<base::Time> 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;
@@ -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<base::Time> 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
@@ -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") {
@@ -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
@@ -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