Index: chrome/browser/ui/sync/one_click_signin_helper.cc |
diff --git a/chrome/browser/ui/sync/one_click_signin_helper.cc b/chrome/browser/ui/sync/one_click_signin_helper.cc |
index 3a26ed453be5377bf36ddefbf907da60b1f4cd49..6e3259ce453e7919666b97208c803817b57a3528 100644 |
--- a/chrome/browser/ui/sync/one_click_signin_helper.cc |
+++ b/chrome/browser/ui/sync/one_click_signin_helper.cc |
@@ -52,6 +52,7 @@ |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/chrome_pages.h" |
#include "chrome/browser/ui/sync/one_click_signin_histogram.h" |
+#include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
#include "chrome/browser/ui/sync/signin_histogram.h" |
#include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
@@ -252,7 +253,7 @@ void StartSync(const OneClickSigninHelper::StartSyncArgs& args, |
return; |
} |
- // The wrapper deletes itself once its done. |
+ // The wrapper deletes itself once it's done. |
OneClickSigninHelper::SyncStarterWrapper* wrapper = |
new OneClickSigninHelper::SyncStarterWrapper(args, start_mode); |
wrapper->Start(); |
@@ -330,10 +331,10 @@ void ClearPendingEmailOnIOThread(content::ResourceContext* context) { |
io_data->set_reverse_autologin_pending_email(std::string()); |
} |
-// Determines the source of the sign in and the continue URL. Its either one |
-// of the known sign in access point (first run, NTP, Apps page, menu, settings) |
-// or its an implicit sign in via another Google property. In the former case, |
-// "service" is also checked to make sure its "chromiumsync". |
+// Determines the source of the sign in and the continue URL. It's either one |
+// of the known sign in access points (first run, NTP, Apps page, menu, or |
+// settings) or its an implicit sign in via another Google property. In the |
+// former case, "service" is also checked to make sure its "chromiumsync". |
signin::Source GetSigninSource(const GURL& url, GURL* continue_url) { |
DCHECK(url.is_valid()); |
std::string value; |
@@ -482,20 +483,6 @@ void CurrentHistoryCleaner::WebContentsDestroyed( |
delete this; // Failure. |
} |
-void CloseTab(content::WebContents* tab) { |
- Browser* browser = chrome::FindBrowserWithWebContents(tab); |
- if (browser) { |
- TabStripModel* tab_strip_model = browser->tab_strip_model(); |
- if (tab_strip_model) { |
- int index = tab_strip_model->GetIndexOfWebContents(tab); |
- if (index != TabStripModel::kNoTab) { |
- tab_strip_model->ExecuteContextMenuCommand( |
- index, TabStripModel::CommandCloseTab); |
- } |
- } |
- } |
-} |
- |
} // namespace |
@@ -669,12 +656,13 @@ void |
OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( |
const std::string& email, |
const std::string& refresh_token) { |
- // The starter deletes itself once its done. |
+ // The starter deletes itself once it's done. |
new OneClickSigninSyncStarter(args_.profile, args_.browser, |
email, args_.password, |
refresh_token, start_mode_, |
args_.web_contents, |
args_.confirmation_required, |
+ GURL(), |
args_.callback); |
} |
@@ -706,11 +694,7 @@ OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents, |
} |
} |
-OneClickSigninHelper::~OneClickSigninHelper() { |
- // WebContentsDestroyed() should always be called before the object is |
- // deleted. |
- DCHECK(!web_contents()); |
-} |
+OneClickSigninHelper::~OneClickSigninHelper() {} |
// static |
void OneClickSigninHelper::LogHistogramValue( |
@@ -1254,6 +1238,7 @@ void OneClickSigninHelper::CleanTransientState() { |
continue_url_ = GURL(); |
untrusted_navigations_since_signin_visit_ = 0; |
untrusted_confirmation_required_ = false; |
+ original_continue_url_ = GURL(); |
error_message_.clear(); |
// Post to IO thread to clear pending email. |
@@ -1570,10 +1555,8 @@ void OneClickSigninHelper::DidStopLoading( |
if (original_source == signin::SOURCE_SETTINGS || |
(original_source == signin::SOURCE_WEBSTORE_INSTALL && |
source_ == signin::SOURCE_SETTINGS)) { |
- ProfileSyncService* sync_service = |
- ProfileSyncServiceFactory::GetForProfile(profile); |
- if (sync_service) |
- sync_service->AddObserver(this); |
+ // The observer deletes itself once it's done. |
+ new OneClickSigninSyncObserver(contents, original_continue_url_); |
} |
break; |
} |
@@ -1589,60 +1572,6 @@ void OneClickSigninHelper::DidStopLoading( |
CleanTransientState(); |
} |
-// It is guaranteed that this method is called before the object is deleted. |
-void OneClickSigninHelper::WebContentsDestroyed( |
- content::WebContents* contents) { |
- Profile* profile = |
- Profile::FromBrowserContext(contents->GetBrowserContext()); |
- ProfileSyncService* sync_service = |
- ProfileSyncServiceFactory::GetForProfile(profile); |
- if (sync_service) |
- sync_service->RemoveObserver(this); |
-} |
- |
-void OneClickSigninHelper::OnStateChanged() { |
- // We only add observer for ProfileSyncService when original_continue_url_ is |
- // not empty. |
- DCHECK(!original_continue_url_.is_empty()); |
- |
- content::WebContents* contents = web_contents(); |
- Profile* profile = |
- Profile::FromBrowserContext(contents->GetBrowserContext()); |
- ProfileSyncService* sync_service = |
- ProfileSyncServiceFactory::GetForProfile(profile); |
- |
- // At this point, the sign in process is complete, and control has been handed |
- // back to the sync engine. Close the gaia sign in tab if |
- // |original_continue_url_| contains the |auto_close| parameter. Otherwise, |
- // wait for sync setup to complete and then navigate to |
- // |original_continue_url_|. |
- if (signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
- // Close the gaia sign in tab via a task to make sure we aren't in the |
- // middle of any webui handler code. |
- base::MessageLoop::current()->PostTask( |
- FROM_HERE, |
- base::Bind(&CloseTab, base::Unretained(contents))); |
- } else { |
- // Sync setup not completed yet. |
- if (sync_service->FirstSetupInProgress()) |
- return; |
- |
- if (sync_service->sync_initialized() && |
- signin::GetSourceForPromoURL(original_continue_url_) |
- != signin::SOURCE_SETTINGS) { |
- contents->GetController().LoadURL(original_continue_url_, |
- content::Referrer(), |
- content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
- std::string()); |
- } |
- } |
- |
- // Clears |original_continue_url_| here instead of in CleanTransientState, |
- // because it is used in OnStateChanged which occurs later. |
- original_continue_url_ = GURL(); |
- sync_service->RemoveObserver(this); |
-} |
- |
OneClickSigninSyncStarter::Callback |
OneClickSigninHelper::CreateSyncStarterCallback() { |
// The callback will only be invoked if this object is still alive when sync |