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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 delete this; // Success. | 477 delete this; // Success. |
477 } | 478 } |
478 } | 479 } |
479 } | 480 } |
480 | 481 |
481 void CurrentHistoryCleaner::WebContentsDestroyed( | 482 void CurrentHistoryCleaner::WebContentsDestroyed( |
482 content::WebContents* contents) { | 483 content::WebContents* contents) { |
483 delete this; // Failure. | 484 delete this; // Failure. |
484 } | 485 } |
485 | 486 |
486 void CloseTab(content::WebContents* tab) { | |
487 content::WebContentsDelegate* tab_delegate = tab->GetDelegate(); | |
488 if (tab_delegate) | |
489 tab_delegate->CloseContents(tab); | |
490 } | |
491 | |
492 } // namespace | 487 } // namespace |
493 | 488 |
494 | 489 |
495 // StartSyncArgs -------------------------------------------------------------- | 490 // StartSyncArgs -------------------------------------------------------------- |
496 | 491 |
497 OneClickSigninHelper::StartSyncArgs::StartSyncArgs() | 492 OneClickSigninHelper::StartSyncArgs::StartSyncArgs() |
498 : profile(NULL), | 493 : profile(NULL), |
499 browser(NULL), | 494 browser(NULL), |
500 auto_accept(AUTO_ACCEPT_NONE), | 495 auto_accept(AUTO_ACCEPT_NONE), |
501 web_contents(NULL), | 496 web_contents(NULL), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 void | 656 void |
662 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( | 657 OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( |
663 const std::string& email, | 658 const std::string& email, |
664 const std::string& refresh_token) { | 659 const std::string& refresh_token) { |
665 // The starter deletes itself once it's done. | 660 // The starter deletes itself once it's done. |
666 new OneClickSigninSyncStarter(args_.profile, args_.browser, | 661 new OneClickSigninSyncStarter(args_.profile, args_.browser, |
667 email, args_.password, | 662 email, args_.password, |
668 refresh_token, start_mode_, | 663 refresh_token, start_mode_, |
669 args_.web_contents, | 664 args_.web_contents, |
670 args_.confirmation_required, | 665 args_.confirmation_required, |
666 GURL(), | |
671 args_.callback); | 667 args_.callback); |
672 } | 668 } |
673 | 669 |
674 | 670 |
675 // OneClickSigninHelper ------------------------------------------------------- | 671 // OneClickSigninHelper ------------------------------------------------------- |
676 | 672 |
677 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 673 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
678 | 674 |
679 // static | 675 // static |
680 const int OneClickSigninHelper::kMaxNavigationsSince = 10; | 676 const int OneClickSigninHelper::kMaxNavigationsSince = 10; |
(...skipping 11 matching lines...) Expand all Loading... | |
692 do_not_start_sync_for_testing_(false), | 688 do_not_start_sync_for_testing_(false), |
693 weak_pointer_factory_(this) { | 689 weak_pointer_factory_(this) { |
694 // May be NULL during testing. | 690 // May be NULL during testing. |
695 if (password_manager) { | 691 if (password_manager) { |
696 password_manager->AddSubmissionCallback( | 692 password_manager->AddSubmissionCallback( |
697 base::Bind(&OneClickSigninHelper::PasswordSubmitted, | 693 base::Bind(&OneClickSigninHelper::PasswordSubmitted, |
698 weak_pointer_factory_.GetWeakPtr())); | 694 weak_pointer_factory_.GetWeakPtr())); |
699 } | 695 } |
700 } | 696 } |
701 | 697 |
702 OneClickSigninHelper::~OneClickSigninHelper() { | 698 OneClickSigninHelper::~OneClickSigninHelper() {} |
703 // WebContentsDestroyed() should always be called before the object is | |
704 // deleted. | |
705 DCHECK(!web_contents()); | |
706 } | |
707 | 699 |
708 // static | 700 // static |
709 void OneClickSigninHelper::LogHistogramValue( | 701 void OneClickSigninHelper::LogHistogramValue( |
710 signin::Source source, int action) { | 702 signin::Source source, int action) { |
711 switch (source) { | 703 switch (source) { |
712 case signin::SOURCE_START_PAGE: | 704 case signin::SOURCE_START_PAGE: |
713 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, | 705 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, |
714 one_click_signin::HISTOGRAM_MAX); | 706 one_click_signin::HISTOGRAM_MAX); |
715 break; | 707 break; |
716 case signin::SOURCE_NTP_LINK: | 708 case signin::SOURCE_NTP_LINK: |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 1232 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
1241 showing_signin_ = false; | 1233 showing_signin_ = false; |
1242 email_.clear(); | 1234 email_.clear(); |
1243 password_.clear(); | 1235 password_.clear(); |
1244 auto_accept_ = AUTO_ACCEPT_NONE; | 1236 auto_accept_ = AUTO_ACCEPT_NONE; |
1245 source_ = signin::SOURCE_UNKNOWN; | 1237 source_ = signin::SOURCE_UNKNOWN; |
1246 switched_to_advanced_ = false; | 1238 switched_to_advanced_ = false; |
1247 continue_url_ = GURL(); | 1239 continue_url_ = GURL(); |
1248 untrusted_navigations_since_signin_visit_ = 0; | 1240 untrusted_navigations_since_signin_visit_ = 0; |
1249 untrusted_confirmation_required_ = false; | 1241 untrusted_confirmation_required_ = false; |
1242 original_continue_url_ = GURL(); | |
1250 error_message_.clear(); | 1243 error_message_.clear(); |
1251 | 1244 |
1252 // Post to IO thread to clear pending email. | 1245 // Post to IO thread to clear pending email. |
1253 if (!do_not_clear_pending_email_) { | 1246 if (!do_not_clear_pending_email_) { |
1254 Profile* profile = | 1247 Profile* profile = |
1255 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1248 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1256 content::BrowserThread::PostTask( | 1249 content::BrowserThread::PostTask( |
1257 content::BrowserThread::IO, FROM_HERE, | 1250 content::BrowserThread::IO, FROM_HERE, |
1258 base::Bind(&ClearPendingEmailOnIOThread, | 1251 base::Bind(&ClearPendingEmailOnIOThread, |
1259 base::Unretained(profile->GetResourceContext()))); | 1252 base::Unretained(profile->GetResourceContext()))); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1556 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); | 1549 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); |
1557 } | 1550 } |
1558 | 1551 |
1559 // Observe the sync service if the Webstore tab or the settings tab | 1552 // Observe the sync service if the Webstore tab or the settings tab |
1560 // requested a gaia sign in, so that when sign in and sync setup are | 1553 // requested a gaia sign in, so that when sign in and sync setup are |
1561 // successful, we can redirect to the correct URL, or auto-close the gaia | 1554 // successful, we can redirect to the correct URL, or auto-close the gaia |
1562 // sign in tab. | 1555 // sign in tab. |
1563 if (original_source == signin::SOURCE_SETTINGS || | 1556 if (original_source == signin::SOURCE_SETTINGS || |
1564 (original_source == signin::SOURCE_WEBSTORE_INSTALL && | 1557 (original_source == signin::SOURCE_WEBSTORE_INSTALL && |
1565 source_ == signin::SOURCE_SETTINGS)) { | 1558 source_ == signin::SOURCE_SETTINGS)) { |
1566 ProfileSyncService* sync_service = | 1559 // The observer deletes itself once it's done. |
1567 ProfileSyncServiceFactory::GetForProfile(profile); | 1560 new OneClickSigninSyncObserver(contents, original_continue_url_); |
guohui
2014/03/24 20:55:58
OneClickSigninHelper is mostly used for web-based
Ilya Sherman
2014/03/26 08:21:39
I'm factoring out some code from this file into th
| |
1568 if (sync_service) | |
1569 sync_service->AddObserver(this); | |
1570 } | 1561 } |
1571 break; | 1562 break; |
1572 } | 1563 } |
1573 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1564 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1574 AddEmailToOneClickRejectedList(profile, email_); | 1565 AddEmailToOneClickRejectedList(profile, email_); |
1575 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1566 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1576 break; | 1567 break; |
1577 default: | 1568 default: |
1578 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1569 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1579 break; | 1570 break; |
1580 } | 1571 } |
1581 | 1572 |
1582 CleanTransientState(); | 1573 CleanTransientState(); |
1583 } | 1574 } |
1584 | 1575 |
1585 // It is guaranteed that this method is called before the object is deleted. | |
1586 void OneClickSigninHelper::WebContentsDestroyed( | |
1587 content::WebContents* contents) { | |
1588 Profile* profile = | |
1589 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1590 ProfileSyncService* sync_service = | |
1591 ProfileSyncServiceFactory::GetForProfile(profile); | |
1592 if (sync_service) | |
1593 sync_service->RemoveObserver(this); | |
1594 } | |
1595 | |
1596 void OneClickSigninHelper::OnStateChanged() { | |
1597 // We only add observer for ProfileSyncService when original_continue_url_ is | |
1598 // not empty. | |
1599 DCHECK(!original_continue_url_.is_empty()); | |
1600 | |
1601 content::WebContents* contents = web_contents(); | |
1602 Profile* profile = | |
1603 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1604 ProfileSyncService* sync_service = | |
1605 ProfileSyncServiceFactory::GetForProfile(profile); | |
1606 | |
1607 // At this point, the sign in process is complete, and control has been handed | |
1608 // back to the sync engine. Close the gaia sign in tab if | |
1609 // |original_continue_url_| contains the |auto_close| parameter. Otherwise, | |
1610 // wait for sync setup to complete and then navigate to | |
1611 // |original_continue_url_|. | |
1612 if (signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | |
1613 // Close the gaia sign in tab via a task to make sure we aren't in the | |
1614 // middle of any webui handler code. | |
1615 base::MessageLoop::current()->PostTask( | |
1616 FROM_HERE, | |
1617 base::Bind(&CloseTab, base::Unretained(contents))); | |
1618 } else { | |
1619 // Sync setup not completed yet. | |
1620 if (sync_service->FirstSetupInProgress()) | |
1621 return; | |
1622 | |
1623 if (sync_service->sync_initialized() && | |
1624 signin::GetSourceForPromoURL(original_continue_url_) | |
1625 != signin::SOURCE_SETTINGS) { | |
1626 contents->GetController().LoadURL(original_continue_url_, | |
1627 content::Referrer(), | |
1628 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
1629 std::string()); | |
1630 } | |
1631 } | |
1632 | |
1633 // Clears |original_continue_url_| here instead of in CleanTransientState, | |
1634 // because it is used in OnStateChanged which occurs later. | |
1635 original_continue_url_ = GURL(); | |
1636 sync_service->RemoveObserver(this); | |
1637 } | |
1638 | |
1639 OneClickSigninSyncStarter::Callback | 1576 OneClickSigninSyncStarter::Callback |
1640 OneClickSigninHelper::CreateSyncStarterCallback() { | 1577 OneClickSigninHelper::CreateSyncStarterCallback() { |
1641 // The callback will only be invoked if this object is still alive when sync | 1578 // The callback will only be invoked if this object is still alive when sync |
1642 // setup is completed. This is correct because this object is only deleted | 1579 // setup is completed. This is correct because this object is only deleted |
1643 // when the web contents that potentially shows a blank page is deleted. | 1580 // when the web contents that potentially shows a blank page is deleted. |
1644 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, | 1581 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, |
1645 weak_pointer_factory_.GetWeakPtr()); | 1582 weak_pointer_factory_.GetWeakPtr()); |
1646 } | 1583 } |
1647 | 1584 |
1648 void OneClickSigninHelper::SyncSetupCompletedCallback( | 1585 void OneClickSigninHelper::SyncSetupCompletedCallback( |
1649 OneClickSigninSyncStarter::SyncSetupResult result) { | 1586 OneClickSigninSyncStarter::SyncSetupResult result) { |
1650 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && | 1587 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && |
1651 web_contents()) { | 1588 web_contents()) { |
1652 GURL current_url = web_contents()->GetVisibleURL(); | 1589 GURL current_url = web_contents()->GetVisibleURL(); |
1653 | 1590 |
1654 // If the web contents is showing a blank page and not about to be closed, | 1591 // If the web contents is showing a blank page and not about to be closed, |
1655 // redirect to the NTP or apps page. | 1592 // redirect to the NTP or apps page. |
1656 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1593 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1657 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1594 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1658 RedirectToNtpOrAppsPage( | 1595 RedirectToNtpOrAppsPage( |
1659 web_contents(), | 1596 web_contents(), |
1660 signin::GetSourceForPromoURL(original_continue_url_)); | 1597 signin::GetSourceForPromoURL(original_continue_url_)); |
1661 } | 1598 } |
1662 } | 1599 } |
1663 } | 1600 } |
OLD | NEW |