Commit 426279be authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Add sync promos

Sync promos are added to the identity box of the
profile menu.

Screenshots:
https://drive.google.com/file/d/16Hrj0jMyRW9V0Lujnht__dq9FwDbDqgZ/view?usp=sharing
https://drive.google.com/file/d/11pITu_EY6jwocAbDwpE14dRQEbWXsMev/view?usp=sharing

Flag: profile-menu-revamp

Bug: 995720
Change-Id: I54848b8688cb9e7417a8b9274f85b6093148e568
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807502
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697537}
parent 6489b7e5
...@@ -169,6 +169,7 @@ void ProfileMenuView::BuildMenu() { ...@@ -169,6 +169,7 @@ void ProfileMenuView::BuildMenu() {
return; return;
} }
BuildIdentity(); BuildIdentity();
BuildSyncInfo();
BuildAutofillButtons(); BuildAutofillButtons();
BuildAccountFeatureButtons(); BuildAccountFeatureButtons();
BuildSelectableProfiles(); BuildSelectableProfiles();
...@@ -422,6 +423,36 @@ void ProfileMenuView::BuildAutofillButtons() { ...@@ -422,6 +423,36 @@ void ProfileMenuView::BuildAutofillButtons() {
base::Unretained(this))); base::Unretained(this)));
} }
void ProfileMenuView::BuildSyncInfo() {
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(browser()->profile());
if (identity_manager->HasPrimaryAccount()) {
// TODO(crbug.com/995720): Implement sync-is-on state.
return;
}
// Show sync promos.
CoreAccountInfo unconsented_account =
identity_manager->GetUnconsentedPrimaryAccountInfo();
base::Optional<AccountInfo> account_info =
identity_manager->FindExtendedAccountInfoForAccountWithRefreshToken(
unconsented_account);
if (account_info.has_value()) {
SetSyncInfo(
/*description=*/base::string16(),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON),
base::BindRepeating(&ProfileMenuView::OnSigninAccountButtonClicked,
base::Unretained(this), account_info.value()));
} else {
SetSyncInfo(l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SYNC_PROMO),
l10n_util::GetStringUTF16(IDS_PROFILES_DICE_SIGNIN_BUTTON),
base::BindRepeating(&ProfileMenuView::OnSigninButtonClicked,
base::Unretained(this)));
}
}
void ProfileMenuView::BuildAccountFeatureButtons() { void ProfileMenuView::BuildAccountFeatureButtons() {
signin::IdentityManager* identity_manager = signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(browser()->profile()); IdentityManagerFactory::GetForProfile(browser()->profile());
......
...@@ -100,6 +100,7 @@ class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver { ...@@ -100,6 +100,7 @@ class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver {
// Helper methods for building the menu. // Helper methods for building the menu.
void BuildIdentity(); void BuildIdentity();
void BuildAutofillButtons(); void BuildAutofillButtons();
void BuildSyncInfo();
void BuildAccountFeatureButtons(); void BuildAccountFeatureButtons();
void BuildSelectableProfiles(); void BuildSelectableProfiles();
void BuildProfileFeatureButtons(); void BuildProfileFeatureButtons();
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h" #include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h" #include "ui/views/controls/separator.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
...@@ -228,6 +229,40 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::Image& image, ...@@ -228,6 +229,40 @@ void ProfileMenuViewBase::SetIdentityInfo(const gfx::Image& image,
} }
} }
void ProfileMenuViewBase::SetSyncInfo(const base::string16& description,
const base::string16& link_text,
base::RepeatingClosure action) {
constexpr int kVerticalPadding = 8;
sync_info_container_->RemoveAllChildViews(/*delete_children=*/true);
sync_info_container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
views::View* separator =
sync_info_container_->AddChildView(std::make_unique<views::Separator>());
separator->SetBorder(
views::CreateEmptyBorder(0, 0, /*bottom=*/kVerticalPadding, 0));
if (!description.empty()) {
views::Label* label = sync_info_container_->AddChildView(
std::make_unique<views::Label>(description));
label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
label->SetHandlesTooltips(false);
label->SetBorder(views::CreateEmptyBorder(gfx::Insets(0, kMenuEdgeMargin)));
}
views::Link* link = sync_info_container_->AddChildView(
std::make_unique<views::Link>(link_text));
link->SetHorizontalAlignment(gfx::ALIGN_CENTER);
link->set_listener(this);
link->SetBorder(views::CreateEmptyBorder(/*top=*/0, /*left=*/kMenuEdgeMargin,
/*bottom=*/kVerticalPadding,
/*right=*/kMenuEdgeMargin));
RegisterClickAction(link, std::move(action));
}
void ProfileMenuViewBase::AddShortcutFeatureButton( void ProfileMenuViewBase::AddShortcutFeatureButton(
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
const base::string16& text, const base::string16& text,
...@@ -395,6 +430,10 @@ void ProfileMenuViewBase::ButtonPressed(views::Button* button, ...@@ -395,6 +430,10 @@ void ProfileMenuViewBase::ButtonPressed(views::Button* button,
OnClick(button); OnClick(button);
} }
void ProfileMenuViewBase::LinkClicked(views::Link* link, int event_flags) {
OnClick(link);
}
void ProfileMenuViewBase::StyledLabelLinkClicked(views::StyledLabel* link, void ProfileMenuViewBase::StyledLabelLinkClicked(views::StyledLabel* link,
const gfx::Range& range, const gfx::Range& range,
int event_flags) { int event_flags) {
...@@ -441,6 +480,8 @@ void ProfileMenuViewBase::Reset() { ...@@ -441,6 +480,8 @@ void ProfileMenuViewBase::Reset() {
bordered_box_container->AddChildView(std::make_unique<views::View>()); bordered_box_container->AddChildView(std::make_unique<views::View>());
shortcut_features_container_ = shortcut_features_container_ =
bordered_box_container->AddChildView(std::make_unique<views::View>()); bordered_box_container->AddChildView(std::make_unique<views::View>());
sync_info_container_ =
bordered_box_container->AddChildView(std::make_unique<views::View>());
account_features_container_ = account_features_container_ =
bordered_box_container->AddChildView(std::make_unique<views::View>()); bordered_box_container->AddChildView(std::make_unique<views::View>());
components->AddChildView( components->AddChildView(
......
...@@ -39,7 +39,8 @@ class DiceSigninButtonView; ...@@ -39,7 +39,8 @@ class DiceSigninButtonView;
class ProfileMenuViewBase : public content::WebContentsDelegate, class ProfileMenuViewBase : public content::WebContentsDelegate,
public views::BubbleDialogDelegateView, public views::BubbleDialogDelegateView,
public views::ButtonListener, public views::ButtonListener,
public views::StyledLabelListener { public views::StyledLabelListener,
public views::LinkListener {
public: public:
// MenuItems struct keeps the menu items and meta data for a group of items in // MenuItems struct keeps the menu items and meta data for a group of items in
// a menu. It takes the ownership of views and passes it to the menu when menu // a menu. It takes the ownership of views and passes it to the menu when menu
...@@ -97,6 +98,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -97,6 +98,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
void SetIdentityInfo(const gfx::Image& image, void SetIdentityInfo(const gfx::Image& image,
const base::string16& title, const base::string16& title,
const base::string16& subtitle); const base::string16& subtitle);
void SetSyncInfo(const base::string16& description,
const base::string16& link_text,
base::RepeatingClosure action);
void AddShortcutFeatureButton(const gfx::VectorIcon& icon, void AddShortcutFeatureButton(const gfx::VectorIcon& icon,
const base::string16& text, const base::string16& text,
base::RepeatingClosure action); base::RepeatingClosure action);
...@@ -184,6 +188,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -184,6 +188,9 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* button, const ui::Event& event) final; void ButtonPressed(views::Button* button, const ui::Event& event) final;
// views::LinkListener:
void LinkClicked(views::Link* link, int event_flags) final;
// views::StyledLabelListener: // views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* link, void StyledLabelLinkClicked(views::StyledLabel* link,
const gfx::Range& range, const gfx::Range& range,
...@@ -213,6 +220,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -213,6 +220,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// Component containers. // Component containers.
views::View* identity_info_container_ = nullptr; views::View* identity_info_container_ = nullptr;
views::View* sync_info_container_ = nullptr;
views::View* shortcut_features_container_ = nullptr; views::View* shortcut_features_container_ = nullptr;
views::View* account_features_container_ = nullptr; views::View* account_features_container_ = nullptr;
views::View* selectable_profiles_container_ = nullptr; views::View* selectable_profiles_container_ = nullptr;
......
...@@ -669,10 +669,11 @@ class ProfileMenuClickTest_MultipleProfiles : public ProfileMenuClickTest { ...@@ -669,10 +669,11 @@ class ProfileMenuClickTest_MultipleProfiles : public ProfileMenuClickTest {
public: public:
// List of actionable items in the correct order as they appear in the menu. // List of actionable items in the correct order as they appear in the menu.
// If a new button is added to the menu, it should also be added to this list. // If a new button is added to the menu, it should also be added to this list.
static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[9] = static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[10] =
{ProfileMenuView::ActionableItem::kPasswordsButton, {ProfileMenuView::ActionableItem::kPasswordsButton,
ProfileMenuView::ActionableItem::kCreditCardsButton, ProfileMenuView::ActionableItem::kCreditCardsButton,
ProfileMenuView::ActionableItem::kAddressesButton, ProfileMenuView::ActionableItem::kAddressesButton,
ProfileMenuView::ActionableItem::kSigninButton,
ProfileMenuView::ActionableItem::kOtherProfileButton, ProfileMenuView::ActionableItem::kOtherProfileButton,
ProfileMenuView::ActionableItem::kOtherProfileButton, ProfileMenuView::ActionableItem::kOtherProfileButton,
ProfileMenuView::ActionableItem::kGuestProfileButton, ProfileMenuView::ActionableItem::kGuestProfileButton,
...@@ -764,10 +765,11 @@ class ProfileMenuClickTest_WithUnconsentedPrimaryAccount ...@@ -764,10 +765,11 @@ class ProfileMenuClickTest_WithUnconsentedPrimaryAccount
public: public:
// List of actionable items in the correct order as they appear in the menu. // List of actionable items in the correct order as they appear in the menu.
// If a new button is added to the menu, it should also be added to this list. // If a new button is added to the menu, it should also be added to this list.
static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[9] = static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[10] =
{ProfileMenuView::ActionableItem::kPasswordsButton, {ProfileMenuView::ActionableItem::kPasswordsButton,
ProfileMenuView::ActionableItem::kCreditCardsButton, ProfileMenuView::ActionableItem::kCreditCardsButton,
ProfileMenuView::ActionableItem::kAddressesButton, ProfileMenuView::ActionableItem::kAddressesButton,
ProfileMenuView::ActionableItem::kSigninAccountButton,
ProfileMenuView::ActionableItem::kManageGoogleAccountButton, ProfileMenuView::ActionableItem::kManageGoogleAccountButton,
ProfileMenuView::ActionableItem::kSignoutButton, ProfileMenuView::ActionableItem::kSignoutButton,
ProfileMenuView::ActionableItem::kGuestProfileButton, ProfileMenuView::ActionableItem::kGuestProfileButton,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment