Commit 06e3530b authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Lacros] Add ToMojoAccountKey/FromMojoAccountKey helpers

Adds ToMojoAccountKey/FromMojoAccountKey helpers to
components/account_manager_core/account_manager_util.h. These methods
will be used by subsequent CLs to implement observers in
AccountManagerFacade.

Bug: 1117472
Change-Id: I625afacc31dc2d3bd4ceb56dde70a99ed1d15e55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2542903Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828181}
parent 24d017d9
...@@ -10,14 +10,13 @@ namespace account_manager { ...@@ -10,14 +10,13 @@ namespace account_manager {
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::AccountType> account_type = const base::Optional<account_manager::AccountKey> account_key =
FromMojoAccountType(mojom_account->key->account_type); FromMojoAccountKey(mojom_account->key);
if (!account_type.has_value()) if (!account_key.has_value())
return base::nullopt; return base::nullopt;
account_manager::Account account; account_manager::Account account;
account.key.id = mojom_account->key->id; account.key = account_key.value();
account.key.account_type = account_type.value();
account.raw_email = mojom_account->raw_email; account.raw_email = mojom_account->raw_email;
return account; return account;
} }
...@@ -25,16 +24,33 @@ base::Optional<account_manager::Account> FromMojoAccount( ...@@ -25,16 +24,33 @@ base::Optional<account_manager::Account> FromMojoAccount(
crosapi::mojom::AccountPtr ToMojoAccount( crosapi::mojom::AccountPtr ToMojoAccount(
const account_manager::Account& account) { const account_manager::Account& account) {
crosapi::mojom::AccountPtr mojom_account = crosapi::mojom::Account::New(); crosapi::mojom::AccountPtr mojom_account = crosapi::mojom::Account::New();
mojom_account->key = ToMojoAccountKey(account.key);
mojom_account->key = crosapi::mojom::AccountKey::New();
mojom_account->key->id = account.key.id;
mojom_account->key->account_type =
ToMojoAccountType(account.key.account_type);
mojom_account->raw_email = account.raw_email; mojom_account->raw_email = account.raw_email;
return mojom_account; return mojom_account;
} }
base::Optional<account_manager::AccountKey> FromMojoAccountKey(
const crosapi::mojom::AccountKeyPtr& mojom_account_key) {
const base::Optional<account_manager::AccountType> account_type =
FromMojoAccountType(mojom_account_key->account_type);
if (!account_type.has_value())
return base::nullopt;
account_manager::AccountKey account_key;
account_key.id = mojom_account_key->id;
account_key.account_type = account_type.value();
return account_key;
}
crosapi::mojom::AccountKeyPtr ToMojoAccountKey(
const account_manager::AccountKey& account_key) {
crosapi::mojom::AccountKeyPtr mojom_account_key =
crosapi::mojom::AccountKey::New();
mojom_account_key->id = account_key.id;
mojom_account_key->account_type = ToMojoAccountType(account_key.account_type);
return mojom_account_key;
}
base::Optional<account_manager::AccountType> FromMojoAccountType( base::Optional<account_manager::AccountType> FromMojoAccountType(
const crosapi::mojom::AccountType& account_type) { const crosapi::mojom::AccountType& account_type) {
switch (account_type) { switch (account_type) {
......
...@@ -20,6 +20,15 @@ COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) ...@@ -20,6 +20,15 @@ COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountPtr ToMojoAccount( crosapi::mojom::AccountPtr ToMojoAccount(
const account_manager::Account& account); const account_manager::Account& account);
// Returns `base::nullopt` if `mojom_account_key` cannot be parsed.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
base::Optional<account_manager::AccountKey> FromMojoAccountKey(
const crosapi::mojom::AccountKeyPtr& mojom_account_key);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountKeyPtr ToMojoAccountKey(
const account_manager::AccountKey& account_key);
// Returns `base::nullopt` if `account_type` cannot be parsed. // Returns `base::nullopt` if `account_type` cannot be parsed.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
base::Optional<account_manager::AccountType> FromMojoAccountType( base::Optional<account_manager::AccountType> FromMojoAccountType(
......
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