From 193b57fb446e95f966579661466c5b58ca7ed923 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Wed, 10 Jul 2024 00:01:18 +0300 Subject: [PATCH] Uplift of #24535 (squashed) to beta --- .../android/sync_service_android_bridge.cc | 29 +++++++++++++++++++ .../android/sync_service_android_bridge.h | 18 ++++++++++++ .../sync/service/sync_user_settings.h | 24 +++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 chromium_src/components/sync/android/sync_service_android_bridge.cc create mode 100644 chromium_src/components/sync/android/sync_service_android_bridge.h create mode 100644 chromium_src/components/sync/service/sync_user_settings.h diff --git a/chromium_src/components/sync/android/sync_service_android_bridge.cc b/chromium_src/components/sync/android/sync_service_android_bridge.cc new file mode 100644 index 000000000000..4cefedbbbfa6 --- /dev/null +++ b/chromium_src/components/sync/android/sync_service_android_bridge.cc @@ -0,0 +1,29 @@ +/* Copyright (c) 2024 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 "components/sync/android/sync_service_android_bridge.h" + +#include "components/sync/service/sync_user_settings.h" + +#define KeepAccountSettingsPrefsOnlyForUsers \ + KeepAccountSettingsPrefsOnlyForUsers_Unused +#include "src/components/sync/android/sync_service_android_bridge.cc" +#undef KeepAccountSettingsPrefsOnlyForUsers + +// Along with SyncUserSettings::KeepAccountSettingsPrefsOnlyForUsers_Unused +// makes this method do nothing. +// We need it on Android because Brave Browser doesn't use Google Account +// to run Brave Sync. Otherwise empty gaia_ids arrives to +// SyncTransportDataPrefs::KeepAccountSettingsPrefsOnlyForUsers, where +// "Clears all account-keyed preferences for all accounts that are NOT in +// `available_gaia_ids`." So all kSyncTransportDataPerAccount gets wiped. +// Then ValidateSyncTransportData at sync_engine_impl.cc fails and +// SyncEngineImpl::Initialize overwrites sync transport prefs. Device with new +// generated cache guid is sent to the chain and all other devices see the +// duplicated entry in addition to other possible mess. +// To avoid this, override with empty implementation. +void SyncServiceAndroidBridge::KeepAccountSettingsPrefsOnlyForUsers( + JNIEnv* env, + const base::android::JavaParamRef& gaia_ids) {} diff --git a/chromium_src/components/sync/android/sync_service_android_bridge.h b/chromium_src/components/sync/android/sync_service_android_bridge.h new file mode 100644 index 000000000000..ba75c510c88e --- /dev/null +++ b/chromium_src/components/sync/android/sync_service_android_bridge.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2024 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_ANDROID_SYNC_SERVICE_ANDROID_BRIDGE_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ANDROID_SYNC_SERVICE_ANDROID_BRIDGE_H_ + +#define KeepAccountSettingsPrefsOnlyForUsers \ + KeepAccountSettingsPrefsOnlyForUsers_Unused( \ + JNIEnv* env, const base::android::JavaParamRef& gaia_ids); \ + void KeepAccountSettingsPrefsOnlyForUsers + +#include "src/components/sync/android/sync_service_android_bridge.h" // IWYU pragma: export + +#undef KeepAccountSettingsPrefsOnlyForUsers + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ANDROID_SYNC_SERVICE_ANDROID_BRIDGE_H_ diff --git a/chromium_src/components/sync/service/sync_user_settings.h b/chromium_src/components/sync/service/sync_user_settings.h new file mode 100644 index 000000000000..6feda8612ac8 --- /dev/null +++ b/chromium_src/components/sync/service/sync_user_settings.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2024 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_SERVICE_SYNC_USER_SETTINGS_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SERVICE_SYNC_USER_SETTINGS_H_ + +// We need to expand SyncUserSettings with +// KeepAccountSettingsPrefsOnlyForUsers_Unused method to match override at +// SyncServiceAndroidBridge::KeepAccountSettingsPrefsOnlyForUsers because it now +// call internally +// GetUserSettings()->KeepAccountSettingsPrefsOnlyForUsers_Unused(gaia_id_hashes); + +#define KeepAccountSettingsPrefsOnlyForUsers \ + KeepAccountSettingsPrefsOnlyForUsers_Unused( \ + const std::vector& available_gaia_ids) {} \ + virtual void KeepAccountSettingsPrefsOnlyForUsers + +#include "src/components/sync/service/sync_user_settings.h" // IWYU pragma: export + +#undef KeepAccountSettingsPrefsOnlyForUsers + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SERVICE_SYNC_USER_SETTINGS_H_