#ifndef CHROMEOS_ASH_COMPONENTS_KCER_TOKEN_KEY_FINDER_H_
#define CHROMEOS_ASH_COMPONENTS_KCER_TOKEN_KEY_FINDER_H_
#include <optional>
#include "base/containers/flat_map.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/types/expected.h"
#include "base/types/pass_key.h"
#include "chromeos/ash/components/kcer/kcer.h"
namespace kcer::internal {
class COMPONENT_EXPORT(KCER) TokenKeyFinder
: public base::RefCounted<TokenKeyFinder> {
public:
static scoped_refptr<TokenKeyFinder> Create(
int results_to_receive,
base::OnceCallback<void(base::expected<std::optional<Token>, Error>)>
callback);
TokenKeyFinder(
base::PassKey<TokenKeyFinder>,
int results_to_receive,
base::OnceCallback<void(base::expected<std::optional<Token>, Error>)>
callback);
base::OnceCallback<void(base::expected<bool, Error>)> GetCallback(
Token token);
private:
friend class base::RefCounted<TokenKeyFinder>;
~TokenKeyFinder();
void HandleOneResult(Token token, base::expected<bool, Error> result);
int callbacks_to_create_ = 0;
int results_to_receive_ = 0;
base::OnceCallback<void(base::expected<std::optional<Token>, Error>)>
callback_;
base::flat_map<Token, Error> errors_;
};
}
#endif