#include "components/trusted_vault/standalone_trusted_vault_client.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h"
#include "components/trusted_vault/command_line_switches.h"
#include "components/trusted_vault/proto/local_trusted_vault.pb.h"
#include "components/trusted_vault/recovery_key_store_connection_impl.h"
#include "components/trusted_vault/recovery_key_store_controller.h"
#include "components/trusted_vault/standalone_trusted_vault_backend.h"
#include "components/trusted_vault/trusted_vault_access_token_fetcher_impl.h"
#include "components/trusted_vault/trusted_vault_connection_impl.h"
#include "components/trusted_vault/trusted_vault_server_constants.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace trusted_vault {
namespace {
constexpr base::TaskTraits kBackendTaskTraits = …;
void ReplyToIsDeviceRegisteredForTesting(
base::OnceCallback<void(bool)> is_device_registered_callback,
const trusted_vault_pb::LocalDeviceRegistrationInfo&
device_registration_info) { … }
class IdentityManagerObserver : public signin::IdentityManager::Observer { … };
IdentityManagerObserver::IdentityManagerObserver(
scoped_refptr<base::SequencedTaskRunner> backend_task_runner,
scoped_refptr<StandaloneTrustedVaultBackend> backend,
const base::RepeatingClosure& notify_keys_changed_callback,
signin::IdentityManager* identity_manager)
: … { … }
IdentityManagerObserver::~IdentityManagerObserver() { … }
void IdentityManagerObserver::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) { … }
void IdentityManagerObserver::OnAccountsCookieDeletedByUserAction() { … }
void IdentityManagerObserver::OnAccountsInCookieUpdated(
const signin::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
const GoogleServiceAuthError& error) { … }
void IdentityManagerObserver::OnErrorStateOfRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info,
const GoogleServiceAuthError& error,
signin_metrics::SourceForRefreshTokenOperation token_operation_source) { … }
void IdentityManagerObserver::OnRefreshTokensLoaded() { … }
void IdentityManagerObserver::UpdatePrimaryAccountIfNeeded() { … }
void IdentityManagerObserver::UpdateAccountsInCookieJarInfoIfNeeded(
const signin::AccountsInCookieJarInfo& accounts_in_cookie_jar_info) { … }
StandaloneTrustedVaultBackend::RefreshTokenErrorState
IdentityManagerObserver::GetPrimaryAccountRefreshTokenErrorState() const { … }
class BackendDelegate : public StandaloneTrustedVaultBackend::Delegate { … };
constexpr base::FilePath::CharType kChromeSyncTrustedVaultFilename[] = …);
constexpr base::FilePath::CharType kPasskeysTrustedVaultFilename[] = …);
base::FilePath GetBackendFilePath(const base::FilePath& base_dir,
SecurityDomainId security_domain) { … }
}
StandaloneTrustedVaultClient::StandaloneTrustedVaultClient(
SecurityDomainId security_domain,
const base::FilePath& base_dir,
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<RecoveryKeyStoreController::RecoveryKeyProvider>
recovery_key_provider)
: … { … }
StandaloneTrustedVaultClient::StandaloneTrustedVaultClient(
SecurityDomainId security_domain,
const base::FilePath& base_dir,
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
StandaloneTrustedVaultClient::~StandaloneTrustedVaultClient() { … }
void StandaloneTrustedVaultClient::AddObserver(Observer* observer) { … }
void StandaloneTrustedVaultClient::RemoveObserver(Observer* observer) { … }
void StandaloneTrustedVaultClient::FetchKeys(
const CoreAccountInfo& account_info,
base::OnceCallback<void(const std::vector<std::vector<uint8_t>>&)> cb) { … }
void StandaloneTrustedVaultClient::StoreKeys(
const std::string& gaia_id,
const std::vector<std::vector<uint8_t>>& keys,
int last_key_version) { … }
void StandaloneTrustedVaultClient::MarkLocalKeysAsStale(
const CoreAccountInfo& account_info,
base::OnceCallback<void(bool)> cb) { … }
void StandaloneTrustedVaultClient::GetIsRecoverabilityDegraded(
const CoreAccountInfo& account_info,
base::OnceCallback<void(bool)> cb) { … }
void StandaloneTrustedVaultClient::AddTrustedRecoveryMethod(
const std::string& gaia_id,
const std::vector<uint8_t>& public_key,
int method_type_hint,
base::OnceClosure cb) { … }
void StandaloneTrustedVaultClient::ClearLocalDataForAccount(
const CoreAccountInfo& account_info) { … }
void StandaloneTrustedVaultClient::WaitForFlushForTesting(
base::OnceClosure cb) const { … }
void StandaloneTrustedVaultClient::FetchBackendPrimaryAccountForTesting(
base::OnceCallback<void(const std::optional<CoreAccountInfo>&)> cb) const { … }
void StandaloneTrustedVaultClient::FetchIsDeviceRegisteredForTesting(
const std::string& gaia_id,
base::OnceCallback<void(bool)> callback) { … }
void StandaloneTrustedVaultClient::AddDebugObserverForTesting(
DebugObserver* debug_observer) { … }
void StandaloneTrustedVaultClient::RemoveDebugObserverForTesting(
DebugObserver* debug_observer) { … }
void StandaloneTrustedVaultClient::
GetLastAddedRecoveryMethodPublicKeyForTesting(
base::OnceCallback<void(const std::vector<uint8_t>&)> callback) { … }
void StandaloneTrustedVaultClient::GetLastKeyVersionForTesting(
const std::string& gaia_id,
base::OnceCallback<void(int last_key_version)> callback) { … }
void StandaloneTrustedVaultClient::NotifyTrustedVaultKeysChanged() { … }
void StandaloneTrustedVaultClient::NotifyRecoverabilityDegradedChanged() { … }
void StandaloneTrustedVaultClient::NotifyBackendStateChanged() { … }
}