Commit 59ae38aa authored by Anastasiia N's avatar Anastasiia N Committed by Chromium LUCI CQ

[Lacros] Add mojo type for GoogleServiceAuthError

Add GoogleServiceAuthError to account_manager.mojom and add to- and
from- mojo conversion methods to account_manager_util.

Bug: 1140469
Change-Id: I98d71e2c5e9fd7a205d52cfb98213bab789e446e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631502
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846010}
parent 0c670037
...@@ -36,6 +36,46 @@ struct Account { ...@@ -36,6 +36,46 @@ struct Account {
string raw_email@1; string raw_email@1;
}; };
// See google_apis/gaia/google_service_auth_error.h
// Currently sent from ash to lacros.
// Next value: 14.
[Stable]
struct GoogleServiceAuthError {
[Stable, Extensible]
enum State {
kNone = 0,
kInvalidGaiaCredentials = 1,
kUserNotSignedUp = 2,
kConnectionFailed = 3,
// DEPRECATED kCaptchaRequired = 4,
// DEPRECATED kAccountDeleted = 5,
// DEPRECATED kAccountDisabled = 6,
kServiceUnavailable = 7,
// DEPRECATED kTwoFactor = 8,
kRequestCanceled = 9,
// DEPRECATED kHostedNotAllowedDeprecated = 10,
kUnexpectedServiceResponse = 11,
kServiceError = 12,
// DEPRECATED kWebLoginRequired = 13,
};
// Next value: 4.
[Stable, Extensible]
enum InvalidGaiaCredentialsReason {
kUnknown = 0,
kCredentialsRejectedByServer = 1,
kCredentialsRejectedByClient = 2,
kCredentialsMissing = 3,
};
State state@0;
// Network error is set only if `state` is set to `kConnectionFailed`.
// In case of no network error, `network_error` is set to 0.
int64 network_error@1;
string error_message@2;
InvalidGaiaCredentialsReason invalid_gaia_credentials_reason@3;
};
// Interface for observers of Chrome OS Account Manager. // Interface for observers of Chrome OS Account Manager.
// This interface is implemented by lacros-chrome, and is used by ash-chrome to // This interface is implemented by lacros-chrome, and is used by ash-chrome to
// send account update notifications. // send account update notifications.
......
...@@ -5,9 +5,93 @@ ...@@ -5,9 +5,93 @@
#include "components/account_manager_core/account_manager_util.h" #include "components/account_manager_core/account_manager_util.h"
#include "components/account_manager_core/account.h" #include "components/account_manager_core/account.h"
#include "google_apis/gaia/google_service_auth_error.h"
namespace account_manager { namespace account_manager {
namespace cm = crosapi::mojom;
namespace {
GoogleServiceAuthError::InvalidGaiaCredentialsReason
FromMojoInvalidGaiaCredentialsReason(
crosapi::mojom::GoogleServiceAuthError::InvalidGaiaCredentialsReason
mojo_reason) {
switch (mojo_reason) {
case cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::kUnknown:
return GoogleServiceAuthError::InvalidGaiaCredentialsReason::UNKNOWN;
case cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsRejectedByServer:
return GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER;
case cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsRejectedByClient:
return GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT;
case cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsMissing:
return GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_MISSING;
default:
LOG(WARNING) << "Unknown "
"crosapi::mojom::GoogleServiceAuthError::"
"InvalidGaiaCredentialsReason: "
<< mojo_reason;
return GoogleServiceAuthError::InvalidGaiaCredentialsReason::UNKNOWN;
}
}
crosapi::mojom::GoogleServiceAuthError::InvalidGaiaCredentialsReason
ToMojoInvalidGaiaCredentialsReason(
GoogleServiceAuthError::InvalidGaiaCredentialsReason reason) {
switch (reason) {
case GoogleServiceAuthError::InvalidGaiaCredentialsReason::UNKNOWN:
return cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::kUnknown;
case GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_SERVER:
return cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsRejectedByServer;
case GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_REJECTED_BY_CLIENT:
return cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsRejectedByClient;
case GoogleServiceAuthError::InvalidGaiaCredentialsReason::
CREDENTIALS_MISSING:
return cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::
kCredentialsMissing;
case GoogleServiceAuthError::InvalidGaiaCredentialsReason::NUM_REASONS:
NOTREACHED();
return cm::GoogleServiceAuthError::InvalidGaiaCredentialsReason::kUnknown;
}
}
crosapi::mojom::GoogleServiceAuthError::State ToMojoGoogleServiceAuthErrorState(
GoogleServiceAuthError::State state) {
switch (state) {
case GoogleServiceAuthError::State::NONE:
return cm::GoogleServiceAuthError::State::kNone;
case GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS:
return cm::GoogleServiceAuthError::State::kInvalidGaiaCredentials;
case GoogleServiceAuthError::State::USER_NOT_SIGNED_UP:
return cm::GoogleServiceAuthError::State::kUserNotSignedUp;
case GoogleServiceAuthError::State::CONNECTION_FAILED:
return cm::GoogleServiceAuthError::State::kConnectionFailed;
case GoogleServiceAuthError::State::SERVICE_UNAVAILABLE:
return cm::GoogleServiceAuthError::State::kServiceUnavailable;
case GoogleServiceAuthError::State::REQUEST_CANCELED:
return cm::GoogleServiceAuthError::State::kRequestCanceled;
case GoogleServiceAuthError::State::UNEXPECTED_SERVICE_RESPONSE:
return cm::GoogleServiceAuthError::State::kUnexpectedServiceResponse;
case GoogleServiceAuthError::State::SERVICE_ERROR:
return cm::GoogleServiceAuthError::State::kServiceError;
case GoogleServiceAuthError::State::NUM_STATES:
NOTREACHED();
return cm::GoogleServiceAuthError::State::kNone;
}
}
} // namespace
base::Optional<account_manager::Account> FromMojoAccount( base::Optional<account_manager::Account> FromMojoAccount(
const crosapi::mojom::AccountPtr& mojom_account) { const crosapi::mojom::AccountPtr& mojom_account) {
const base::Optional<account_manager::AccountKey> account_key = const base::Optional<account_manager::AccountKey> account_key =
...@@ -83,4 +167,56 @@ crosapi::mojom::AccountType ToMojoAccountType( ...@@ -83,4 +167,56 @@ crosapi::mojom::AccountType ToMojoAccountType(
} }
} }
base::Optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
const crosapi::mojom::GoogleServiceAuthErrorPtr& mojo_error) {
switch (mojo_error->state) {
case cm::GoogleServiceAuthError::State::kNone:
return GoogleServiceAuthError::AuthErrorNone();
case cm::GoogleServiceAuthError::State::kInvalidGaiaCredentials:
return GoogleServiceAuthError::FromInvalidGaiaCredentialsReason(
FromMojoInvalidGaiaCredentialsReason(
mojo_error->invalid_gaia_credentials_reason));
case cm::GoogleServiceAuthError::State::kConnectionFailed:
return GoogleServiceAuthError::FromConnectionError(
mojo_error->network_error);
case cm::GoogleServiceAuthError::State::kServiceError:
return GoogleServiceAuthError::FromServiceError(
mojo_error->error_message);
case cm::GoogleServiceAuthError::State::kUnexpectedServiceResponse:
return GoogleServiceAuthError::FromUnexpectedServiceResponse(
mojo_error->error_message);
case cm::GoogleServiceAuthError::State::kUserNotSignedUp:
return GoogleServiceAuthError(
GoogleServiceAuthError::State::USER_NOT_SIGNED_UP);
case cm::GoogleServiceAuthError::State::kServiceUnavailable:
return GoogleServiceAuthError(
GoogleServiceAuthError::State::SERVICE_UNAVAILABLE);
case cm::GoogleServiceAuthError::State::kRequestCanceled:
return GoogleServiceAuthError(
GoogleServiceAuthError::State::REQUEST_CANCELED);
default:
LOG(WARNING) << "Unknown crosapi::mojom::GoogleServiceAuthError::State: "
<< mojo_error->state;
return base::nullopt;
}
}
crosapi::mojom::GoogleServiceAuthErrorPtr ToMojoGoogleServiceAuthError(
GoogleServiceAuthError error) {
crosapi::mojom::GoogleServiceAuthErrorPtr mojo_result =
crosapi::mojom::GoogleServiceAuthError::New();
mojo_result->error_message = error.error_message();
if (error.state() == GoogleServiceAuthError::State::CONNECTION_FAILED) {
mojo_result->network_error = error.network_error();
}
if (error.state() ==
GoogleServiceAuthError::State::INVALID_GAIA_CREDENTIALS) {
mojo_result->invalid_gaia_credentials_reason =
ToMojoInvalidGaiaCredentialsReason(
error.GetInvalidGaiaCredentialsReason());
}
mojo_result->state = ToMojoGoogleServiceAuthErrorState(error.state());
return mojo_result;
}
} // namespace account_manager } // namespace account_manager
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "components/account_manager_core/account.h" #include "components/account_manager_core/account.h"
class GoogleServiceAuthError;
namespace account_manager { namespace account_manager {
// Returns `base::nullopt` if `mojom_account` cannot be parsed. // Returns `base::nullopt` if `mojom_account` cannot be parsed.
...@@ -38,6 +40,17 @@ COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) ...@@ -38,6 +40,17 @@ COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountType ToMojoAccountType( crosapi::mojom::AccountType ToMojoAccountType(
const account_manager::AccountType& account_type); const account_manager::AccountType& account_type);
// Returns `base::nullopt` if `mojo_error` cannot be parsed. This probably means
// that a new error type was added, so it should be considered a persistent
// error.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
base::Optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
const crosapi::mojom::GoogleServiceAuthErrorPtr& mojo_error);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::GoogleServiceAuthErrorPtr ToMojoGoogleServiceAuthError(
GoogleServiceAuthError error);
} // namespace account_manager } // namespace account_manager
#endif // COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_UTIL_H_ #endif // COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_UTIL_H_
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