From baf5b05ee53e96df10bfaac540863c3c8eea0150 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Thu, 25 Aug 2022 19:18:29 +0300 Subject: [PATCH] Don't show account deleted informer for Brave Sync setup page --- browser/brave_browser_main_parts.cc | 4 +-- ...e_sync_account_deleted_infobar_delegate.cc | 25 +++++++++++++------ ...ve_sync_account_deleted_infobar_delegate.h | 8 +++--- browser/sync/brave_sync_alerts_service.cc | 7 ++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/browser/brave_browser_main_parts.cc b/browser/brave_browser_main_parts.cc index 3f866502d27..29077f0bef4 100644 --- a/browser/brave_browser_main_parts.cc +++ b/browser/brave_browser_main_parts.cc @@ -150,8 +150,8 @@ void BraveBrowserMainParts::PostBrowserStart() { SyncCannotRunInfoBarDelegate::Create(infobar_manager, profile, browser); - BraveSyncAccountDeletedInfoBarDelegate::Create(infobar_manager, profile, - browser); + BraveSyncAccountDeletedInfoBarDelegate::Create(active_web_contents, + profile, browser); } } } diff --git a/browser/infobars/brave_sync_account_deleted_infobar_delegate.cc b/browser/infobars/brave_sync_account_deleted_infobar_delegate.cc index 542a0fed827..760b7ff841a 100644 --- a/browser/infobars/brave_sync_account_deleted_infobar_delegate.cc +++ b/browser/infobars/brave_sync_account_deleted_infobar_delegate.cc @@ -6,27 +6,22 @@ #include "brave/browser/infobars/brave_sync_account_deleted_infobar_delegate.h" #include -#include -#include "base/feature_list.h" #include "brave/browser/ui/brave_pages.h" #include "brave/components/brave_sync/brave_sync_prefs.h" -#include "brave/components/constants/pref_names.h" +#include "brave/components/constants/webui_url_constants.h" #include "brave/components/l10n/common/locale_util.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/infobars/confirm_infobar_creator.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/grit/chromium_strings.h" +#include "chrome/browser/ui/chrome_pages.h" #include "components/infobars/content/content_infobar_manager.h" #include "components/infobars/core/infobar.h" -#include "components/prefs/pref_service.h" -#include "components/strings/grit/components_strings.h" #include "ui/views/vector_icons.h" // static void BraveSyncAccountDeletedInfoBarDelegate::Create( - infobars::ContentInfoBarManager* infobar_manager, + content::WebContents* active_web_contents, Profile* profile, Browser* browser) { brave_sync::Prefs brave_sync_prefs(profile->GetPrefs()); @@ -36,6 +31,20 @@ void BraveSyncAccountDeletedInfoBarDelegate::Create( return; } + // If we already are on brave://settings/braveSync/setup page, don't show + // informer + if (!active_web_contents || active_web_contents->GetURL() == + chrome::GetSettingsUrl(kBraveSyncSetupPath)) { + return; + } + + infobars::ContentInfoBarManager* infobar_manager = + infobars::ContentInfoBarManager::FromWebContents(active_web_contents); + + if (!infobar_manager) { + return; + } + // Show infobar infobar_manager->AddInfoBar( CreateConfirmInfoBar(std::unique_ptr( diff --git a/browser/infobars/brave_sync_account_deleted_infobar_delegate.h b/browser/infobars/brave_sync_account_deleted_infobar_delegate.h index ea01e6b07c3..b48dcd34fe7 100644 --- a/browser/infobars/brave_sync_account_deleted_infobar_delegate.h +++ b/browser/infobars/brave_sync_account_deleted_infobar_delegate.h @@ -13,9 +13,9 @@ class Browser; class Profile; -namespace infobars { -class ContentInfoBarManager; -} // namespace infobars +namespace content { +class WebContents; +} // An infobar that is run with a string, buttons, and a "Learn More" link. class BraveSyncAccountDeletedInfoBarDelegate : public ConfirmInfoBarDelegate { @@ -25,7 +25,7 @@ class BraveSyncAccountDeletedInfoBarDelegate : public ConfirmInfoBarDelegate { BraveSyncAccountDeletedInfoBarDelegate& operator=( const BraveSyncAccountDeletedInfoBarDelegate&) = delete; - static void Create(infobars::ContentInfoBarManager* infobar_manager, + static void Create(content::WebContents* active_web_contents, Profile* profile, Browser* browser); diff --git a/browser/sync/brave_sync_alerts_service.cc b/browser/sync/brave_sync_alerts_service.cc index 527ccb94f04..53445081071 100644 --- a/browser/sync/brave_sync_alerts_service.cc +++ b/browser/sync/brave_sync_alerts_service.cc @@ -63,11 +63,8 @@ void BraveSyncAlertsService::ShowInfobar() { content::WebContents* active_web_contents = browser->tab_strip_model()->GetActiveWebContents(); if (active_web_contents) { - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(active_web_contents); - - BraveSyncAccountDeletedInfoBarDelegate::Create(infobar_manager, profile_, - browser); + BraveSyncAccountDeletedInfoBarDelegate::Create(active_web_contents, + profile_, browser); } } #endif