#include "components/unexportable_keys/unexportable_key_task_manager.h"
#include <memory>
#include <optional>
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/task/single_thread_task_runner_thread_mode.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/types/expected.h"
#include "components/unexportable_keys/background_long_task_scheduler.h"
#include "components/unexportable_keys/background_task_priority.h"
#include "components/unexportable_keys/background_task_type.h"
#include "components/unexportable_keys/features.h"
#include "components/unexportable_keys/ref_counted_unexportable_signing_key.h"
#include "components/unexportable_keys/service_error.h"
#include "components/unexportable_keys/unexportable_key_id.h"
#include "components/unexportable_keys/unexportable_key_tasks.h"
#include "crypto/signature_verifier.h"
#include "crypto/unexportable_key.h"
namespace unexportable_keys {
namespace {
constexpr std::string_view kBaseTaskResultHistogramName = …;
ServiceErrorOr<scoped_refptr<RefCountedUnexportableSigningKey>>
MakeSigningKeyRefCounted(std::unique_ptr<crypto::UnexportableSigningKey> key) { … }
ServiceErrorOr<std::vector<uint8_t>> OptionalToServiceErrorOr(
std::optional<std::vector<uint8_t>> result) { … }
template <class CallbackReturnType>
ServiceErrorOr<CallbackReturnType> ReportResultMetrics(
BackgroundTaskType task_type,
ServiceErrorOr<CallbackReturnType> result) { … }
template <class CallbackReturnType>
base::OnceCallback<void(ServiceErrorOr<CallbackReturnType>)>
WrapCallbackWithMetrics(
BackgroundTaskType task_type,
base::OnceCallback<void(ServiceErrorOr<CallbackReturnType>)> callback) { … }
}
UnexportableKeyTaskManager::UnexportableKeyTaskManager(
crypto::UnexportableKeyProvider::Config config)
: … { … }
UnexportableKeyTaskManager::~UnexportableKeyTaskManager() = default;
std::unique_ptr<crypto::UnexportableKeyProvider>
UnexportableKeyTaskManager::GetUnexportableKeyProvider(
crypto::UnexportableKeyProvider::Config config) { … }
void UnexportableKeyTaskManager::GenerateSigningKeySlowlyAsync(
base::span<const crypto::SignatureVerifier::SignatureAlgorithm>
acceptable_algorithms,
BackgroundTaskPriority priority,
base::OnceCallback<
void(ServiceErrorOr<scoped_refptr<RefCountedUnexportableSigningKey>>)>
callback) { … }
void UnexportableKeyTaskManager::FromWrappedSigningKeySlowlyAsync(
base::span<const uint8_t> wrapped_key,
BackgroundTaskPriority priority,
base::OnceCallback<
void(ServiceErrorOr<scoped_refptr<RefCountedUnexportableSigningKey>>)>
callback) { … }
void UnexportableKeyTaskManager::SignSlowlyAsync(
scoped_refptr<RefCountedUnexportableSigningKey> signing_key,
base::span<const uint8_t> data,
BackgroundTaskPriority priority,
base::OnceCallback<void(ServiceErrorOr<std::vector<uint8_t>>)> callback) { … }
}