Chromium Code Reviews| Index: chrome/browser/ui/auto_login_info_bar_delegate.cc |
| diff --git a/chrome/browser/ui/auto_login_info_bar_delegate.cc b/chrome/browser/ui/auto_login_info_bar_delegate.cc |
| index c862ee37435b8a312f4650627fcb8a39bf3c42bb..864d4afbe3f7bdb0639413d0a9e26e9036ff7304 100644 |
| --- a/chrome/browser/ui/auto_login_info_bar_delegate.cc |
| +++ b/chrome/browser/ui/auto_login_info_bar_delegate.cc |
| @@ -4,12 +4,15 @@ |
| #include "chrome/browser/ui/auto_login_info_bar_delegate.h" |
| +#include "base/bind.h" |
| #include "base/logging.h" |
| +#include "base/message_loop.h" |
| #include "base/metrics/histogram.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/infobars/infobar_tab_helper.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| -#include "chrome/browser/signin/token_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/signin/ubertoken_fetcher.h" |
| #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -51,18 +54,20 @@ enum { |
| // auto-login. It holds context information needed while re-issuing service |
| // tokens using the TokenService, gets the browser cookies with the TokenAuth |
| // API, and finally redirects the user to the correct page. |
| -class AutoLoginRedirector : public content::NotificationObserver { |
| +class AutoLoginRedirector : public UbertokenConsumer { |
| public: |
| - AutoLoginRedirector(TokenService* token_service, |
| - NavigationController* navigation_controller, |
| + AutoLoginRedirector(NavigationController* navigation_controller, |
| const std::string& args); |
| virtual ~AutoLoginRedirector(); |
| + static void Delete(AutoLoginRedirector* redirector) { |
| + delete redirector; |
| + } |
| + |
| private: |
| - // content::NotificationObserver override. |
| - virtual void Observe(int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) OVERRIDE; |
| + // Overriden from UbertokenConsumer: |
| + virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE; |
| + virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| // Redirect tab to MergeSession URL, logging the user in and navigating |
| // to the desired page. |
| @@ -70,56 +75,38 @@ class AutoLoginRedirector : public content::NotificationObserver { |
| NavigationController* navigation_controller_; |
| const std::string args_; |
| - content::NotificationRegistrar registrar_; |
| + scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; |
| DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector); |
| }; |
| AutoLoginRedirector::AutoLoginRedirector( |
| - TokenService* token_service, |
| NavigationController* navigation_controller, |
| const std::string& args) |
| : navigation_controller_(navigation_controller), |
| args_(args) { |
| - // Register to receive notification for new tokens and then force the tokens |
| - // to be re-issued. The token service guarantees to fire either |
| - // TOKEN_AVAILABLE or TOKEN_REQUEST_FAILED, so we will get at least one or |
| - // the other, allow AutoLoginRedirector to delete itself correctly. |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| - content::Source<TokenService>(token_service)); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| - content::Source<TokenService>(token_service)); |
| - token_service->StartFetchingTokens(); |
| + ubertoken_fetcher_.reset(new UbertokenFetcher( |
| + static_cast<Profile*>(navigation_controller_->GetBrowserContext()), |
|
sky
2012/01/31 16:54:41
Profile::FromBrowserContext. That said, it's prefe
qsr
2012/02/01 14:59:18
We need the navigation_controller_ anyway. I can a
|
| + this)); |
| + ubertoken_fetcher_->StartFetchingToken(); |
| } |
| AutoLoginRedirector::~AutoLoginRedirector() { |
| } |
| -void AutoLoginRedirector::Observe(int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE || |
| - type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED); |
| - |
| - // We are only interested in GAIA tokens. |
| - if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| - TokenService::TokenAvailableDetails* tok_details = |
| - content::Details<TokenService::TokenAvailableDetails>(details).ptr(); |
| - if (tok_details->service() == GaiaConstants::kGaiaService) { |
| - RedirectToMergeSession(tok_details->token()); |
| - delete this; |
| - } |
| - } else { |
| - TokenService::TokenRequestFailedDetails* tok_details = |
| - content::Details<TokenService::TokenRequestFailedDetails>(details). |
| - ptr(); |
| - if (tok_details->service() == GaiaConstants::kGaiaService) { |
| - LOG(WARNING) << "AutoLoginRedirector: token request failed"; |
| - delete this; |
| - } |
| - } |
| +void AutoLoginRedirector::OnUbertokenSuccess(const std::string& token) { |
| + RedirectToMergeSession(token); |
| + MessageLoop::current()->PostTask(FROM_HERE, |
| + base::Bind(&AutoLoginRedirector::Delete, |
| + this)); |
|
Roger Tawa OOO till Jul 10th
2012/01/31 21:38:23
'this' should be aligned under &. same below.
qsr
2012/02/01 14:59:18
Not relevant anymore.
|
| +} |
| + |
| +void AutoLoginRedirector::OnUbertokenFailure( |
| + const GoogleServiceAuthError& error) { |
| + LOG(WARNING) << "AutoLoginRedirector: token request failed"; |
| + MessageLoop::current()->PostTask(FROM_HERE, |
|
sky
2012/01/31 16:54:41
Is there a reason you're not using DeleteSoon on t
qsr
2012/02/01 14:59:18
The usual one -> ignorance. Done.
|
| + base::Bind(&AutoLoginRedirector::Delete, |
| + this)); |
| } |
| void AutoLoginRedirector::RedirectToMergeSession(const std::string& token) { |
| @@ -184,7 +171,7 @@ string16 AutoLoginInfoBarDelegate::GetButtonLabel( |
| bool AutoLoginInfoBarDelegate::Accept() { |
| // AutoLoginRedirector deletes itself. |
| - new AutoLoginRedirector(token_service_, navigation_controller_, args_); |
| + new AutoLoginRedirector(navigation_controller_, args_); |
|
Roger Tawa OOO till Jul 10th
2012/01/31 21:38:23
the token_service_ member does not look likes its
qsr
2012/02/01 14:59:18
Not relevant anymore after your change.
|
| RecordHistogramAction(HISTOGRAM_ACCEPTED); |
| button_pressed_ = true; |
| return true; |