| 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/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/profiles/profile_metrics.h" | 14 #include "chrome/browser/profiles/profile_metrics.h" |
| 15 #include "chrome/browser/profiles/profile_window.h" | 15 #include "chrome/browser/profiles/profile_window.h" |
| 16 #include "chrome/browser/profiles/profiles_state.h" | 16 #include "chrome/browser/profiles/profiles_state.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_header_helper.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/signin/signin_promo.h" | 20 #include "chrome/browser/signin/signin_promo.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 22 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
| 23 #include "chrome/browser/ui/chrome_pages.h" | 24 #include "chrome/browser/ui/chrome_pages.h" |
| 24 #include "chrome/browser/ui/singleton_tabs.h" | 25 #include "chrome/browser/ui/singleton_tabs.h" |
| 25 #include "chrome/browser/ui/views/profiles/user_manager_view.h" | 26 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 426 |
| 426 // ProfileChooserView --------------------------------------------------------- | 427 // ProfileChooserView --------------------------------------------------------- |
| 427 | 428 |
| 428 // static | 429 // static |
| 429 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; | 430 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; |
| 430 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; | 431 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; |
| 431 | 432 |
| 432 // static | 433 // static |
| 433 void ProfileChooserView::ShowBubble( | 434 void ProfileChooserView::ShowBubble( |
| 434 profiles::BubbleViewMode view_mode, | 435 profiles::BubbleViewMode view_mode, |
| 436 signin::GAIAServiceType service_type, |
| 435 views::View* anchor_view, | 437 views::View* anchor_view, |
| 436 views::BubbleBorder::Arrow arrow, | 438 views::BubbleBorder::Arrow arrow, |
| 437 views::BubbleBorder::BubbleAlignment border_alignment, | 439 views::BubbleBorder::BubbleAlignment border_alignment, |
| 438 const gfx::Rect& anchor_rect, | 440 const gfx::Rect& anchor_rect, |
| 439 Browser* browser) { | 441 Browser* browser) { |
| 440 if (IsShowing()) | 442 if (IsShowing()) |
| 441 return; | 443 return; |
| 442 | 444 |
| 443 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, anchor_rect, | 445 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, anchor_rect, |
| 444 browser, view_mode); | 446 browser, view_mode, service_type); |
| 445 views::BubbleDelegateView::CreateBubble(profile_bubble_); | 447 views::BubbleDelegateView::CreateBubble(profile_bubble_); |
| 446 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); | 448 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); |
| 447 profile_bubble_->SetAlignment(border_alignment); | 449 profile_bubble_->SetAlignment(border_alignment); |
| 448 profile_bubble_->GetWidget()->Show(); | 450 profile_bubble_->GetWidget()->Show(); |
| 449 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 451 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 450 } | 452 } |
| 451 | 453 |
| 452 // static | 454 // static |
| 453 bool ProfileChooserView::IsShowing() { | 455 bool ProfileChooserView::IsShowing() { |
| 454 return profile_bubble_ != NULL; | 456 return profile_bubble_ != NULL; |
| 455 } | 457 } |
| 456 | 458 |
| 457 // static | 459 // static |
| 458 void ProfileChooserView::Hide() { | 460 void ProfileChooserView::Hide() { |
| 459 if (IsShowing()) | 461 if (IsShowing()) |
| 460 profile_bubble_->GetWidget()->Close(); | 462 profile_bubble_->GetWidget()->Close(); |
| 461 } | 463 } |
| 462 | 464 |
| 463 ProfileChooserView::ProfileChooserView(views::View* anchor_view, | 465 ProfileChooserView::ProfileChooserView(views::View* anchor_view, |
| 464 views::BubbleBorder::Arrow arrow, | 466 views::BubbleBorder::Arrow arrow, |
| 465 const gfx::Rect& anchor_rect, | 467 const gfx::Rect& anchor_rect, |
| 466 Browser* browser, | 468 Browser* browser, |
| 467 profiles::BubbleViewMode view_mode) | 469 profiles::BubbleViewMode view_mode, |
| 470 signin::GAIAServiceType service_type) |
| 468 : BubbleDelegateView(anchor_view, arrow), | 471 : BubbleDelegateView(anchor_view, arrow), |
| 469 browser_(browser), | 472 browser_(browser), |
| 470 view_mode_(view_mode), | 473 view_mode_(view_mode), |
| 471 tutorial_mode_(profiles::TUTORIAL_MODE_NONE) { | 474 tutorial_mode_(profiles::TUTORIAL_MODE_NONE), |
| 475 gaia_service_type_(service_type) { |
| 472 // Reset the default margins inherited from the BubbleDelegateView. | 476 // Reset the default margins inherited from the BubbleDelegateView. |
| 473 set_margins(gfx::Insets()); | 477 set_margins(gfx::Insets()); |
| 474 | 478 |
| 475 ResetView(); | 479 ResetView(); |
| 476 | 480 |
| 477 avatar_menu_.reset(new AvatarMenu( | 481 avatar_menu_.reset(new AvatarMenu( |
| 478 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 482 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 479 this, | 483 this, |
| 480 browser_)); | 484 browser_)); |
| 481 avatar_menu_->RebuildMenu(); | 485 avatar_menu_->RebuildMenu(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 if (sender->parent()) | 621 if (sender->parent()) |
| 618 sender->SetEnabled(false); | 622 sender->SetEnabled(false); |
| 619 | 623 |
| 620 if (sender == users_button_) { | 624 if (sender == users_button_) { |
| 621 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 625 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
| 622 // If this is a guest session, also close all the guest browser windows. | 626 // If this is a guest session, also close all the guest browser windows. |
| 623 if (browser_->profile()->IsGuestSession()) | 627 if (browser_->profile()->IsGuestSession()) |
| 624 profiles::CloseGuestProfileWindows(); | 628 profiles::CloseGuestProfileWindows(); |
| 625 } else if (sender == lock_button_) { | 629 } else if (sender == lock_button_) { |
| 626 profiles::LockProfile(browser_->profile()); | 630 profiles::LockProfile(browser_->profile()); |
| 631 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK); |
| 627 } else if (sender == tutorial_ok_button_) { | 632 } else if (sender == tutorial_ok_button_) { |
| 628 // If the user manually dismissed the tutorial, never show it again by | 633 // If the user manually dismissed the tutorial, never show it again by |
| 629 // setting the number of times shown to the maximum plus 1, so that later we | 634 // setting the number of times shown to the maximum plus 1, so that later we |
| 630 // could distinguish between the dismiss case and the case when the tutorial | 635 // could distinguish between the dismiss case and the case when the tutorial |
| 631 // is indeed shown for the maximum number of times. | 636 // is indeed shown for the maximum number of times. |
| 632 browser_->profile()->GetPrefs()->SetInteger( | 637 browser_->profile()->GetPrefs()->SetInteger( |
| 633 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); | 638 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); |
| 634 | 639 |
| 635 ProfileMetrics::LogProfileUpgradeEnrollment( | 640 ProfileMetrics::LogProfileUpgradeEnrollment( |
| 636 ProfileMetrics::PROFILE_ENROLLMENT_CLOSE_WELCOME_CARD); | 641 ProfileMetrics::PROFILE_ENROLLMENT_CLOSE_WELCOME_CARD); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 } | 706 } |
| 702 } | 707 } |
| 703 } | 708 } |
| 704 } | 709 } |
| 705 | 710 |
| 706 void ProfileChooserView::RemoveAccount() { | 711 void ProfileChooserView::RemoveAccount() { |
| 707 DCHECK(!account_id_to_remove_.empty()); | 712 DCHECK(!account_id_to_remove_.empty()); |
| 708 MutableProfileOAuth2TokenService* oauth2_token_service = | 713 MutableProfileOAuth2TokenService* oauth2_token_service = |
| 709 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( | 714 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
| 710 browser_->profile()); | 715 browser_->profile()); |
| 711 if (oauth2_token_service) | 716 if (oauth2_token_service) { |
| 712 oauth2_token_service->RevokeCredentials(account_id_to_remove_); | 717 oauth2_token_service->RevokeCredentials(account_id_to_remove_); |
| 718 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT); |
| 719 } |
| 713 account_id_to_remove_.clear(); | 720 account_id_to_remove_.clear(); |
| 714 | 721 |
| 715 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); | 722 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); |
| 716 } | 723 } |
| 717 | 724 |
| 718 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { | 725 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { |
| 719 if (sender == manage_accounts_link_) { | 726 if (sender == manage_accounts_link_) { |
| 720 // This link can either mean show/hide the account management view, | 727 // This link can either mean show/hide the account management view, |
| 721 // depending on which view it is displayed. ShowView() will DCHECK if | 728 // depending on which view it is displayed. ShowView() will DCHECK if |
| 722 // the account management view is displayed for non signed-in users. | 729 // the account management view is displayed for non signed-in users. |
| 723 ShowView( | 730 ShowView( |
| 724 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? | 731 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? |
| 725 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER : | 732 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER : |
| 726 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | 733 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, |
| 727 avatar_menu_.get()); | 734 avatar_menu_.get()); |
| 728 } else if (sender == add_account_link_) { | 735 } else if (sender == add_account_link_) { |
| 729 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); | 736 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); |
| 737 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT); |
| 730 } else if (sender == tutorial_learn_more_link_) { | 738 } else if (sender == tutorial_learn_more_link_) { |
| 731 ProfileMetrics::LogProfileUpgradeEnrollment( | 739 ProfileMetrics::LogProfileUpgradeEnrollment( |
| 732 ProfileMetrics::PROFILE_ENROLLMENT_LAUNCH_LEARN_MORE); | 740 ProfileMetrics::PROFILE_ENROLLMENT_LAUNCH_LEARN_MORE); |
| 733 // TODO(guohui): update |learn_more_url| once it is decided. | 741 // TODO(guohui): update |learn_more_url| once it is decided. |
| 734 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); | 742 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); |
| 735 chrome::NavigateParams params( | 743 chrome::NavigateParams params( |
| 736 browser_->profile(), | 744 browser_->profile(), |
| 737 lear_more_url, | 745 lear_more_url, |
| 738 content::PAGE_TRANSITION_LINK); | 746 content::PAGE_TRANSITION_LINK); |
| 739 params.disposition = NEW_FOREGROUND_TAB; | 747 params.disposition = NEW_FOREGROUND_TAB; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 if (profile->IsManaged()) | 779 if (profile->IsManaged()) |
| 772 return true; | 780 return true; |
| 773 | 781 |
| 774 profiles::UpdateProfileName(profile, new_profile_name); | 782 profiles::UpdateProfileName(profile, new_profile_name); |
| 775 current_profile_name_->ShowReadOnlyView(); | 783 current_profile_name_->ShowReadOnlyView(); |
| 776 return true; | 784 return true; |
| 777 } | 785 } |
| 778 return false; | 786 return false; |
| 779 } | 787 } |
| 780 | 788 |
| 789 void ProfileChooserView::PostActionPerformed( |
| 790 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 791 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 792 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 793 } |
| 794 |
| 781 views::View* ProfileChooserView::CreateProfileChooserView( | 795 views::View* ProfileChooserView::CreateProfileChooserView( |
| 782 AvatarMenu* avatar_menu, | 796 AvatarMenu* avatar_menu, |
| 783 profiles::TutorialMode last_tutorial_mode) { | 797 profiles::TutorialMode last_tutorial_mode) { |
| 784 // TODO(guohui, noms): the view should be customized based on whether new | 798 // TODO(guohui, noms): the view should be customized based on whether new |
| 785 // profile management preview is enabled or not. | 799 // profile management preview is enabled or not. |
| 786 | 800 |
| 787 views::View* view = new views::View(); | 801 views::View* view = new views::View(); |
| 788 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 802 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 789 // Separate items into active and alternatives. | 803 // Separate items into active and alternatives. |
| 790 Indexes other_profiles; | 804 Indexes other_profiles; |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 layout->StartRowWithPadding( | 1434 layout->StartRowWithPadding( |
| 1421 1, 0, 0, views::kUnrelatedControlVerticalSpacing); | 1435 1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
| 1422 layout->AddView(end_preview_and_relaunch_button_); | 1436 layout->AddView(end_preview_and_relaunch_button_); |
| 1423 | 1437 |
| 1424 TitleCard* title_card = new TitleCard( | 1438 TitleCard* title_card = new TitleCard( |
| 1425 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); | 1439 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); |
| 1426 return TitleCard::AddPaddedTitleCard( | 1440 return TitleCard::AddPaddedTitleCard( |
| 1427 view, title_card, kFixedAccountRemovalViewWidth); | 1441 view, title_card, kFixedAccountRemovalViewWidth); |
| 1428 } | 1442 } |
| 1429 | 1443 |
| OLD | NEW |