diff --git a/browser/android/brave_sync_worker.cc b/browser/android/brave_sync_worker.cc index 38ddea615c92..6773ac719872 100644 --- a/browser/android/brave_sync_worker.cc +++ b/browser/android/brave_sync_worker.cc @@ -163,6 +163,8 @@ void BraveSyncWorker::ResetSync(JNIEnv* env) { if (!sync_service) return; + sync_service->prefs().AddLeaveChainDetail(__FILE__, __LINE__, __func__); + auto* device_info_sync_service = DeviceInfoSyncServiceFactory::GetForProfile(profile_); brave_sync::ResetSync(sync_service, device_info_sync_service, @@ -258,6 +260,8 @@ void BraveSyncWorker::PermanentlyDeleteAccount( auto* sync_service = GetSyncService(); CHECK_NE(sync_service, nullptr); + sync_service->prefs().AddLeaveChainDetail(__FILE__, __LINE__, __func__); + base::android::ScopedJavaGlobalRef java_callback; java_callback.Reset(env, callback); diff --git a/chromium_src/components/sync/service/sync_internals_util.cc b/chromium_src/components/sync/service/sync_internals_util.cc index 56f2e16c989c..401bc2f98790 100644 --- a/chromium_src/components/sync/service/sync_internals_util.cc +++ b/chromium_src/components/sync/service/sync_internals_util.cc @@ -49,6 +49,10 @@ base::Value::Dict ConstructAboutInformation( section_brave_sync.AddBoolStat("OS encryption available"); is_os_encryption_available->Set(OSCrypt::IsEncryptionAvailable()); + Stat* leave_chain_details = + section_brave_sync.AddStringStat("Leave chain details"); + leave_chain_details->Set(brave_sync_service->prefs().GetLeaveChainDetails()); + base::Value::List* details = about_info.FindList(kDetailsKey); DCHECK_NE(details, nullptr); diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 6227b6afb4fe..365c84289d92 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -8,6 +8,7 @@ #include #include "base/base64.h" +#include "base/files/file_path.h" #include "base/logging.h" #include "components/os_crypt/sync/os_crypt.h" #include "components/prefs/pref_registry_simple.h" @@ -23,6 +24,7 @@ const char kSyncFailedDecryptSeedNoticeDismissed[] = "brave_sync_v2.failed_decrypt_seed_notice_dismissed"; const char kSyncAccountDeletedNoticePending[] = "brave_sync_v2.account_deleted_notice_pending"; +const char kSyncLeaveChainDetails[] = "brave_sync_v2.diag.leave_chain_details"; // Deprecated // ============================================================================ @@ -69,6 +71,7 @@ void Prefs::RegisterProfilePrefs(PrefRegistrySimple* registry) { registry->RegisterStringPref(kSyncV2Seed, std::string()); registry->RegisterBooleanPref(kSyncFailedDecryptSeedNoticeDismissed, false); registry->RegisterBooleanPref(kSyncAccountDeletedNoticePending, false); + registry->RegisterStringPref(kSyncLeaveChainDetails, std::string()); } // static @@ -163,6 +166,24 @@ void Prefs::SetSyncAccountDeletedNoticePending(bool is_pending) { pref_service_->SetBoolean(kSyncAccountDeletedNoticePending, is_pending); } +void Prefs::AddLeaveChainDetail(const char* file, int line, const char* func) { + std::string details = pref_service_->GetString(kSyncLeaveChainDetails); + + std::ostringstream stream; + stream << base::Time::Now() << " " + << base::FilePath::FromASCII(file).BaseName() << "(" << line << ") " + << func << std::endl; + pref_service_->SetString(kSyncLeaveChainDetails, details + stream.str()); +} + +std::string Prefs::GetLeaveChainDetails() const { + return pref_service_->GetString(kSyncLeaveChainDetails); +} + +void Prefs::ClearLeaveChainDetails() { + pref_service_->ClearPref(kSyncLeaveChainDetails); +} + void Prefs::Clear() { pref_service_->ClearPref(kSyncV2Seed); pref_service_->ClearPref(kSyncFailedDecryptSeedNoticeDismissed); diff --git a/components/brave_sync/brave_sync_prefs.h b/components/brave_sync/brave_sync_prefs.h index 34068ba89a8f..68b3211eed64 100644 --- a/components/brave_sync/brave_sync_prefs.h +++ b/components/brave_sync/brave_sync_prefs.h @@ -45,6 +45,10 @@ class Prefs { bool IsFailedDecryptSeedNoticeDismissed() const; void DismissFailedDecryptSeedNotice(); + void AddLeaveChainDetail(const char* file, int line, const char* func); + std::string GetLeaveChainDetails() const; + void ClearLeaveChainDetails(); + void Clear(); private: diff --git a/components/brave_sync/sync_service_impl_helper.cc b/components/brave_sync/sync_service_impl_helper.cc index 61a00136405e..e791dceb6369 100644 --- a/components/brave_sync/sync_service_impl_helper.cc +++ b/components/brave_sync/sync_service_impl_helper.cc @@ -18,6 +18,7 @@ namespace brave_sync { void ResetSync(syncer::BraveSyncServiceImpl* sync_service_impl, syncer::DeviceInfoSyncService* device_info_service, base::OnceClosure on_reset_done) { + sync_service_impl->prefs().AddLeaveChainDetail(__FILE__, __LINE__, __func__); if (sync_service_impl->GetTransportState() != syncer::SyncService::TransportState::ACTIVE) { sync_service_impl->OnSelfDeviceInfoDeleted(std::move(on_reset_done)); diff --git a/components/sync/service/brave_sync_service_impl.cc b/components/sync/service/brave_sync_service_impl.cc index d680a10138a3..0e641ae64ecb 100644 --- a/components/sync/service/brave_sync_service_impl.cc +++ b/components/sync/service/brave_sync_service_impl.cc @@ -61,6 +61,7 @@ bool BraveSyncServiceImpl::IsSetupInProgress() const { } void BraveSyncServiceImpl::StopAndClear() { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); // Clear prefs before StopAndClear() to make NotifyObservers() be invoked brave_sync_prefs_.Clear(); SyncServiceImpl::StopAndClear(); @@ -107,6 +108,7 @@ bool BraveSyncServiceImpl::SetSyncCode(const std::string& sync_code) { } void BraveSyncServiceImpl::OnSelfDeviceInfoDeleted(base::OnceClosure cb) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); initiated_self_device_info_deleted_ = true; // This function will follow normal reset process and set SyncRequested to // false @@ -154,8 +156,11 @@ void BraveSyncServiceImpl::OnBraveSyncPrefsChanged(const std::string& path) { syncer::UserSelectableTypeSet selected_types; selected_types.Put(UserSelectableType::kBookmarks); GetUserSettings()->SetSelectedTypes(false, selected_types); + + brave_sync_prefs_.ClearLeaveChainDetails(); } else { VLOG(1) << "Brave sync seed cleared"; + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); GetBraveSyncAuthManager()->ResetKeys(); // Send updated status here, because OnDeviceInfoChange is not triggered // when device leaves the chain by `Leave Sync Chain` button @@ -215,6 +220,7 @@ void BraveSyncServiceImpl::OnAccountDeleted( const int current_attempt, base::OnceCallback callback, const SyncProtocolError& sync_protocol_error) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); if (sync_protocol_error.error_type == SYNC_SUCCESS) { std::move(callback).Run(sync_protocol_error); // If request succeded - reset and clear all in a forced way @@ -240,6 +246,7 @@ void BraveSyncServiceImpl::OnAccountDeleted( void BraveSyncServiceImpl::PermanentlyDeleteAccountImpl( const int current_attempt, base::OnceCallback callback) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); if (!engine_) { // We can reach here if two devices almost at the same time will initiate // the deletion procedure @@ -259,6 +266,7 @@ void BraveSyncServiceImpl::PermanentlyDeleteAccountImpl( void BraveSyncServiceImpl::PermanentlyDeleteAccount( base::OnceCallback callback) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); initiated_delete_account_ = true; PermanentlyDeleteAccountImpl(1, std::move(callback)); } @@ -275,12 +283,14 @@ void BraveSyncServiceImpl::ResetEngine(ShutdownReason shutdown_reason, reset_reason == ResetEngineReason::kDisabledAccount && sync_disabled_by_admin_ && !initiated_delete_account_ && !initiated_join_chain_) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); brave_sync_prefs_.SetSyncAccountDeletedNoticePending(true); // Forcing stop and clear, because sync account was deleted BraveSyncServiceImpl::StopAndClear(); } else if (shutdown_reason == ShutdownReason::DISABLE_SYNC_AND_CLEAR_DATA && reset_reason == ResetEngineReason::kDisabledAccount && sync_disabled_by_admin_ && initiated_join_chain_) { + brave_sync_prefs_.AddLeaveChainDetail(__FILE__, __LINE__, __func__); // Forcing stop and clear, because we are trying to join the sync chain, but // sync account was deleted BraveSyncServiceImpl::StopAndClear(); diff --git a/components/sync/service/brave_sync_service_impl.h b/components/sync/service/brave_sync_service_impl.h index c77d5731e6e0..9c1fedfc1e23 100644 --- a/components/sync/service/brave_sync_service_impl.h +++ b/components/sync/service/brave_sync_service_impl.h @@ -60,7 +60,8 @@ class BraveSyncServiceImpl : public SyncServiceImpl { void Initialize() override; - const brave_sync::Prefs& prefs() { return brave_sync_prefs_; } + const brave_sync::Prefs& prefs() const { return brave_sync_prefs_; } + brave_sync::Prefs& prefs() { return brave_sync_prefs_; } void PermanentlyDeleteAccount( base::OnceCallback callback); diff --git a/ios/browser/api/sync/brave_sync_worker.cc b/ios/browser/api/sync/brave_sync_worker.cc index 7ccb93830ed8..52d5af243982 100644 --- a/ios/browser/api/sync/brave_sync_worker.cc +++ b/ios/browser/api/sync/brave_sync_worker.cc @@ -313,6 +313,8 @@ void BraveSyncWorker::ResetSync() { return; } + sync_service->prefs().AddLeaveChainDetail(__FILE__, __LINE__, __func__); + auto* device_info_service = DeviceInfoSyncServiceFactory::GetForBrowserState(browser_state_); DCHECK(device_info_service); @@ -358,6 +360,8 @@ void BraveSyncWorker::PermanentlyDeleteAccount( return; } + sync_service->prefs().AddLeaveChainDetail(__FILE__, __LINE__, __func__); + sync_service->PermanentlyDeleteAccount(std::move(callback)); }