fido_task.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2018 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. #ifndef DEVICE_FIDO_FIDO_TASK_H_
  5. #define DEVICE_FIDO_FIDO_TASK_H_
  6. #include <stdint.h>
  7. #include "base/callback.h"
  8. #include "base/component_export.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "device/fido/fido_device.h"
  12. namespace device {
  13. // Encapsulates per-device request logic shared between MakeCredential and
  14. // GetAssertion.
  15. //
  16. // TODO(martinkr): FidoTask should be subsumed by FidoDeviceAuthenticator.
  17. class COMPONENT_EXPORT(DEVICE_FIDO) FidoTask {
  18. public:
  19. // The |device| must outlive the FidoTask instance.
  20. explicit FidoTask(FidoDevice* device);
  21. FidoTask(const FidoTask&) = delete;
  22. FidoTask& operator=(const FidoTask&) = delete;
  23. virtual ~FidoTask();
  24. // Cancel attempts to cancel the operation. This may safely be called at any
  25. // point but may not be effective because the task may have already completed
  26. // or the device may not support cancelation. Even if canceled, the callback
  27. // will still be invoked, albeit perhaps with a status of
  28. // |kCtap2ErrKeepAliveCancel|.
  29. virtual void Cancel() = 0;
  30. protected:
  31. // Asynchronously initiates CTAP request operation for a single device.
  32. virtual void StartTask() = 0;
  33. FidoDevice* device() const {
  34. DCHECK(device_);
  35. return device_;
  36. }
  37. private:
  38. const raw_ptr<FidoDevice> device_;
  39. base::WeakPtrFactory<FidoTask> weak_factory_{this};
  40. };
  41. } // namespace device
  42. #endif // DEVICE_FIDO_FIDO_TASK_H_