Skip to content

Commit

Permalink
Merge pull request #13562 from brave/sync_perman_del_acc
Browse files Browse the repository at this point in the history
Permanently delete sync account
  • Loading branch information
AlexeyBarabash authored Dec 20, 2022
2 parents 1a93317 + de692ee commit 51a81ba
Show file tree
Hide file tree
Showing 79 changed files with 2,178 additions and 168 deletions.
1 change: 1 addition & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/infobar/BraveInfoBarIdentifier.java",
"../../brave/android/java/org/chromium/chrome/browser/infobar/BraveTranslateCompactInfoBarBase.java",
"../../brave/android/java/org/chromium/chrome/browser/informers/BraveAndroidSyncDisabledInformer.java",
"../../brave/android/java/org/chromium/chrome/browser/informers/BraveSyncAccountDeletedInformer.java",
"../../brave/android/java/org/chromium/chrome/browser/language/settings/BraveLanguageSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/BraveStatsTable.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/DatabaseHelper.java",
Expand Down
1 change: 1 addition & 0 deletions android/java/apk_for_test.flags
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
*** mReviewSyncData;
*** mSyncPaymentsIntegration;
*** mSyncReadingList;
*** mSyncAutofill;
*** mTurnOffSync;
}

Expand Down
31 changes: 31 additions & 0 deletions android/java/org/chromium/chrome/browser/BraveSyncWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.SharedPreferences;

import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
Expand Down Expand Up @@ -200,6 +201,32 @@ public void setSyncV2MigrateNoticeDismissed(boolean isDismissed) {
mNativeBraveSyncWorker, isDismissed);
}

@CalledByNative
private static void onPermanentlyDeleteAccountResult(Callback<String> callback, String result) {
callback.onResult(result);
}

public void permanentlyDeleteAccount(Callback<String> callback) {
BraveSyncWorkerJni.get().permanentlyDeleteAccount(mNativeBraveSyncWorker, callback);
}

public void clearAccountDeletedNoticePending() {
BraveSyncWorkerJni.get().clearAccountDeletedNoticePending(mNativeBraveSyncWorker);
}

public boolean isAccountDeletedNoticePending() {
return BraveSyncWorkerJni.get().isAccountDeletedNoticePending(mNativeBraveSyncWorker);
}

@CalledByNative
private static void onJoinSyncChainResult(Callback<Boolean> callback, Boolean result) {
callback.onResult(result);
}

public void setJoinSyncChainCallback(Callback<Boolean> callback) {
BraveSyncWorkerJni.get().setJoinSyncChainCallback(mNativeBraveSyncWorker, callback);
}

@NativeMethods
interface Natives {
void init(BraveSyncWorker caller);
Expand Down Expand Up @@ -231,5 +258,9 @@ interface Natives {
boolean getSyncV1WasEnabled(long nativeBraveSyncWorker);
boolean getSyncV2MigrateNoticeDismissed(long nativeBraveSyncWorker);
void setSyncV2MigrateNoticeDismissed(long nativeBraveSyncWorker, boolean isDismissed);
void permanentlyDeleteAccount(long nativeBraveSyncWorker, Callback<String> callback);
void clearAccountDeletedNoticePending(long nativeBraveSyncWorker);
boolean isAccountDeletedNoticePending(long nativeBraveSyncWorker);
void setJoinSyncChainCallback(long nativeBraveSyncWorker, Callback<Boolean> callback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.fullscreen.BrowserControlsManager;
import org.chromium.chrome.browser.informers.BraveAndroidSyncDisabledInformer;
import org.chromium.chrome.browser.informers.BraveSyncAccountDeletedInformer;
import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog;
import org.chromium.chrome.browser.notifications.BravePermissionUtils;
import org.chromium.chrome.browser.notifications.permissions.NotificationPermissionController;
Expand Down Expand Up @@ -943,6 +944,7 @@ public void finishNativeInitialization() {
}
BraveSyncInformers.show();
BraveAndroidSyncDisabledInformer.showInformers();
BraveSyncAccountDeletedInformer.show();

if (!OnboardingPrefManager.getInstance().isOneTimeNotificationStarted()
&& PackageUtils.isFirstInstall(this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
@IntDef({BraveInfoBarIdentifier.INVALID, BraveInfoBarIdentifier.BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.WAYBACK_MACHINE_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.SYNC_V2_MIGRATE_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.ANDROID_SYSTEM_SYNC_DISABLED_INFOBAR})
BraveInfoBarIdentifier.ANDROID_SYSTEM_SYNC_DISABLED_INFOBAR,
BraveInfoBarIdentifier.SYNC_CANNOT_RUN_INFOBAR,
BraveInfoBarIdentifier.WEB_DISCOVERY_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR})

@Retention(RetentionPolicy.SOURCE)
public @interface BraveInfoBarIdentifier {
Expand All @@ -24,4 +27,7 @@
int WAYBACK_MACHINE_INFOBAR_DELEGATE = 502;
int SYNC_V2_MIGRATE_INFOBAR_DELEGATE = 503;
int ANDROID_SYSTEM_SYNC_DISABLED_INFOBAR = 504;
int SYNC_CANNOT_RUN_INFOBAR = 505;
int WEB_DISCOVERY_INFOBAR_DELEGATE = 506;
int BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR = 507;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* Copyright (c) 2022 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/. */

package org.chromium.chrome.browser.informers;

import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;

import org.chromium.base.ContextUtils;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveSyncWorker;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.infobar.BraveInfoBarIdentifier;
import org.chromium.chrome.browser.settings.BraveSyncScreensPreference;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.ui.messages.infobar.BraveSimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.ui.messages.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.components.browser_ui.settings.SettingsLauncher;

public class BraveSyncAccountDeletedInformer {
@CalledByNative
public static void show() {
BraveActivity activity = BraveActivity.getBraveActivity();
if (activity == null) return;

Tab tab = activity.getActivityTabProvider().get();
if (tab == null) return;

if (!BraveSyncWorker.get().isAccountDeletedNoticePending()) {
return;
}

BraveSimpleConfirmInfoBarBuilder.createInfobarWithDrawable(tab.getWebContents(),
new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {
// Pressing cross
// In any way don't show the informer again
disableInformer();
}

@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
assert isPrimary : "We don't have secondary button";
// Pressing `OK`
// Don't show the informer again
disableInformer();
return false;
}

@Override
public boolean onInfoBarLinkClicked() {
// Pressing link `re-create the account`
// Don't show the informer again
disableInformer();
SettingsLauncher settingsLauncher = new SettingsLauncherImpl();
settingsLauncher.launchSettingsActivity(
ContextUtils.getApplicationContext(),
BraveSyncScreensPreference.class);
return false;
}
},
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR, activity,
R.drawable.ic_warning_circle,
// See comment at |BraveSyncAccountDeletedInfoBarDelegate::GetMessageText|
// for the informer text and link test placeholder empty substitution
activity.getString(R.string.brave_sync_account_deleted_infobar_message, ""),
activity.getString(R.string.ok), "",
activity.getString(R.string.brave_sync_account_deleted_infobar_link_text, ""),
false);
}

private static void disableInformer() {
BraveSyncWorker.get().clearAccountDeletedNoticePending();
}
}
Loading

0 comments on commit 51a81ba

Please sign in to comment.