sync_auth_util.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 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. #include "components/sync/driver/sync_auth_util.h"
  5. #include "components/signin/public/base/consent_level.h"
  6. #include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h"
  7. #include "components/signin/public/identity_manager/identity_manager.h"
  8. #include "google_apis/gaia/gaia_auth_util.h"
  9. #include "google_apis/gaia/google_service_auth_error.h"
  10. namespace syncer {
  11. SyncAccountInfo::SyncAccountInfo() = default;
  12. SyncAccountInfo::SyncAccountInfo(const CoreAccountInfo& account_info,
  13. bool is_sync_consented)
  14. : account_info(account_info), is_sync_consented(is_sync_consented) {}
  15. SyncAccountInfo DetermineAccountToUse(
  16. signin::IdentityManager* identity_manager) {
  17. return SyncAccountInfo(
  18. identity_manager->GetPrimaryAccountInfo(signin::ConsentLevel::kSignin),
  19. /*is_sync_consented=*/identity_manager->HasPrimaryAccount(
  20. signin::ConsentLevel::kSync));
  21. }
  22. bool IsWebSignout(const GoogleServiceAuthError& auth_error) {
  23. // The identity code sets an account's refresh token to be invalid (error
  24. // CREDENTIALS_REJECTED_BY_CLIENT) if the user signs out of that account on
  25. // the web.
  26. return auth_error ==
  27. GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
  28. GoogleServiceAuthError::InvalidGaiaCredentialsReason::
  29. CREDENTIALS_REJECTED_BY_CLIENT);
  30. }
  31. } // namespace syncer