| 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" |
| 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/profiles/profile_metrics.h" | 15 #include "chrome/browser/profiles/profile_metrics.h" |
| 15 #include "chrome/browser/profiles/profile_window.h" | 16 #include "chrome/browser/profiles/profile_window.h" |
| 16 #include "chrome/browser/profiles/profiles_state.h" | 17 #include "chrome/browser/profiles/profiles_state.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_header_helper.h" | 19 #include "chrome/browser/signin/signin_header_helper.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/signin/signin_promo.h" | 21 #include "chrome/browser/signin/signin_promo.h" |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 // has no parent (like in tests) because that will also crash. | 655 // has no parent (like in tests) because that will also crash. |
| 655 if (sender->parent()) | 656 if (sender->parent()) |
| 656 sender->SetEnabled(false); | 657 sender->SetEnabled(false); |
| 657 | 658 |
| 658 if (sender == users_button_) { | 659 if (sender == users_button_) { |
| 659 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 660 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
| 660 // If this is a guest session, also close all the guest browser windows. | 661 // If this is a guest session, also close all the guest browser windows. |
| 661 if (browser_->profile()->IsGuestSession()) | 662 if (browser_->profile()->IsGuestSession()) |
| 662 profiles::CloseGuestProfileWindows(); | 663 profiles::CloseGuestProfileWindows(); |
| 663 } else if (sender == go_incognito_button_) { | 664 } else if (sender == go_incognito_button_) { |
| 664 DCHECK(!browser_->profile()->IsGuestSession()); | 665 DCHECK(ShouldShowGoIncognito()); |
| 665 chrome::NewIncognitoWindow(browser_); | 666 chrome::NewIncognitoWindow(browser_); |
| 666 } else if (sender == lock_button_) { | 667 } else if (sender == lock_button_) { |
| 667 profiles::LockProfile(browser_->profile()); | 668 profiles::LockProfile(browser_->profile()); |
| 668 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK); | 669 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK); |
| 669 } else if (sender == auth_error_email_button_) { | 670 } else if (sender == auth_error_email_button_) { |
| 670 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); | 671 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); |
| 671 } else if (sender == tutorial_ok_button_) { | 672 } else if (sender == tutorial_ok_button_) { |
| 672 // If the user manually dismissed the tutorial, never show it again by | 673 // If the user manually dismissed the tutorial, never show it again by |
| 673 // setting the number of times shown to the maximum plus 1, so that later we | 674 // setting the number of times shown to the maximum plus 1, so that later we |
| 674 // could distinguish between the dismiss case and the case when the tutorial | 675 // could distinguish between the dismiss case and the case when the tutorial |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 return true; | 819 return true; |
| 819 | 820 |
| 820 profiles::UpdateProfileName(profile, new_profile_name); | 821 profiles::UpdateProfileName(profile, new_profile_name); |
| 821 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); | 822 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); |
| 822 current_profile_name_->ShowReadOnlyView(); | 823 current_profile_name_->ShowReadOnlyView(); |
| 823 return true; | 824 return true; |
| 824 } | 825 } |
| 825 return false; | 826 return false; |
| 826 } | 827 } |
| 827 | 828 |
| 828 void ProfileChooserView::PostActionPerformed( | |
| 829 ProfileMetrics::ProfileDesktopMenu action_performed) { | |
| 830 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | |
| 831 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | |
| 832 } | |
| 833 | |
| 834 views::View* ProfileChooserView::CreateProfileChooserView( | 829 views::View* ProfileChooserView::CreateProfileChooserView( |
| 835 AvatarMenu* avatar_menu, | 830 AvatarMenu* avatar_menu, |
| 836 profiles::TutorialMode last_tutorial_mode) { | 831 profiles::TutorialMode last_tutorial_mode) { |
| 837 // TODO(guohui, noms): the view should be customized based on whether new | 832 // TODO(guohui, noms): the view should be customized based on whether new |
| 838 // profile management preview is enabled or not. | 833 // profile management preview is enabled or not. |
| 839 | 834 |
| 840 views::View* view = new views::View(); | 835 views::View* view = new views::View(); |
| 841 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 836 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 842 // Separate items into active and alternatives. | 837 // Separate items into active and alternatives. |
| 843 Indexes other_profiles; | 838 Indexes other_profiles; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : | 1230 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : |
| 1236 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); | 1231 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); |
| 1237 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1232 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 1238 users_button_ = new BackgroundColorHoverButton( | 1233 users_button_ = new BackgroundColorHoverButton( |
| 1239 this, | 1234 this, |
| 1240 text, | 1235 text, |
| 1241 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); | 1236 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); |
| 1242 layout->StartRow(1, 0); | 1237 layout->StartRow(1, 0); |
| 1243 layout->AddView(users_button_); | 1238 layout->AddView(users_button_); |
| 1244 | 1239 |
| 1245 if (!browser_->profile()->IsGuestSession()) { | 1240 if (ShouldShowGoIncognito()) { |
| 1246 layout->StartRow(1, 0); | 1241 layout->StartRow(1, 0); |
| 1247 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1242 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1248 | 1243 |
| 1249 // TODO(noms): Use the correct incognito icon when it's available. | 1244 // TODO(noms): Use the correct incognito icon when it's available. |
| 1250 go_incognito_button_ = new BackgroundColorHoverButton( | 1245 go_incognito_button_ = new BackgroundColorHoverButton( |
| 1251 this, | 1246 this, |
| 1252 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON), | 1247 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON), |
| 1253 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); | 1248 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); |
| 1254 layout->StartRow(1, 0); | 1249 layout->StartRow(1, 0); |
| 1255 layout->AddView(go_incognito_button_); | 1250 layout->AddView(go_incognito_button_); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 gfx::ALIGN_CENTER); | 1521 gfx::ALIGN_CENTER); |
| 1527 layout->StartRowWithPadding( | 1522 layout->StartRowWithPadding( |
| 1528 1, 0, 0, views::kUnrelatedControlVerticalSpacing); | 1523 1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
| 1529 layout->AddView(end_preview_and_relaunch_button_); | 1524 layout->AddView(end_preview_and_relaunch_button_); |
| 1530 | 1525 |
| 1531 TitleCard* title_card = new TitleCard( | 1526 TitleCard* title_card = new TitleCard( |
| 1532 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); | 1527 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); |
| 1533 return TitleCard::AddPaddedTitleCard( | 1528 return TitleCard::AddPaddedTitleCard( |
| 1534 view, title_card, kFixedAccountRemovalViewWidth); | 1529 view, title_card, kFixedAccountRemovalViewWidth); |
| 1535 } | 1530 } |
| 1531 |
| 1532 bool ProfileChooserView::ShouldShowGoIncognito() const { |
| 1533 bool incognito_available = |
| 1534 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1535 IncognitoModePrefs::DISABLED; |
| 1536 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1537 } |
| 1538 |
| 1539 void ProfileChooserView::PostActionPerformed( |
| 1540 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1541 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1542 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1543 } |
| OLD | NEW |