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 6fc6ede98058c237519597fc2989e6126cc3b1cd..8f4c8e92311d6ef9c603de0ec2ea639d26fe1859 100644 |
--- a/chrome/browser/ui/sync/one_click_signin_helper.cc |
+++ b/chrome/browser/ui/sync/one_click_signin_helper.cc |
@@ -49,6 +49,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" |
@@ -483,12 +484,6 @@ void CurrentHistoryCleaner::WebContentsDestroyed( |
delete this; // Failure. |
} |
-void CloseTab(content::WebContents* tab) { |
- content::WebContentsDelegate* tab_delegate = tab->GetDelegate(); |
- if (tab_delegate) |
- tab_delegate->CloseContents(tab); |
-} |
- |
} // namespace |
@@ -668,6 +663,7 @@ OneClickSigninHelper::SyncStarterWrapper::StartOneClickSigninSyncStarter( |
refresh_token, start_mode_, |
args_.web_contents, |
args_.confirmation_required, |
+ GURL(), |
args_.callback); |
} |
@@ -699,11 +695,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( |
@@ -1247,6 +1239,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. |
@@ -1563,10 +1556,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_); |
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
|
} |
break; |
} |
@@ -1582,60 +1573,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 |