Commit e54e5b9a authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

Move ActiveAccountAccessTokenFetcherImpl out of IdentityProvider

IdentityProvider currently has baked-in knowledge of OAuth2TokenService
for functionality that is shared between ProfileIdentityProvider and
DeviceIdentityProvider. However, as we will be converting
ProfileIdentityProvider to talk to IdentityManager rather than
OAuth2TokenService, this baked-in knowledge needs to be moved out of
IdentityProvider; ultimately, it will end up only in
DeviceIdentityProvider.

This CL takes the first step along that path by moving
ActiveAccountAccessTokenFetcherImpl, which fetches access tokens via
OAuth2TokenService, out of identity_provider.cc into its own file. The
next CL will have ProfileIdentityProvider and DeviceIdentityProvider
each implement FetchAccessToken() rather than having IdentityProvider do
so directly.

Bug: 809452
Change-Id: I664c4da998cf90d0a398dc2c9e309425f95515a3
Reviewed-on: https://chromium-review.googlesource.com/1114604Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571070}
parent 7e659c27
......@@ -8,6 +8,8 @@ static_library("public") {
"ack_handle.h",
"ack_handler.cc",
"ack_handler.h",
"active_account_access_token_fetcher_impl.cc",
"active_account_access_token_fetcher_impl.h",
"identity_provider.cc",
"identity_provider.h",
"invalidation.cc",
......
// Copyright 2018 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 "components/invalidation/public/active_account_access_token_fetcher_impl.h"
namespace invalidation {
ActiveAccountAccessTokenFetcherImpl::ActiveAccountAccessTokenFetcherImpl(
const std::string& active_account_id,
const std::string& oauth_consumer_name,
OAuth2TokenService* token_service,
const OAuth2TokenService::ScopeSet& scopes,
ActiveAccountAccessTokenCallback callback)
: OAuth2TokenService::Consumer(oauth_consumer_name),
callback_(std::move(callback)) {
access_token_request_ =
token_service->StartRequest(active_account_id, scopes, this);
}
ActiveAccountAccessTokenFetcherImpl::~ActiveAccountAccessTokenFetcherImpl() {}
void ActiveAccountAccessTokenFetcherImpl::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) {
HandleTokenRequestCompletion(request, GoogleServiceAuthError::AuthErrorNone(),
access_token);
}
void ActiveAccountAccessTokenFetcherImpl::OnGetTokenFailure(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) {
HandleTokenRequestCompletion(request, error, std::string());
}
void ActiveAccountAccessTokenFetcherImpl::HandleTokenRequestCompletion(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error,
const std::string& access_token) {
DCHECK_EQ(request, access_token_request_.get());
std::unique_ptr<OAuth2TokenService::Request> request_deleter(
std::move(access_token_request_));
std::move(callback_).Run(error, access_token);
}
} // namespace invalidation
// Copyright 2018 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.
#ifndef COMPONENTS_INVALIDATION_PUBLIC_ACTIVE_ACCOUNT_ACCESS_TOKEN_FETCHER_IMPL_H_
#define COMPONENTS_INVALIDATION_PUBLIC_ACTIVE_ACCOUNT_ACCESS_TOKEN_FETCHER_IMPL_H_
#include <string>
#include "base/macros.h"
#include "base/time/time.h"
#include "components/invalidation/public/identity_provider.h"
#include "google_apis/gaia/oauth2_token_service.h"
namespace invalidation {
// An implementation of ActiveAccountAccessTokenFetcher that is backed by
// OAuth2TokenService.
// TODO(809452): Once ProfileIdentityProvider is converted to talk to
// IdentityManager, this helper class should either be hidden inside
// DeviceIdentityProvider or moved to live next to it.
class ActiveAccountAccessTokenFetcherImpl
: public ActiveAccountAccessTokenFetcher,
OAuth2TokenService::Consumer {
public:
ActiveAccountAccessTokenFetcherImpl(
const std::string& active_account_id,
const std::string& oauth_consumer_name,
OAuth2TokenService* token_service,
const OAuth2TokenService::ScopeSet& scopes,
ActiveAccountAccessTokenCallback callback);
~ActiveAccountAccessTokenFetcherImpl() override;
private:
// OAuth2TokenService::Consumer implementation.
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) override;
void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override;
// Invokes |callback_| with (|access_token|, |error|).
void HandleTokenRequestCompletion(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error,
const std::string& access_token);
ActiveAccountAccessTokenCallback callback_;
std::unique_ptr<OAuth2TokenService::Request> access_token_request_;
DISALLOW_COPY_AND_ASSIGN(ActiveAccountAccessTokenFetcherImpl);
};
} // namespace invalidation
#endif // COMPONENTS_INVALIDATION_PUBLIC_ACTIVE_ACCOUNT_ACCESS_TOKEN_FETCHER_IMPL_H_
......@@ -4,75 +4,9 @@
#include "components/invalidation/public/identity_provider.h"
namespace invalidation {
class ActiveAccountAccessTokenFetcherImpl
: public ActiveAccountAccessTokenFetcher,
OAuth2TokenService::Consumer {
public:
ActiveAccountAccessTokenFetcherImpl(
const std::string& active_account_id,
const std::string& oauth_consumer_name,
OAuth2TokenService* token_service,
const OAuth2TokenService::ScopeSet& scopes,
ActiveAccountAccessTokenCallback callback);
~ActiveAccountAccessTokenFetcherImpl() override = default;
private:
// OAuth2TokenService::Consumer implementation.
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) override;
void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override;
// Invokes |callback_| with (|access_token|, |error|).
void HandleTokenRequestCompletion(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error,
const std::string& access_token);
ActiveAccountAccessTokenCallback callback_;
std::unique_ptr<OAuth2TokenService::Request> access_token_request_;
DISALLOW_COPY_AND_ASSIGN(ActiveAccountAccessTokenFetcherImpl);
};
ActiveAccountAccessTokenFetcherImpl::ActiveAccountAccessTokenFetcherImpl(
const std::string& active_account_id,
const std::string& oauth_consumer_name,
OAuth2TokenService* token_service,
const OAuth2TokenService::ScopeSet& scopes,
ActiveAccountAccessTokenCallback callback)
: OAuth2TokenService::Consumer(oauth_consumer_name),
callback_(std::move(callback)) {
access_token_request_ =
token_service->StartRequest(active_account_id, scopes, this);
}
void ActiveAccountAccessTokenFetcherImpl::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) {
HandleTokenRequestCompletion(request, GoogleServiceAuthError::AuthErrorNone(),
access_token);
}
#include "components/invalidation/public/active_account_access_token_fetcher_impl.h"
void ActiveAccountAccessTokenFetcherImpl::OnGetTokenFailure(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) {
HandleTokenRequestCompletion(request, error, std::string());
}
void ActiveAccountAccessTokenFetcherImpl::HandleTokenRequestCompletion(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error,
const std::string& access_token) {
DCHECK_EQ(request, access_token_request_.get());
std::unique_ptr<OAuth2TokenService::Request> request_deleter(
std::move(access_token_request_));
std::move(callback_).Run(error, access_token);
}
namespace invalidation {
IdentityProvider::Observer::~Observer() {}
......
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