OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/signin/signin_names_io_thread.h" | 42 #include "chrome/browser/signin/signin_names_io_thread.h" |
43 #include "chrome/browser/sync/profile_sync_service.h" | 43 #include "chrome/browser/sync/profile_sync_service.h" |
44 #include "chrome/browser/sync/profile_sync_service_factory.h" | 44 #include "chrome/browser/sync/profile_sync_service_factory.h" |
45 #include "chrome/browser/tab_contents/tab_util.h" | 45 #include "chrome/browser/tab_contents/tab_util.h" |
46 #include "chrome/browser/ui/browser_finder.h" | 46 #include "chrome/browser/ui/browser_finder.h" |
47 #include "chrome/browser/ui/browser_list.h" | 47 #include "chrome/browser/ui/browser_list.h" |
48 #include "chrome/browser/ui/browser_tabstrip.h" | 48 #include "chrome/browser/ui/browser_tabstrip.h" |
49 #include "chrome/browser/ui/browser_window.h" | 49 #include "chrome/browser/ui/browser_window.h" |
50 #include "chrome/browser/ui/chrome_pages.h" | 50 #include "chrome/browser/ui/chrome_pages.h" |
51 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 51 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
| 52 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
52 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 53 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
53 #include "chrome/browser/ui/sync/signin_histogram.h" | 54 #include "chrome/browser/ui/sync/signin_histogram.h" |
54 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 55 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
55 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 56 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 57 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
57 #include "chrome/common/chrome_version_info.h" | 58 #include "chrome/common/chrome_version_info.h" |
58 #include "chrome/common/net/url_util.h" | 59 #include "chrome/common/net/url_util.h" |
59 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
60 #include "chrome/common/profile_management_switches.h" | 61 #include "chrome/common/profile_management_switches.h" |
61 #include "chrome/common/url_constants.h" | 62 #include "chrome/common/url_constants.h" |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 delete this; // Success. | 478 delete this; // Success. |
478 } | 479 } |
479 } | 480 } |
480 } | 481 } |
481 | 482 |
482 void CurrentHistoryCleaner::WebContentsDestroyed( | 483 void CurrentHistoryCleaner::WebContentsDestroyed( |
483 content::WebContents* contents) { | 484 content::WebContents* contents) { |
484 delete this; // Failure. | 485 delete this; // Failure. |
485 } | 486 } |
486 | 487 |
487 void CloseTab(content::WebContents* tab) { | |
488 content::WebContentsDelegate* tab_delegate = tab->GetDelegate(); | |
489 if (tab_delegate) | |
490 tab_delegate->CloseContents(tab); | |
491 } | |
492 | |
493 } // namespace | 488 } // namespace |
494 | 489 |
495 | 490 |
496 // StartSyncArgs -------------------------------------------------------------- | 491 // StartSyncArgs -------------------------------------------------------------- |
497 | 492 |
498 OneClickSigninHelper::StartSyncArgs::StartSyncArgs() | 493 OneClickSigninHelper::StartSyncArgs::StartSyncArgs() |
499 : profile(NULL), | 494 : profile(NULL), |
500 browser(NULL), | 495 browser(NULL), |
501 auto_accept(AUTO_ACCEPT_NONE), | 496 auto_accept(AUTO_ACCEPT_NONE), |
502 web_contents(NULL), | 497 web_contents(NULL), |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 do_not_start_sync_for_testing_(false), | 688 do_not_start_sync_for_testing_(false), |
694 weak_pointer_factory_(this) { | 689 weak_pointer_factory_(this) { |
695 // May be NULL during testing. | 690 // May be NULL during testing. |
696 if (password_manager) { | 691 if (password_manager) { |
697 password_manager->AddSubmissionCallback( | 692 password_manager->AddSubmissionCallback( |
698 base::Bind(&OneClickSigninHelper::PasswordSubmitted, | 693 base::Bind(&OneClickSigninHelper::PasswordSubmitted, |
699 weak_pointer_factory_.GetWeakPtr())); | 694 weak_pointer_factory_.GetWeakPtr())); |
700 } | 695 } |
701 } | 696 } |
702 | 697 |
703 OneClickSigninHelper::~OneClickSigninHelper() { | 698 OneClickSigninHelper::~OneClickSigninHelper() {} |
704 // WebContentsDestroyed() should always be called before the object is | |
705 // deleted. | |
706 DCHECK(!web_contents()); | |
707 } | |
708 | 699 |
709 // static | 700 // static |
710 void OneClickSigninHelper::LogHistogramValue( | 701 void OneClickSigninHelper::LogHistogramValue( |
711 signin::Source source, int action) { | 702 signin::Source source, int action) { |
712 switch (source) { | 703 switch (source) { |
713 case signin::SOURCE_START_PAGE: | 704 case signin::SOURCE_START_PAGE: |
714 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, | 705 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, |
715 one_click_signin::HISTOGRAM_MAX); | 706 one_click_signin::HISTOGRAM_MAX); |
716 break; | 707 break; |
717 case signin::SOURCE_NTP_LINK: | 708 case signin::SOURCE_NTP_LINK: |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); | 1554 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); |
1564 } | 1555 } |
1565 | 1556 |
1566 // Observe the sync service if the Webstore tab or the settings tab | 1557 // Observe the sync service if the Webstore tab or the settings tab |
1567 // requested a gaia sign in, so that when sign in and sync setup are | 1558 // requested a gaia sign in, so that when sign in and sync setup are |
1568 // successful, we can redirect to the correct URL, or auto-close the gaia | 1559 // successful, we can redirect to the correct URL, or auto-close the gaia |
1569 // sign in tab. | 1560 // sign in tab. |
1570 if (original_source == signin::SOURCE_SETTINGS || | 1561 if (original_source == signin::SOURCE_SETTINGS || |
1571 (original_source == signin::SOURCE_WEBSTORE_INSTALL && | 1562 (original_source == signin::SOURCE_WEBSTORE_INSTALL && |
1572 source_ == signin::SOURCE_SETTINGS)) { | 1563 source_ == signin::SOURCE_SETTINGS)) { |
1573 ProfileSyncService* sync_service = | 1564 // The observer deletes itself once it's done. |
1574 ProfileSyncServiceFactory::GetForProfile(profile); | 1565 new OneClickSigninSyncObserver(contents, original_continue_url_); |
1575 if (sync_service) | |
1576 sync_service->AddObserver(this); | |
1577 } | 1566 } |
1578 break; | 1567 break; |
1579 } | 1568 } |
1580 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1569 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1581 AddEmailToOneClickRejectedList(profile, email_); | 1570 AddEmailToOneClickRejectedList(profile, email_); |
1582 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1571 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1583 break; | 1572 break; |
1584 default: | 1573 default: |
1585 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1574 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1586 break; | 1575 break; |
1587 } | 1576 } |
1588 | 1577 |
1589 CleanTransientState(); | 1578 CleanTransientState(); |
1590 } | 1579 } |
1591 | 1580 |
1592 // It is guaranteed that this method is called before the object is deleted. | |
1593 void OneClickSigninHelper::WebContentsDestroyed( | |
1594 content::WebContents* contents) { | |
1595 Profile* profile = | |
1596 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1597 ProfileSyncService* sync_service = | |
1598 ProfileSyncServiceFactory::GetForProfile(profile); | |
1599 if (sync_service) | |
1600 sync_service->RemoveObserver(this); | |
1601 } | |
1602 | |
1603 void OneClickSigninHelper::OnStateChanged() { | |
1604 // We only add observer for ProfileSyncService when original_continue_url_ is | |
1605 // not empty. | |
1606 DCHECK(!original_continue_url_.is_empty()); | |
1607 | |
1608 content::WebContents* contents = web_contents(); | |
1609 Profile* profile = | |
1610 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1611 ProfileSyncService* sync_service = | |
1612 ProfileSyncServiceFactory::GetForProfile(profile); | |
1613 | |
1614 // At this point, the sign in process is complete, and control has been handed | |
1615 // back to the sync engine. Close the gaia sign in tab if | |
1616 // |original_continue_url_| contains the |auto_close| parameter. Otherwise, | |
1617 // wait for sync setup to complete and then navigate to | |
1618 // |original_continue_url_|. | |
1619 if (signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | |
1620 // Close the gaia sign in tab via a task to make sure we aren't in the | |
1621 // middle of any webui handler code. | |
1622 base::MessageLoop::current()->PostTask( | |
1623 FROM_HERE, | |
1624 base::Bind(&CloseTab, base::Unretained(contents))); | |
1625 } else { | |
1626 // Sync setup not completed yet. | |
1627 if (sync_service->FirstSetupInProgress()) | |
1628 return; | |
1629 | |
1630 if (sync_service->sync_initialized() && | |
1631 signin::GetSourceForPromoURL(original_continue_url_) | |
1632 != signin::SOURCE_SETTINGS) { | |
1633 contents->GetController().LoadURL(original_continue_url_, | |
1634 content::Referrer(), | |
1635 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
1636 std::string()); | |
1637 } | |
1638 } | |
1639 | |
1640 // Clears |original_continue_url_| here instead of in CleanTransientState, | |
1641 // because it is used in OnStateChanged which occurs later. | |
1642 original_continue_url_ = GURL(); | |
1643 sync_service->RemoveObserver(this); | |
1644 } | |
1645 | |
1646 OneClickSigninSyncStarter::Callback | 1581 OneClickSigninSyncStarter::Callback |
1647 OneClickSigninHelper::CreateSyncStarterCallback() { | 1582 OneClickSigninHelper::CreateSyncStarterCallback() { |
1648 // The callback will only be invoked if this object is still alive when sync | 1583 // The callback will only be invoked if this object is still alive when sync |
1649 // setup is completed. This is correct because this object is only deleted | 1584 // setup is completed. This is correct because this object is only deleted |
1650 // when the web contents that potentially shows a blank page is deleted. | 1585 // when the web contents that potentially shows a blank page is deleted. |
1651 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, | 1586 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, |
1652 weak_pointer_factory_.GetWeakPtr()); | 1587 weak_pointer_factory_.GetWeakPtr()); |
1653 } | 1588 } |
1654 | 1589 |
1655 void OneClickSigninHelper::SyncSetupCompletedCallback( | 1590 void OneClickSigninHelper::SyncSetupCompletedCallback( |
1656 OneClickSigninSyncStarter::SyncSetupResult result) { | 1591 OneClickSigninSyncStarter::SyncSetupResult result) { |
1657 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && | 1592 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && |
1658 web_contents()) { | 1593 web_contents()) { |
1659 GURL current_url = web_contents()->GetVisibleURL(); | 1594 GURL current_url = web_contents()->GetVisibleURL(); |
1660 | 1595 |
1661 // If the web contents is showing a blank page and not about to be closed, | 1596 // If the web contents is showing a blank page and not about to be closed, |
1662 // redirect to the NTP or apps page. | 1597 // redirect to the NTP or apps page. |
1663 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1598 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1664 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1599 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1665 RedirectToNtpOrAppsPage( | 1600 RedirectToNtpOrAppsPage( |
1666 web_contents(), | 1601 web_contents(), |
1667 signin::GetSourceForPromoURL(original_continue_url_)); | 1602 signin::GetSourceForPromoURL(original_continue_url_)); |
1668 } | 1603 } |
1669 } | 1604 } |
1670 } | 1605 } |
OLD | NEW |