Chromium Code Reviews| Index: chrome/browser/extensions/api/identity/identity_signin_flow.cc |
| diff --git a/chrome/browser/extensions/api/identity/identity_signin_flow.cc b/chrome/browser/extensions/api/identity/identity_signin_flow.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..56b7584cfc378e96ccadbf6bc36084812268ef59 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/identity/identity_signin_flow.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/identity/identity_signin_flow.h" |
|
Pete Williamson
2013/03/27 18:03:55
Should there be a unit test for this file?
Michael Courage
2013/03/27 18:40:11
Pretty much everything in this file would have to
|
| + |
| +#include "chrome/browser/signin/token_service.h" |
| +#include "chrome/browser/signin/token_service_factory.h" |
| +#include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| +#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "google_apis/gaia/gaia_constants.h" |
| + |
| +namespace extensions { |
| + |
| +IdentitySigninFlow::IdentitySigninFlow(Delegate* delegate, Profile* profile) |
| + : delegate_(delegate), |
| + profile_(profile) { |
| +} |
| + |
| +IdentitySigninFlow::~IdentitySigninFlow() { |
| + delegate_ = NULL; |
| +} |
| + |
| +void IdentitySigninFlow::Start() { |
| +#if !defined(OS_CHROMEOS) |
| + TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| + content::Source<TokenService>(token_service)); |
| + |
| + signin_tracker_.reset(new SigninTracker(profile_, this)); |
| + |
| + LoginUIService* login_ui_service = |
| + LoginUIServiceFactory::GetForProfile(profile_); |
| + login_ui_service->ShowLoginPopup(); |
| +#else |
| + // On Chrome OS, the user has to log out to re-establish credentials. Let the |
| + // global error popup handle everything. |
| + delegate_->SigninFailed(); |
| + delegate_ = NULL; |
| +#endif |
| +} |
| + |
| +void IdentitySigninFlow::SigninFailed(const GoogleServiceAuthError& error) { |
| + if (delegate_) { |
| + delegate_->SigninFailed(); |
| + delegate_ = NULL; |
| + } |
|
Pete Williamson
2013/03/27 18:03:55
This implies to me that the signin flow object sho
Michael Courage
2013/03/27 18:40:11
Done.
|
| +} |
| + |
| +void IdentitySigninFlow::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| + TokenService::TokenAvailableDetails* token_details = |
| + content::Details<TokenService::TokenAvailableDetails>(details).ptr(); |
| + if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken) |
| + ReportSigninSuccess(token_details->token()); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void IdentitySigninFlow::ReportSigninSuccess(const std::string& token) { |
| + if (delegate_) { |
| + delegate_->SigninSuccess(token); |
| + delegate_ = NULL; |
| + } |
| +} |
| + |
| +} // namespace extensions |