NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / inline_login_handler_chromeos.cc
blob2c61cd171ca1de2436cda2aff54d438a44804128
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h"
7 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/profile_oauth2_token_service.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager.h"
12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "content/public/browser/web_ui.h"
15 namespace chromeos {
17 class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate
18 : public OAuth2TokenFetcher::Delegate {
19 public:
20 explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui)
21 : web_ui_(web_ui) {}
22 virtual ~InlineLoginUIOAuth2Delegate() {}
24 // OAuth2TokenFetcher::Delegate overrides:
25 virtual void OnOAuth2TokensAvailable(
26 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE {
27 // Closes sign-in dialog before update token service. Token service update
28 // might trigger a permission dialog and if this dialog does not close,
29 // a DCHECK would be triggered because attempting to activate a window
30 // while there is a modal dialog.
31 web_ui_->CallJavascriptFunction("inline.login.closeDialog");
33 Profile* profile = Profile::FromWebUI(web_ui_);
34 ProfileOAuth2TokenService* token_service =
35 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
36 SigninManagerBase* signin_manager =
37 SigninManagerFactory::GetForProfile(profile);
38 token_service->UpdateCredentials(
39 signin_manager->GetAuthenticatedAccountId(),
40 oauth2_tokens.refresh_token);
43 virtual void OnOAuth2TokensFetchFailed() OVERRIDE {
44 LOG(ERROR) << "Failed to fetch oauth2 token with inline login.";
45 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure");
48 private:
49 content::WebUI* web_ui_;
52 InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {}
54 InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {}
56 void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) {
57 Profile* profile = Profile::FromWebUI(web_ui());
59 oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui()));
60 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
61 oauth2_delegate_.get(), profile->GetRequestContext()));
62 oauth2_token_fetcher_->StartExchangeFromCookies();
65 } // namespace chromeos