Commit b7ac0d80 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Don't use Mojo to get access tokens in identity_get_auth_token_function.cc

identity_get_auth_token_function.cc uses a mix of C++ and Mojo code.
This CL ports GetAccessToken() to C++.

Bug: 913853
Change-Id: I71ffbc6944dff0a886d57a4d8b10cb0fa334390b
Reviewed-on: https://chromium-review.googlesource.com/c/1458300
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635492}
parent 2b46b38f
...@@ -710,6 +710,7 @@ void IdentityGetAuthTokenFunction::OnGetTokenFailure( ...@@ -710,6 +710,7 @@ void IdentityGetAuthTokenFunction::OnGetTokenFailure(
device_access_token_request_.reset(); device_access_token_request_.reset();
OnGetAccessTokenComplete(base::nullopt, base::Time(), error); OnGetAccessTokenComplete(base::nullopt, base::Time(), error);
} }
#endif
void IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted( void IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted(
GoogleServiceAuthError error, GoogleServiceAuthError error,
...@@ -723,7 +724,6 @@ void IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted( ...@@ -723,7 +724,6 @@ void IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted(
OnGetAccessTokenComplete(base::nullopt, base::Time(), error); OnGetAccessTokenComplete(base::nullopt, base::Time(), error);
} }
} }
#endif
void IdentityGetAuthTokenFunction::OnIdentityAPIShutdown() { void IdentityGetAuthTokenFunction::OnIdentityAPIShutdown() {
gaia_web_auth_flow_.reset(); gaia_web_auth_flow_.reset();
...@@ -766,6 +766,7 @@ bool IdentityGetAuthTokenFunction::IsOriginWhitelistedInPublicSession() { ...@@ -766,6 +766,7 @@ bool IdentityGetAuthTokenFunction::IsOriginWhitelistedInPublicSession() {
#endif #endif
void IdentityGetAuthTokenFunction::StartTokenKeyAccountAccessTokenRequest() { void IdentityGetAuthTokenFunction::StartTokenKeyAccountAccessTokenRequest() {
auto* identity_manager = IdentityManagerFactory::GetForProfile(GetProfile());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (chrome::IsRunningInForcedAppMode()) { if (chrome::IsRunningInForcedAppMode()) {
std::string app_client_id; std::string app_client_id;
...@@ -774,25 +775,27 @@ void IdentityGetAuthTokenFunction::StartTokenKeyAccountAccessTokenRequest() { ...@@ -774,25 +775,27 @@ void IdentityGetAuthTokenFunction::StartTokenKeyAccountAccessTokenRequest() {
GetAppModeChromeClientOAuthInfo(&app_client_id, GetAppModeChromeClientOAuthInfo(&app_client_id,
&app_client_secret)) { &app_client_secret)) {
token_key_account_access_token_fetcher_ = token_key_account_access_token_fetcher_ =
IdentityManagerFactory::GetForProfile(GetProfile()) identity_manager->CreateAccessTokenFetcherForClient(
->CreateAccessTokenFetcherForClient( token_key_.account_id, app_client_id, app_client_secret,
token_key_.account_id, app_client_id, app_client_secret, kExtensionsIdentityAPIOAuthConsumerName,
kExtensionsIdentityAPIOAuthConsumerName, OAuth2TokenService::ScopeSet(),
OAuth2TokenService::ScopeSet(), base::BindOnce(
base::BindOnce(&IdentityGetAuthTokenFunction:: &IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted,
OnAccessTokenFetchCompleted, base::Unretained(this)),
base::Unretained(this)), identity::AccessTokenFetcher::Mode::kImmediate);
identity::AccessTokenFetcher::Mode::kImmediate);
return; return;
} }
} }
#endif #endif
GetMojoIdentityManager()->GetAccessToken( token_key_account_access_token_fetcher_ =
token_key_.account_id, ::identity::ScopeSet(), identity_manager->CreateAccessTokenFetcherForAccount(
kExtensionsIdentityAPIOAuthConsumerName, token_key_.account_id, kExtensionsIdentityAPIOAuthConsumerName,
base::BindOnce(&IdentityGetAuthTokenFunction::OnGetAccessTokenComplete, ::identity::ScopeSet(),
base::Unretained(this))); base::BindOnce(
&IdentityGetAuthTokenFunction::OnAccessTokenFetchCompleted,
base::Unretained(this)),
identity::AccessTokenFetcher::Mode::kImmediate);
} }
void IdentityGetAuthTokenFunction::StartGaiaRequest( void IdentityGetAuthTokenFunction::StartGaiaRequest(
......
...@@ -89,12 +89,12 @@ class IdentityGetAuthTokenFunction : public ChromeAsyncExtensionFunction, ...@@ -89,12 +89,12 @@ class IdentityGetAuthTokenFunction : public ChromeAsyncExtensionFunction,
const OAuth2AccessTokenConsumer::TokenResponse& token_response) override; const OAuth2AccessTokenConsumer::TokenResponse& token_response) override;
void OnGetTokenFailure(const OAuth2TokenService::Request* request, void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override; const GoogleServiceAuthError& error) override;
#endif
void OnAccessTokenFetchCompleted(GoogleServiceAuthError error, void OnAccessTokenFetchCompleted(GoogleServiceAuthError error,
identity::AccessTokenInfo access_token_info); identity::AccessTokenInfo access_token_info);
#endif
// Invoked on completion of IdentityManager::GetAccessToken(). // Invoked on completion of the access token fetcher.
// Exposed for testing. // Exposed for testing.
void OnGetAccessTokenComplete(const base::Optional<std::string>& access_token, void OnGetAccessTokenComplete(const base::Optional<std::string>& access_token,
base::Time expiration_time, base::Time expiration_time,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment