OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h
" |
| 6 |
| 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 "content/public/browser/web_ui.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 class InlineLoginHandlerChromeOS::InlineLoginUIOAuth2Delegate |
| 16 : public OAuth2TokenFetcher::Delegate { |
| 17 public: |
| 18 explicit InlineLoginUIOAuth2Delegate(content::WebUI* web_ui) |
| 19 : web_ui_(web_ui) {} |
| 20 virtual ~InlineLoginUIOAuth2Delegate() {} |
| 21 |
| 22 // OAuth2TokenFetcher::Delegate overrides: |
| 23 virtual void OnOAuth2TokensAvailable( |
| 24 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE { |
| 25 // Closes sign-in dialog before update token service. Token service update |
| 26 // might trigger a permission dialog and if this dialog does not close, |
| 27 // a DCHECK would be triggered because attempting to activate a window |
| 28 // while there is a modal dialog. |
| 29 web_ui_->CallJavascriptFunction("inline.login.closeDialog"); |
| 30 |
| 31 Profile* profile = Profile::FromWebUI(web_ui_); |
| 32 ProfileOAuth2TokenService* token_service = |
| 33 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 34 token_service->UpdateCredentials(token_service->GetPrimaryAccountId(), |
| 35 oauth2_tokens.refresh_token); |
| 36 } |
| 37 |
| 38 virtual void OnOAuth2TokensFetchFailed() OVERRIDE { |
| 39 LOG(ERROR) << "Failed to fetch oauth2 token with inline login."; |
| 40 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure"); |
| 41 } |
| 42 |
| 43 private: |
| 44 content::WebUI* web_ui_; |
| 45 }; |
| 46 |
| 47 InlineLoginHandlerChromeOS::InlineLoginHandlerChromeOS() {} |
| 48 |
| 49 InlineLoginHandlerChromeOS::~InlineLoginHandlerChromeOS() {} |
| 50 |
| 51 void InlineLoginHandlerChromeOS::CompleteLogin(const base::ListValue* args) { |
| 52 Profile* profile = Profile::FromWebUI(web_ui()); |
| 53 |
| 54 oauth2_delegate_.reset(new InlineLoginUIOAuth2Delegate(web_ui())); |
| 55 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher( |
| 56 oauth2_delegate_.get(), profile->GetRequestContext())); |
| 57 oauth2_token_fetcher_->StartExchangeFromCookies(); |
| 58 } |
| 59 |
| 60 } // namespace chromeos |
OLD | NEW |