blob: 863ea1478e294856019233bf3e709b43941b0519 [file] [log] [blame]
// Copyright 2014 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_IMPL_PROFILE_IDENTITY_PROVIDER_H_
#define COMPONENTS_INVALIDATION_IMPL_PROFILE_IDENTITY_PROVIDER_H_
#include "base/macros.h"
#include "build/build_config.h"
#include "components/invalidation/public/identity_provider.h"
#include "components/signin/core/browser/signin_manager_base.h"
class ProfileOAuth2TokenService;
namespace invalidation {
// An identity provider implementation that's backed by
// ProfileOAuth2TokenService and SigninManager.
class ProfileIdentityProvider : public IdentityProvider,
public OAuth2TokenService::Observer,
public SigninManagerBase::Observer {
public:
ProfileIdentityProvider(SigninManagerBase* signin_manager,
ProfileOAuth2TokenService* token_service);
#if defined(UNIT_TEST)
// Provide a testing constructor that allows for a null SigninManager instance
// to be passed, as there are tests that don't interact with the login
// functionality and it is a pain to set up FakeSigninManager(Base).
// TODO(809452): Eliminate this testing constructor when this class is
// converted to take in IdentityManager, at which point the tests can use
// IdentityTestEnvironment.
ProfileIdentityProvider(ProfileOAuth2TokenService* token_service)
: signin_manager_(nullptr), token_service_(token_service) {}
#endif
~ProfileIdentityProvider() override;
// IdentityProvider:
std::string GetActiveAccountId() override;
bool IsActiveAccountAvailable() override;
std::unique_ptr<ActiveAccountAccessTokenFetcher> FetchAccessToken(
const std::string& oauth_consumer_name,
const OAuth2TokenService::ScopeSet& scopes,
ActiveAccountAccessTokenCallback callback) override;
void InvalidateAccessToken(const OAuth2TokenService::ScopeSet& scopes,
const std::string& access_token) override;
// SigninManagerBase::Observer:
void GoogleSigninSucceeded(const std::string& account_id,
const std::string& username) override;
void GoogleSignedOut(const std::string& account_id,
const std::string& username) override;
// OAuth2TokenService::Observer:
void OnRefreshTokenAvailable(const std::string& account_id) override;
void OnRefreshTokenRevoked(const std::string& account_id) override;
private:
SigninManagerBase* const signin_manager_;
ProfileOAuth2TokenService* const token_service_;
DISALLOW_COPY_AND_ASSIGN(ProfileIdentityProvider);
};
} // namespace invalidation
#endif // COMPONENTS_INVALIDATION_IMPL_PROFILE_IDENTITY_PROVIDER_H_