Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 1120013003: Add right-click user switching tutorial bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 profiles::TutorialMode tutorial_mode, 484 profiles::TutorialMode tutorial_mode,
485 const signin::ManageAccountsParams& manage_accounts_params, 485 const signin::ManageAccountsParams& manage_accounts_params,
486 views::View* anchor_view, 486 views::View* anchor_view,
487 views::BubbleBorder::Arrow arrow, 487 views::BubbleBorder::Arrow arrow,
488 views::BubbleBorder::BubbleAlignment border_alignment, 488 views::BubbleBorder::BubbleAlignment border_alignment,
489 Browser* browser) { 489 Browser* browser) {
490 // Don't start creating the view if it would be an empty fast user switcher. 490 // Don't start creating the view if it would be an empty fast user switcher.
491 // It has to happen here to prevent the view system from creating an empty 491 // It has to happen here to prevent the view system from creating an empty
492 // container. 492 // container.
493 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && 493 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER &&
494 profiles::HasProfileSwitchTargets(browser->profile())) { 494 !profiles::HasProfileSwitchTargets(browser->profile())) {
495 return; 495 return;
496 } 496 }
497 497
498 if (IsShowing()) { 498 if (IsShowing()) {
499 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { 499 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) {
500 profile_bubble_->tutorial_mode_ = tutorial_mode; 500 profile_bubble_->tutorial_mode_ = tutorial_mode;
501 profile_bubble_->ShowView(view_mode, profile_bubble_->avatar_menu_.get()); 501 profile_bubble_->ShowView(view_mode, profile_bubble_->avatar_menu_.get());
502 } 502 }
503 return; 503 return;
504 } 504 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 views::View* current_profile_view = NULL; 906 views::View* current_profile_view = NULL;
907 views::View* current_profile_accounts = NULL; 907 views::View* current_profile_accounts = NULL;
908 views::View* option_buttons_view = NULL; 908 views::View* option_buttons_view = NULL;
909 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 909 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
910 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 910 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
911 if (item.active) { 911 if (item.active) {
912 option_buttons_view = CreateOptionsView( 912 option_buttons_view = CreateOptionsView(
913 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 913 item.signed_in && profiles::IsLockAvailable(browser_->profile()));
914 current_profile_view = CreateCurrentProfileView(item, false); 914 current_profile_view = CreateCurrentProfileView(item, false);
915 if (IsProfileChooser(view_mode_)) { 915 if (IsProfileChooser(view_mode_)) {
916 switch (tutorial_mode_) { 916 tutorial_view = CreateTutorialViewIfNeeded(item);
917 case profiles::TUTORIAL_MODE_NONE:
918 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE:
919 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded(
920 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE,
921 item);
922 break;
923 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN:
924 tutorial_view = CreateSigninConfirmationView();
925 break;
926 case profiles::TUTORIAL_MODE_SHOW_ERROR:
927 tutorial_view = CreateSigninErrorView();
928 break;
929 }
930 } else { 917 } else {
931 current_profile_accounts = CreateCurrentProfileAccountsView(item); 918 current_profile_accounts = CreateCurrentProfileAccountsView(item);
932 } 919 }
933 } else { 920 } else {
934 other_profiles.push_back(i); 921 other_profiles.push_back(i);
935 } 922 }
936 } 923 }
937 924
938 if (tutorial_view) { 925 if (tutorial_view) {
939 // TODO(mlerman): update UMA stats for the new tutorial. 926 // TODO(mlerman): update UMA stats for the new tutorial.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 983
997 layout->StartRow(1, 0); 984 layout->StartRow(1, 0);
998 layout->AddView(CreateOtherProfilesView(other_profiles)); 985 layout->AddView(CreateOtherProfilesView(other_profiles));
999 } 986 }
1000 987
1001 views::View* ProfileChooserView::CreateProfileChooserView( 988 views::View* ProfileChooserView::CreateProfileChooserView(
1002 AvatarMenu* avatar_menu) { 989 AvatarMenu* avatar_menu) {
1003 views::View* view = new views::View(); 990 views::View* view = new views::View();
1004 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 991 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1005 992
1006 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) 993 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
1007 PopulateMinimalProfileChooserView(layout, avatar_menu); 994 PopulateMinimalProfileChooserView(layout, avatar_menu);
1008 else 995 // The user is using right-click switching, no need to tell them about it.
996 PrefService* local_state = g_browser_process->local_state();
997 local_state->SetBoolean(
998 prefs::kProfileAvatarRightClickTutorialDismissed, true);
999 } else {
1009 PopulateCompleteProfileChooserView(layout, avatar_menu); 1000 PopulateCompleteProfileChooserView(layout, avatar_menu);
1001 }
1010 1002
1011 return view; 1003 return view;
1012 } 1004 }
1013 1005
1014 void ProfileChooserView::DismissTutorial() { 1006 void ProfileChooserView::DismissTutorial() {
1015 // Never shows the upgrade tutorial again if manually closed. 1007 // Never shows the upgrade tutorial again if manually closed.
1016 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { 1008 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) {
1017 browser_->profile()->GetPrefs()->SetInteger( 1009 browser_->profile()->GetPrefs()->SetInteger(
1018 prefs::kProfileAvatarTutorialShown, 1010 prefs::kProfileAvatarTutorialShown,
1019 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); 1011 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1);
1020 } 1012 }
1021 1013
1014 if (tutorial_mode_ == profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING) {
1015 PrefService* local_state = g_browser_process->local_state();
1016 local_state->SetBoolean(
1017 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1018 }
1019
1022 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 1020 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
1023 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 1021 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
1024 } 1022 }
1025 1023
1024 views::View* ProfileChooserView::CreateTutorialViewIfNeeded(
1025 const AvatarMenu::Item& item) {
1026 if (tutorial_mode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN)
1027 return CreateSigninConfirmationView();
1028
1029 if (tutorial_mode_ == profiles::TUTORIAL_MODE_SHOW_ERROR)
1030 return CreateSigninErrorView();
1031
1032 if (ShouldShowWelcomeUpgradeTutorial()) {
1033 if (tutorial_mode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) {
1034 Profile* profile = browser_->profile();
1035 const int show_count = profile->GetPrefs()->GetInteger(
1036 prefs::kProfileAvatarTutorialShown);
1037 profile->GetPrefs()->SetInteger(
1038 prefs::kProfileAvatarTutorialShown, show_count + 1);
1039 }
1040
1041 return CreateWelcomeUpgradeTutorialView(item);
1042 }
1043
1044 if (ShouldShowRightClickTutorialView())
1045 return CreateRightClickTutorialView();
1046
1047 return nullptr;
1048 }
1049
1026 views::View* ProfileChooserView::CreateTutorialView( 1050 views::View* ProfileChooserView::CreateTutorialView(
1027 profiles::TutorialMode tutorial_mode, 1051 profiles::TutorialMode tutorial_mode,
1028 const base::string16& title_text, 1052 const base::string16& title_text,
1029 const base::string16& content_text, 1053 const base::string16& content_text,
1030 const base::string16& link_text, 1054 const base::string16& link_text,
1031 const base::string16& button_text, 1055 const base::string16& button_text,
1032 bool stack_button, 1056 bool stack_button,
1033 views::Link** link, 1057 views::Link** link,
1034 views::LabelButton** button, 1058 views::LabelButton** button,
1035 views::ImageButton** close_button) { 1059 views::ImageButton** close_button) {
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 1589 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
1566 } 1590 }
1567 1591
1568 TitleCard* title_card = new TitleCard( 1592 TitleCard* title_card = new TitleCard(
1569 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE), 1593 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE),
1570 this, &account_removal_cancel_button_); 1594 this, &account_removal_cancel_button_);
1571 return TitleCard::AddPaddedTitleCard(view, title_card, 1595 return TitleCard::AddPaddedTitleCard(view, title_card,
1572 kFixedAccountRemovalViewWidth); 1596 kFixedAccountRemovalViewWidth);
1573 } 1597 }
1574 1598
1575 views::View* ProfileChooserView::CreateWelcomeUpgradeTutorialViewIfNeeded( 1599 bool ProfileChooserView::ShouldShowWelcomeUpgradeTutorial() {
Mike Lerman 2015/05/14 20:29:43 You can remove these method definitions from the h
anthonyvd 2015/05/15 13:26:56 Done.
1576 bool tutorial_shown, const AvatarMenu::Item& avatar_item) {
1577 Profile* profile = browser_->profile(); 1600 Profile* profile = browser_->profile();
1578 1601
1579 const int show_count = profile->GetPrefs()->GetInteger( 1602 const int show_count = profile->GetPrefs()->GetInteger(
1580 prefs::kProfileAvatarTutorialShown); 1603 prefs::kProfileAvatarTutorialShown);
1581 // Do not show the tutorial if user has dismissed it. 1604 // Do not show the tutorial if user has dismissed it.
1582 if (show_count > signin_ui_util::kUpgradeWelcomeTutorialShowMax) 1605 if (show_count > signin_ui_util::kUpgradeWelcomeTutorialShowMax)
1583 return NULL; 1606 return false;
1584 1607
1585 if (!tutorial_shown) { 1608 return tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE ||
1586 if (show_count == signin_ui_util::kUpgradeWelcomeTutorialShowMax) 1609 show_count != signin_ui_util::kUpgradeWelcomeTutorialShowMax;
1587 return NULL; 1610 }
1588 profile->GetPrefs()->SetInteger( 1611
1589 prefs::kProfileAvatarTutorialShown, show_count + 1); 1612 bool ProfileChooserView::ShouldShowRightClickTutorialView() {
1590 } 1613 PrefService* local_state = g_browser_process->local_state();
1614 const bool dismissed = local_state->GetBoolean(
1615 prefs::kProfileAvatarRightClickTutorialDismissed);
1616
1617 // Don't show the tutorial if it's already been dismissed or if right-clicking
1618 // wouldn't show any targets.
1619 return !dismissed && profiles::HasProfileSwitchTargets(browser_->profile());
1620 }
1621
1622 views::View* ProfileChooserView::CreateWelcomeUpgradeTutorialView(
1623 const AvatarMenu::Item& avatar_item) {
1591 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 1624 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
1592 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); 1625 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW);
1593 1626
1594 // For local profiles, the "Not you" link doesn't make sense. 1627 // For local profiles, the "Not you" link doesn't make sense.
1595 base::string16 link_message = avatar_item.signed_in ? 1628 base::string16 link_message = avatar_item.signed_in ?
1596 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatar_item.name) : 1629 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatar_item.name) :
1597 base::string16(); 1630 base::string16();
1598 1631
1599 return CreateTutorialView( 1632 return CreateTutorialView(
1600 profiles::TUTORIAL_MODE_WELCOME_UPGRADE, 1633 profiles::TUTORIAL_MODE_WELCOME_UPGRADE,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE), 1669 l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE),
1637 last_login_result, 1670 last_login_result,
1638 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), 1671 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE),
1639 base::string16(), 1672 base::string16(),
1640 false /* stack_button */, 1673 false /* stack_button */,
1641 &tutorial_learn_more_link_, 1674 &tutorial_learn_more_link_,
1642 NULL, 1675 NULL,
1643 &tutorial_close_button_); 1676 &tutorial_close_button_);
1644 } 1677 }
1645 1678
1679 views::View* ProfileChooserView::CreateRightClickTutorialView() {
1680 return CreateTutorialView(
1681 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING,
1682 l10n_util::GetStringUTF16(IDS_PROFILES_RIGHT_CLICK_TUTORIAL_TITLE),
1683 l10n_util::GetStringUTF16(IDS_PROFILES_RIGHT_CLICK_TUTORIAL_CONTENT_TEXT),
1684 base::string16(),
1685 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON),
1686 false,
1687 nullptr,
1688 &tutorial_sync_settings_ok_button_,
1689 nullptr);
1690 }
1691
1646 views::View* ProfileChooserView::CreateSwitchUserView() { 1692 views::View* ProfileChooserView::CreateSwitchUserView() {
1647 views::View* view = new views::View(); 1693 views::View* view = new views::View();
1648 views::GridLayout* layout = CreateSingleColumnLayout( 1694 views::GridLayout* layout = CreateSingleColumnLayout(
1649 view, kFixedSwitchUserViewWidth); 1695 view, kFixedSwitchUserViewWidth);
1650 views::ColumnSet* columns = layout->AddColumnSet(1); 1696 views::ColumnSet* columns = layout->AddColumnSet(1);
1651 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 1697 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
1652 int label_width = 1698 int label_width =
1653 kFixedSwitchUserViewWidth - 2 * views::kButtonHEdgeMarginNew; 1699 kFixedSwitchUserViewWidth - 2 * views::kButtonHEdgeMarginNew;
1654 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 1700 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
1655 views::GridLayout::FIXED, label_width, label_width); 1701 views::GridLayout::FIXED, label_width, label_width);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1750 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1705 IncognitoModePrefs::DISABLED; 1751 IncognitoModePrefs::DISABLED;
1706 return incognito_available && !browser_->profile()->IsGuestSession(); 1752 return incognito_available && !browser_->profile()->IsGuestSession();
1707 } 1753 }
1708 1754
1709 void ProfileChooserView::PostActionPerformed( 1755 void ProfileChooserView::PostActionPerformed(
1710 ProfileMetrics::ProfileDesktopMenu action_performed) { 1756 ProfileMetrics::ProfileDesktopMenu action_performed) {
1711 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1757 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1712 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1758 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1713 } 1759 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698