account_addition_result.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 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/account_manager_core/account_addition_result.h"
  5. #include "base/check.h"
  6. #include "google_apis/gaia/google_service_auth_error.h"
  7. namespace account_manager {
  8. // static
  9. AccountAdditionResult AccountAdditionResult::FromStatus(Status status) {
  10. DCHECK_NE(status, Status::kSuccess);
  11. DCHECK_NE(status, Status::kNetworkError);
  12. return AccountAdditionResult(status, /*account=*/absl::nullopt,
  13. GoogleServiceAuthError::AuthErrorNone());
  14. }
  15. // static
  16. AccountAdditionResult AccountAdditionResult::FromAccount(
  17. const Account& account) {
  18. return AccountAdditionResult(Status::kSuccess, account,
  19. GoogleServiceAuthError::AuthErrorNone());
  20. }
  21. // static
  22. AccountAdditionResult AccountAdditionResult::FromError(
  23. const GoogleServiceAuthError& error) {
  24. DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
  25. return AccountAdditionResult(Status::kNetworkError, /*account=*/absl::nullopt,
  26. error);
  27. }
  28. AccountAdditionResult::AccountAdditionResult(const AccountAdditionResult&) =
  29. default;
  30. AccountAdditionResult::~AccountAdditionResult() = default;
  31. AccountAdditionResult::AccountAdditionResult(
  32. Status status,
  33. const absl::optional<Account>& account,
  34. const GoogleServiceAuthError& error)
  35. : status_(status), account_(account), error_(error) {
  36. DCHECK_EQ(account.has_value(), status == Status::kSuccess);
  37. DCHECK_NE(error.state() == GoogleServiceAuthError::NONE,
  38. status == Status::kNetworkError);
  39. }
  40. } // namespace account_manager