| Index: chrome/browser/ui/webui/chromeos/login/inline_login_handler_cros_impl.cc
|
| diff --git a/chrome/browser/ui/webui/chromeos/login/inline_login_handler_cros_impl.cc b/chrome/browser/ui/webui/chromeos/login/inline_login_handler_cros_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c6f5c9c50968ad590ee01818a4760e8701fca3bb
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/webui/chromeos/login/inline_login_handler_cros_impl.cc
|
| @@ -0,0 +1,60 @@
|
| +// 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/ui/webui/chromeos/login/inline_login_handler_cros_impl.h"
|
| +
|
| +#include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/signin/profile_oauth2_token_service.h"
|
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| +#include "content/public/browser/web_ui.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +class InlineLoginHandlerCrosImpl::InlineLoginUIOAuth2Delegate
|
| + : public OAuth2TokenFetcher::Delegate {
|
| + public:
|
| + explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui)
|
| + : web_ui_(web_ui) {}
|
| + virtual ~InlineLoginUIOAuth2Delegate() {}
|
| +
|
| + // OAuth2TokenFetcher::Delegate overrides:
|
| + virtual void OnOAuth2TokensAvailable(
|
| + const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
|
| + // Closes sign-in dialog before update token service. Token service update
|
| + // might trigger a permission dialog and if this dialog does not close,
|
| + // a DCHECK would be triggered because attempting to activate a window
|
| + // while there is a modal dialog.
|
| + web_ui_->CallJavascriptFunction("inline.login.closeDialog");
|
| +
|
| + Profile* profile = Profile::FromWebUI(web_ui_);
|
| + ProfileOAuth2TokenService* token_service =
|
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
|
| + token_service->UpdateCredentials(token_service->GetPrimaryAccountId(),
|
| + 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_;
|
| +};
|
| +
|
| +InlineLoginHandlerCrosImpl::InlineLoginHandlerCrosImpl() {}
|
| +
|
| +InlineLoginHandlerCrosImpl::~InlineLoginHandlerCrosImpl() {}
|
| +
|
| +void InlineLoginHandlerCrosImpl::CompleteLogin(const base::ListValue* args) {
|
| + DCHECK(email_.empty() && password_.empty());
|
| +
|
| + oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui()));
|
| + oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
|
| + oauth2_delegate_.get(), profile_->GetRequestContext()));
|
| + oauth2_token_fetcher_->StartExchangeFromCookies();
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|