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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 380 |
380 // ProfileChooserView --------------------------------------------------------- | 381 // ProfileChooserView --------------------------------------------------------- |
381 | 382 |
382 // static | 383 // static |
383 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; | 384 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; |
384 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; | 385 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; |
385 | 386 |
386 // static | 387 // static |
387 void ProfileChooserView::ShowBubble( | 388 void ProfileChooserView::ShowBubble( |
388 BubbleViewMode view_mode, | 389 BubbleViewMode view_mode, |
390 signin::GAIA_SERVICE_TYPE service_type, | |
389 views::View* anchor_view, | 391 views::View* anchor_view, |
390 views::BubbleBorder::Arrow arrow, | 392 views::BubbleBorder::Arrow arrow, |
391 views::BubbleBorder::BubbleAlignment border_alignment, | 393 views::BubbleBorder::BubbleAlignment border_alignment, |
392 const gfx::Rect& anchor_rect, | 394 const gfx::Rect& anchor_rect, |
393 Browser* browser) { | 395 Browser* browser) { |
394 if (IsShowing()) | 396 if (IsShowing()) |
395 return; | 397 return; |
396 | 398 |
397 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, anchor_rect, | 399 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, anchor_rect, |
398 browser, view_mode); | 400 browser, view_mode, service_type); |
399 views::BubbleDelegateView::CreateBubble(profile_bubble_); | 401 views::BubbleDelegateView::CreateBubble(profile_bubble_); |
400 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); | 402 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); |
401 profile_bubble_->SetAlignment(border_alignment); | 403 profile_bubble_->SetAlignment(border_alignment); |
402 profile_bubble_->GetWidget()->Show(); | 404 profile_bubble_->GetWidget()->Show(); |
403 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 405 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
404 } | 406 } |
405 | 407 |
406 // static | 408 // static |
407 bool ProfileChooserView::IsShowing() { | 409 bool ProfileChooserView::IsShowing() { |
408 return profile_bubble_ != NULL; | 410 return profile_bubble_ != NULL; |
409 } | 411 } |
410 | 412 |
411 // static | 413 // static |
412 void ProfileChooserView::Hide() { | 414 void ProfileChooserView::Hide() { |
413 if (IsShowing()) | 415 if (IsShowing()) |
414 profile_bubble_->GetWidget()->Close(); | 416 profile_bubble_->GetWidget()->Close(); |
415 } | 417 } |
416 | 418 |
417 ProfileChooserView::ProfileChooserView(views::View* anchor_view, | 419 ProfileChooserView::ProfileChooserView(views::View* anchor_view, |
418 views::BubbleBorder::Arrow arrow, | 420 views::BubbleBorder::Arrow arrow, |
419 const gfx::Rect& anchor_rect, | 421 const gfx::Rect& anchor_rect, |
420 Browser* browser, | 422 Browser* browser, |
421 BubbleViewMode view_mode) | 423 BubbleViewMode view_mode, |
424 signin::GAIA_SERVICE_TYPE service_type) | |
422 : BubbleDelegateView(anchor_view, arrow), | 425 : BubbleDelegateView(anchor_view, arrow), |
423 browser_(browser), | 426 browser_(browser), |
427 tutorial_mode_(TUTORIAL_MODE_NONE), | |
424 view_mode_(view_mode), | 428 view_mode_(view_mode), |
425 tutorial_mode_(TUTORIAL_MODE_NONE) { | 429 gaia_service_type_(service_type) { |
guohui
2014/05/22 20:20:49
gaia_service_type_ is not cleared anywhere, it mea
Mike Lerman
2014/05/23 17:15:36
There is not real default, we would need to reset
| |
426 // Reset the default margins inherited from the BubbleDelegateView. | 430 // Reset the default margins inherited from the BubbleDelegateView. |
427 set_margins(gfx::Insets()); | 431 set_margins(gfx::Insets()); |
428 | 432 |
429 ResetView(); | 433 ResetView(); |
430 | 434 |
431 avatar_menu_.reset(new AvatarMenu( | 435 avatar_menu_.reset(new AvatarMenu( |
432 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 436 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
433 this, | 437 this, |
434 browser_)); | 438 browser_)); |
435 avatar_menu_->RebuildMenu(); | 439 avatar_menu_->RebuildMenu(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 // has no parent (like in tests) because that will also crash. | 565 // has no parent (like in tests) because that will also crash. |
562 if (sender->parent()) | 566 if (sender->parent()) |
563 sender->SetEnabled(false); | 567 sender->SetEnabled(false); |
564 | 568 |
565 if (sender == users_button_) { | 569 if (sender == users_button_) { |
566 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 570 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
567 // If this is a guest session, also close all the guest browser windows. | 571 // If this is a guest session, also close all the guest browser windows. |
568 if (browser_->profile()->IsGuestSession()) | 572 if (browser_->profile()->IsGuestSession()) |
569 profiles::CloseGuestProfileWindows(); | 573 profiles::CloseGuestProfileWindows(); |
570 } else if (sender == lock_button_) { | 574 } else if (sender == lock_button_) { |
575 ProfileMetrics::LogProfileDesktopMenu( | |
576 ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK, gaia_service_type_); | |
571 profiles::LockProfile(browser_->profile()); | 577 profiles::LockProfile(browser_->profile()); |
572 } else if (sender == tutorial_ok_button_) { | 578 } else if (sender == tutorial_ok_button_) { |
573 // If the user manually dismissed the tutorial, never show it again by | 579 // If the user manually dismissed the tutorial, never show it again by |
574 // setting the number of times shown to the maximum plus 1, so that later we | 580 // setting the number of times shown to the maximum plus 1, so that later we |
575 // could distinguish between the dismiss case and the case when the tutorial | 581 // could distinguish between the dismiss case and the case when the tutorial |
576 // is indeed shown for the maximum number of times. | 582 // is indeed shown for the maximum number of times. |
577 browser_->profile()->GetPrefs()->SetInteger( | 583 browser_->profile()->GetPrefs()->SetInteger( |
578 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); | 584 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); |
579 | 585 |
580 ProfileMetrics::LogProfileUpgradeEnrollment( | 586 ProfileMetrics::LogProfileUpgradeEnrollment( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 // buttons was pressed. | 629 // buttons was pressed. |
624 ButtonIndexes::const_iterator profile_match = | 630 ButtonIndexes::const_iterator profile_match = |
625 open_other_profile_indexes_map_.find(sender); | 631 open_other_profile_indexes_map_.find(sender); |
626 if (profile_match != open_other_profile_indexes_map_.end()) { | 632 if (profile_match != open_other_profile_indexes_map_.end()) { |
627 avatar_menu_->SwitchToProfile( | 633 avatar_menu_->SwitchToProfile( |
628 profile_match->second, | 634 profile_match->second, |
629 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, | 635 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, |
630 ProfileMetrics::SWITCH_PROFILE_ICON); | 636 ProfileMetrics::SWITCH_PROFILE_ICON); |
631 } else { | 637 } else { |
632 // This was a profile accounts button. | 638 // This was a profile accounts button. |
639 ProfileMetrics::LogProfileDesktopMenu( | |
640 ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT, gaia_service_type_); | |
guohui
2014/05/22 20:20:49
here we just show the account removal view, the ac
Mike Lerman
2014/05/23 17:15:36
Done.
| |
633 AccountButtonIndexes::const_iterator account_match = | 641 AccountButtonIndexes::const_iterator account_match = |
634 current_profile_accounts_map_.find(sender); | 642 current_profile_accounts_map_.find(sender); |
635 DCHECK(account_match != current_profile_accounts_map_.end()); | 643 DCHECK(account_match != current_profile_accounts_map_.end()); |
636 account_id_to_remove_ = account_match->second; | 644 account_id_to_remove_ = account_match->second; |
637 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); | 645 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); |
638 } | 646 } |
639 } | 647 } |
640 } | 648 } |
641 | 649 |
642 void ProfileChooserView::RemoveAccount() { | 650 void ProfileChooserView::RemoveAccount() { |
(...skipping 12 matching lines...) Expand all Loading... | |
655 if (sender == manage_accounts_link_) { | 663 if (sender == manage_accounts_link_) { |
656 // This link can either mean show/hide the account management view, | 664 // This link can either mean show/hide the account management view, |
657 // depending on which view it is displayed. ShowView() will DCHECK if | 665 // depending on which view it is displayed. ShowView() will DCHECK if |
658 // the account management view is displayed for non signed-in users. | 666 // the account management view is displayed for non signed-in users. |
659 ShowView( | 667 ShowView( |
660 view_mode_ == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? | 668 view_mode_ == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? |
661 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : | 669 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : |
662 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | 670 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, |
663 avatar_menu_.get()); | 671 avatar_menu_.get()); |
664 } else if (sender == add_account_link_) { | 672 } else if (sender == add_account_link_) { |
673 ProfileMetrics::LogProfileDesktopMenu( | |
674 ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT, gaia_service_type_); | |
665 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); | 675 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); |
666 } else if (sender == tutorial_learn_more_link_) { | 676 } else if (sender == tutorial_learn_more_link_) { |
667 ProfileMetrics::LogProfileUpgradeEnrollment( | 677 ProfileMetrics::LogProfileUpgradeEnrollment( |
668 ProfileMetrics::PROFILE_ENROLLMENT_LAUNCH_LEARN_MORE); | 678 ProfileMetrics::PROFILE_ENROLLMENT_LAUNCH_LEARN_MORE); |
669 // TODO(guohui): update |learn_more_url| once it is decided. | 679 // TODO(guohui): update |learn_more_url| once it is decided. |
670 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); | 680 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); |
671 chrome::NavigateParams params( | 681 chrome::NavigateParams params( |
672 browser_->profile(), | 682 browser_->profile(), |
673 lear_more_url, | 683 lear_more_url, |
674 content::PAGE_TRANSITION_LINK); | 684 content::PAGE_TRANSITION_LINK); |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 layout->StartRowWithPadding( | 1312 layout->StartRowWithPadding( |
1303 1, 0, 0, views::kUnrelatedControlVerticalSpacing); | 1313 1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
1304 layout->AddView(end_preview_and_relaunch_button_); | 1314 layout->AddView(end_preview_and_relaunch_button_); |
1305 | 1315 |
1306 TitleCard* title_card = new TitleCard( | 1316 TitleCard* title_card = new TitleCard( |
1307 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); | 1317 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); |
1308 return TitleCard::AddPaddedTitleCard( | 1318 return TitleCard::AddPaddedTitleCard( |
1309 view, title_card, kFixedAccountRemovalViewWidth); | 1319 view, title_card, kFixedAccountRemovalViewWidth); |
1310 } | 1320 } |
1311 | 1321 |
OLD | NEW |