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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "chrome/browser/signin/signin_names_io_thread.h" | 43 #include "chrome/browser/signin/signin_names_io_thread.h" |
44 #include "chrome/browser/sync/profile_sync_service.h" | 44 #include "chrome/browser/sync/profile_sync_service.h" |
45 #include "chrome/browser/sync/profile_sync_service_factory.h" | 45 #include "chrome/browser/sync/profile_sync_service_factory.h" |
46 #include "chrome/browser/tab_contents/tab_util.h" | 46 #include "chrome/browser/tab_contents/tab_util.h" |
47 #include "chrome/browser/ui/browser_finder.h" | 47 #include "chrome/browser/ui/browser_finder.h" |
48 #include "chrome/browser/ui/browser_list.h" | 48 #include "chrome/browser/ui/browser_list.h" |
49 #include "chrome/browser/ui/browser_tabstrip.h" | 49 #include "chrome/browser/ui/browser_tabstrip.h" |
50 #include "chrome/browser/ui/browser_window.h" | 50 #include "chrome/browser/ui/browser_window.h" |
51 #include "chrome/browser/ui/chrome_pages.h" | 51 #include "chrome/browser/ui/chrome_pages.h" |
52 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" | 52 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
53 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" | |
53 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 54 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
54 #include "chrome/browser/ui/sync/signin_histogram.h" | 55 #include "chrome/browser/ui/sync/signin_histogram.h" |
55 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 56 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
56 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 57 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
57 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 58 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
58 #include "chrome/common/chrome_version_info.h" | 59 #include "chrome/common/chrome_version_info.h" |
59 #include "chrome/common/net/url_util.h" | 60 #include "chrome/common/net/url_util.h" |
60 #include "chrome/common/pref_names.h" | 61 #include "chrome/common/pref_names.h" |
61 #include "chrome/common/profile_management_switches.h" | 62 #include "chrome/common/profile_management_switches.h" |
62 #include "chrome/common/url_constants.h" | 63 #include "chrome/common/url_constants.h" |
(...skipping 414 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()); | |
Roger Tawa OOO till Jul 10th
2014/03/31 18:24:11
Why is this DCHECK no longer valid?
Ilya Sherman
2014/03/31 19:34:06
It's valid, but no longer relevant, since this cla
| |
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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1241 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 1232 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
1242 showing_signin_ = false; | 1233 showing_signin_ = false; |
1243 email_.clear(); | 1234 email_.clear(); |
1244 password_.clear(); | 1235 password_.clear(); |
1245 auto_accept_ = AUTO_ACCEPT_NONE; | 1236 auto_accept_ = AUTO_ACCEPT_NONE; |
1246 source_ = signin::SOURCE_UNKNOWN; | 1237 source_ = signin::SOURCE_UNKNOWN; |
1247 switched_to_advanced_ = false; | 1238 switched_to_advanced_ = false; |
1248 continue_url_ = GURL(); | 1239 continue_url_ = GURL(); |
1249 untrusted_navigations_since_signin_visit_ = 0; | 1240 untrusted_navigations_since_signin_visit_ = 0; |
1250 untrusted_confirmation_required_ = false; | 1241 untrusted_confirmation_required_ = false; |
1242 original_continue_url_ = GURL(); | |
Roger Tawa OOO till Jul 10th
2014/03/31 18:24:11
Because this member is used in OneClickSigninHelpe
Ilya Sherman
2014/04/01 02:00:35
Good catch. Is it ok to never reset the continue
Roger Tawa OOO till Jul 10th
2014/04/01 15:21:08
Its OK to not reset here, it would be reinitialize
| |
1251 error_message_.clear(); | 1243 error_message_.clear(); |
1252 | 1244 |
1253 // Post to IO thread to clear pending email. | 1245 // Post to IO thread to clear pending email. |
1254 if (!do_not_clear_pending_email_) { | 1246 if (!do_not_clear_pending_email_) { |
1255 Profile* profile = | 1247 Profile* profile = |
1256 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1248 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1257 content::BrowserThread::PostTask( | 1249 content::BrowserThread::PostTask( |
1258 content::BrowserThread::IO, FROM_HERE, | 1250 content::BrowserThread::IO, FROM_HERE, |
1259 base::Bind(&ClearPendingEmailOnIOThread, | 1251 base::Bind(&ClearPendingEmailOnIOThread, |
1260 base::Unretained(profile->GetResourceContext()))); | 1252 base::Unretained(profile->GetResourceContext()))); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1557 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); | 1549 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); |
1558 } | 1550 } |
1559 | 1551 |
1560 // 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 |
1561 // 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 |
1562 // 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 |
1563 // sign in tab. | 1555 // sign in tab. |
1564 if (original_source == signin::SOURCE_SETTINGS || | 1556 if (original_source == signin::SOURCE_SETTINGS || |
1565 (original_source == signin::SOURCE_WEBSTORE_INSTALL && | 1557 (original_source == signin::SOURCE_WEBSTORE_INSTALL && |
1566 source_ == signin::SOURCE_SETTINGS)) { | 1558 source_ == signin::SOURCE_SETTINGS)) { |
1567 ProfileSyncService* sync_service = | 1559 // The observer deletes itself once it's done. |
1568 ProfileSyncServiceFactory::GetForProfile(profile); | 1560 new OneClickSigninSyncObserver(contents, original_continue_url_); |
1569 if (sync_service) | |
1570 sync_service->AddObserver(this); | |
1571 } | 1561 } |
1572 break; | 1562 break; |
1573 } | 1563 } |
1574 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1564 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1575 AddEmailToOneClickRejectedList(profile, email_); | 1565 AddEmailToOneClickRejectedList(profile, email_); |
1576 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1566 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1577 break; | 1567 break; |
1578 default: | 1568 default: |
1579 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1569 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1580 break; | 1570 break; |
1581 } | 1571 } |
1582 | 1572 |
1583 CleanTransientState(); | 1573 CleanTransientState(); |
1584 } | 1574 } |
1585 | 1575 |
1586 // It is guaranteed that this method is called before the object is deleted. | |
1587 void OneClickSigninHelper::WebContentsDestroyed( | |
1588 content::WebContents* contents) { | |
1589 Profile* profile = | |
1590 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1591 ProfileSyncService* sync_service = | |
1592 ProfileSyncServiceFactory::GetForProfile(profile); | |
1593 if (sync_service) | |
1594 sync_service->RemoveObserver(this); | |
1595 } | |
1596 | |
1597 void OneClickSigninHelper::OnStateChanged() { | |
1598 // We only add observer for ProfileSyncService when original_continue_url_ is | |
1599 // not empty. | |
1600 DCHECK(!original_continue_url_.is_empty()); | |
1601 | |
1602 content::WebContents* contents = web_contents(); | |
1603 Profile* profile = | |
1604 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
1605 ProfileSyncService* sync_service = | |
1606 ProfileSyncServiceFactory::GetForProfile(profile); | |
1607 | |
1608 // At this point, the sign in process is complete, and control has been handed | |
1609 // back to the sync engine. Close the gaia sign in tab if | |
1610 // |original_continue_url_| contains the |auto_close| parameter. Otherwise, | |
1611 // wait for sync setup to complete and then navigate to | |
1612 // |original_continue_url_|. | |
1613 if (signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | |
1614 // Close the gaia sign in tab via a task to make sure we aren't in the | |
1615 // middle of any webui handler code. | |
1616 base::MessageLoop::current()->PostTask( | |
1617 FROM_HERE, | |
1618 base::Bind(&CloseTab, base::Unretained(contents))); | |
1619 } else { | |
1620 // Sync setup not completed yet. | |
1621 if (sync_service->FirstSetupInProgress()) | |
1622 return; | |
1623 | |
1624 if (sync_service->sync_initialized() && | |
1625 signin::GetSourceForPromoURL(original_continue_url_) | |
1626 != signin::SOURCE_SETTINGS) { | |
1627 contents->GetController().LoadURL(original_continue_url_, | |
1628 content::Referrer(), | |
1629 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
1630 std::string()); | |
1631 } | |
1632 } | |
1633 | |
1634 // Clears |original_continue_url_| here instead of in CleanTransientState, | |
1635 // because it is used in OnStateChanged which occurs later. | |
1636 original_continue_url_ = GURL(); | |
1637 sync_service->RemoveObserver(this); | |
1638 } | |
1639 | |
1640 OneClickSigninSyncStarter::Callback | 1576 OneClickSigninSyncStarter::Callback |
1641 OneClickSigninHelper::CreateSyncStarterCallback() { | 1577 OneClickSigninHelper::CreateSyncStarterCallback() { |
1642 // 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 |
1643 // 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 |
1644 // 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. |
1645 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, | 1581 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback, |
1646 weak_pointer_factory_.GetWeakPtr()); | 1582 weak_pointer_factory_.GetWeakPtr()); |
1647 } | 1583 } |
1648 | 1584 |
1649 void OneClickSigninHelper::SyncSetupCompletedCallback( | 1585 void OneClickSigninHelper::SyncSetupCompletedCallback( |
1650 OneClickSigninSyncStarter::SyncSetupResult result) { | 1586 OneClickSigninSyncStarter::SyncSetupResult result) { |
1651 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && | 1587 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE && |
1652 web_contents()) { | 1588 web_contents()) { |
1653 GURL current_url = web_contents()->GetVisibleURL(); | 1589 GURL current_url = web_contents()->GetVisibleURL(); |
1654 | 1590 |
1655 // 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, |
1656 // redirect to the NTP or apps page. | 1592 // redirect to the NTP or apps page. |
1657 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1593 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
1658 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1594 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
1659 RedirectToNtpOrAppsPage( | 1595 RedirectToNtpOrAppsPage( |
1660 web_contents(), | 1596 web_contents(), |
1661 signin::GetSourceForPromoURL(original_continue_url_)); | 1597 signin::GetSourceForPromoURL(original_continue_url_)); |
1662 } | 1598 } |
1663 } | 1599 } |
1664 } | 1600 } |
OLD | NEW |