Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 switch (tutorial_mode_) { |
| 917 case profiles::TUTORIAL_MODE_NONE: | 917 case profiles::TUTORIAL_MODE_NONE: |
| 918 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | 918 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: |
| 919 case profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING: | |
| 919 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( | 920 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( |
| 920 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, | 921 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, |
| 921 item); | 922 item); |
| 923 if (!tutorial_view) | |
|
Mike Lerman
2015/05/05 01:31:45
I understand what you're doing here, but the contr
anthonyvd
2015/05/05 16:19:17
Very good point, here's a small refactor :) Let me
Mike Lerman
2015/05/05 17:18:09
I love it! Thanks!
| |
| 924 tutorial_view = CreateRightClickTutorialViewIfNeeded(); | |
| 922 break; | 925 break; |
| 923 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | 926 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: |
| 924 tutorial_view = CreateSigninConfirmationView(); | 927 tutorial_view = CreateSigninConfirmationView(); |
| 925 break; | 928 break; |
| 926 case profiles::TUTORIAL_MODE_SHOW_ERROR: | 929 case profiles::TUTORIAL_MODE_SHOW_ERROR: |
| 927 tutorial_view = CreateSigninErrorView(); | 930 tutorial_view = CreateSigninErrorView(); |
| 928 break; | 931 break; |
| 929 } | 932 } |
| 930 } else { | 933 } else { |
| 931 current_profile_accounts = CreateCurrentProfileAccountsView(item); | 934 current_profile_accounts = CreateCurrentProfileAccountsView(item); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 | 999 |
| 997 layout->StartRow(1, 0); | 1000 layout->StartRow(1, 0); |
| 998 layout->AddView(CreateOtherProfilesView(other_profiles)); | 1001 layout->AddView(CreateOtherProfilesView(other_profiles)); |
| 999 } | 1002 } |
| 1000 | 1003 |
| 1001 views::View* ProfileChooserView::CreateProfileChooserView( | 1004 views::View* ProfileChooserView::CreateProfileChooserView( |
| 1002 AvatarMenu* avatar_menu) { | 1005 AvatarMenu* avatar_menu) { |
| 1003 views::View* view = new views::View(); | 1006 views::View* view = new views::View(); |
| 1004 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 1007 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 1005 | 1008 |
| 1006 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) | 1009 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { |
| 1007 PopulateMinimalProfileChooserView(layout, avatar_menu); | 1010 PopulateMinimalProfileChooserView(layout, avatar_menu); |
| 1008 else | 1011 // The user is using right-click switching, no need to tell them about it. |
| 1012 profiles::SetFastUserSwitchingTutorialDismissedState(true); | |
| 1013 } else { | |
| 1009 PopulateCompleteProfileChooserView(layout, avatar_menu); | 1014 PopulateCompleteProfileChooserView(layout, avatar_menu); |
| 1015 } | |
| 1010 | 1016 |
| 1011 return view; | 1017 return view; |
| 1012 } | 1018 } |
| 1013 | 1019 |
| 1014 void ProfileChooserView::DismissTutorial() { | 1020 void ProfileChooserView::DismissTutorial() { |
| 1015 // Never shows the upgrade tutorial again if manually closed. | 1021 // Never shows the upgrade tutorial again if manually closed. |
| 1016 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1022 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1017 browser_->profile()->GetPrefs()->SetInteger( | 1023 browser_->profile()->GetPrefs()->SetInteger( |
| 1018 prefs::kProfileAvatarTutorialShown, | 1024 prefs::kProfileAvatarTutorialShown, |
| 1019 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1025 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
| 1020 } | 1026 } |
| 1021 | 1027 |
| 1028 if (tutorial_mode_ == profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING) { | |
| 1029 profiles::SetFastUserSwitchingTutorialDismissedState(true); | |
| 1030 } | |
| 1031 | |
| 1022 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; | 1032 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; |
| 1023 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); | 1033 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); |
| 1024 } | 1034 } |
| 1025 | 1035 |
| 1026 views::View* ProfileChooserView::CreateTutorialView( | 1036 views::View* ProfileChooserView::CreateTutorialView( |
| 1027 profiles::TutorialMode tutorial_mode, | 1037 profiles::TutorialMode tutorial_mode, |
| 1028 const base::string16& title_text, | 1038 const base::string16& title_text, |
| 1029 const base::string16& content_text, | 1039 const base::string16& content_text, |
| 1030 const base::string16& link_text, | 1040 const base::string16& link_text, |
| 1031 const base::string16& button_text, | 1041 const base::string16& button_text, |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1636 l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE), | 1646 l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE), |
| 1637 last_login_result, | 1647 last_login_result, |
| 1638 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), | 1648 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), |
| 1639 base::string16(), | 1649 base::string16(), |
| 1640 false /* stack_button */, | 1650 false /* stack_button */, |
| 1641 &tutorial_learn_more_link_, | 1651 &tutorial_learn_more_link_, |
| 1642 NULL, | 1652 NULL, |
| 1643 &tutorial_close_button_); | 1653 &tutorial_close_button_); |
| 1644 } | 1654 } |
| 1645 | 1655 |
| 1656 views::View* ProfileChooserView::CreateRightClickTutorialViewIfNeeded() { | |
| 1657 const bool dismissed = profiles::GetFastUserSwitchingTutorialDismissedState(); | |
| 1658 | |
| 1659 // Don't show the tutorial if it's already been dismissed for this profile or | |
| 1660 // if right-clicking wouldn't show any targets. | |
| 1661 if (dismissed || !profiles::HasProfileSwitchTargets(browser_->profile())) | |
| 1662 return nullptr; | |
| 1663 | |
| 1664 return CreateTutorialView( | |
| 1665 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING, | |
| 1666 l10n_util::GetStringUTF16(IDS_PROFILES_RIGHT_CLICK_TUTORIAL_TITLE), | |
| 1667 l10n_util::GetStringUTF16(IDS_PROFILES_RIGHT_CLICK_TUTORIAL_CONTENT_TEXT), | |
| 1668 base::string16(), | |
| 1669 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON), | |
| 1670 false, | |
| 1671 nullptr, | |
| 1672 &tutorial_sync_settings_ok_button_, | |
| 1673 nullptr); | |
| 1674 } | |
| 1675 | |
| 1646 views::View* ProfileChooserView::CreateSwitchUserView() { | 1676 views::View* ProfileChooserView::CreateSwitchUserView() { |
| 1647 views::View* view = new views::View(); | 1677 views::View* view = new views::View(); |
| 1648 views::GridLayout* layout = CreateSingleColumnLayout( | 1678 views::GridLayout* layout = CreateSingleColumnLayout( |
| 1649 view, kFixedSwitchUserViewWidth); | 1679 view, kFixedSwitchUserViewWidth); |
| 1650 views::ColumnSet* columns = layout->AddColumnSet(1); | 1680 views::ColumnSet* columns = layout->AddColumnSet(1); |
| 1651 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 1681 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); |
| 1652 int label_width = | 1682 int label_width = |
| 1653 kFixedSwitchUserViewWidth - 2 * views::kButtonHEdgeMarginNew; | 1683 kFixedSwitchUserViewWidth - 2 * views::kButtonHEdgeMarginNew; |
| 1654 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 1684 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 1655 views::GridLayout::FIXED, label_width, label_width); | 1685 views::GridLayout::FIXED, label_width, label_width); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1704 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1734 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1705 IncognitoModePrefs::DISABLED; | 1735 IncognitoModePrefs::DISABLED; |
| 1706 return incognito_available && !browser_->profile()->IsGuestSession(); | 1736 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1707 } | 1737 } |
| 1708 | 1738 |
| 1709 void ProfileChooserView::PostActionPerformed( | 1739 void ProfileChooserView::PostActionPerformed( |
| 1710 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1740 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1711 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1741 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1712 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1742 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1713 } | 1743 } |
| OLD | NEW |