1 // Copyright 2014 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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "google_apis/gaia/gaia_auth_consumer.h" 12 #include "google_apis/gaia/gaia_auth_fetcher.h" 13 14 // Retrieves the OAuth2 information from an already signed in cookie jar. 15 // The information retrieved is: username, refresh token. 16 class SigninOAuthHelper : public GaiaAuthConsumer { 17 public: 18 // Implemented by users of SigninOAuthHelper to know then helper is finished. 19 class Consumer { 20 public: 21 virtual ~Consumer() {} 22 23 // Called when all the information is retrieved successfully. |email| 24 // and |display_email| correspond to the gaia properties called "email" 25 // and "displayEmail" associated with the signed in account. |refresh_token| 26 // is the account's login-scoped oauth2 refresh token. 27 virtual void OnSigninOAuthInformationAvailable( 28 const std::string& email, 29 const std::string& display_email, 30 const std::string& refresh_token) {} 31 32 // Called when an error occurs while getting the information. 33 virtual void OnSigninOAuthInformationFailure( 34 const GoogleServiceAuthError& error) {} 35 }; 36 37 explicit SigninOAuthHelper(net::URLRequestContextGetter* getter, 38 const std::string& session_index, 39 const std::string& signin_scoped_device_id, 40 Consumer* consumer); 41 virtual ~SigninOAuthHelper(); 42 43 private: 44 // Overridden from GaiaAuthConsumer. 45 virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; 46 virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error) 47 OVERRIDE; 48 virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; 49 virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) 50 OVERRIDE; 51 virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; 52 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) 53 OVERRIDE; 54 55 GaiaAuthFetcher gaia_auth_fetcher_; 56 std::string refresh_token_; 57 Consumer* consumer_; 58 59 DISALLOW_COPY_AND_ASSIGN(SigninOAuthHelper); 60 }; 61 62 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 63