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