This source file includes following definitions.
- InlineLoginUIOAuth2Delegate
- InlineLoginUIOAuth2Delegate
- OnOAuth2TokensAvailable
- OnOAuth2TokensFetchFailed
- CompleteLogin
#include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h"
#include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/web_ui.h"
namespace chromeos {
class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate
: public OAuth2TokenFetcher::Delegate {
public:
explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui)
: web_ui_(web_ui) {}
virtual ~InlineLoginUIOAuth2Delegate() {}
virtual void OnOAuth2TokensAvailable(
const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
web_ui_->CallJavascriptFunction("inline.login.closeDialog");
Profile* profile = Profile::FromWebUI(web_ui_);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
token_service->UpdateCredentials(
signin_manager->GetAuthenticatedAccountId(),
oauth2_tokens.refresh_token);
}
virtual void OnOAuth2TokensFetchFailed() OVERRIDE {
LOG(ERROR) << "Failed to fetch oauth2 token with inline login.";
web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure");
}
private:
content::WebUI* web_ui_;
};
InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {}
InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {}
void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui()));
oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
oauth2_delegate_.get(), profile->GetRequestContext()));
oauth2_token_fetcher_->StartExchangeFromCookies();
}
}