forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfido_device_discovery.h
86 lines (65 loc) · 2.45 KB
/
fido_device_discovery.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_FIDO_FIDO_DEVICE_DISCOVERY_H_
#define DEVICE_FIDO_FIDO_DEVICE_DISCOVERY_H_
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/component_export.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_piece.h"
#include "device/fido/fido_discovery_base.h"
#include "device/fido/fido_transport_protocol.h"
namespace device {
class FidoDevice;
class FidoDeviceAuthenticator;
class COMPONENT_EXPORT(DEVICE_FIDO) FidoDeviceDiscovery
: public FidoDiscoveryBase {
public:
enum class State {
kIdle,
kStarting,
kRunning,
kStopped,
};
~FidoDeviceDiscovery() override;
bool is_start_requested() const { return state_ != State::kIdle; }
bool is_running() const { return state_ == State::kRunning; }
std::vector<FidoDeviceAuthenticator*> GetAuthenticatorsForTesting();
std::vector<const FidoDeviceAuthenticator*> GetAuthenticatorsForTesting()
const;
FidoDeviceAuthenticator* GetAuthenticatorForTesting(
base::StringPiece authenticator_id);
// FidoDiscoveryBase:
void Start() override;
bool MaybeStop() override;
protected:
FidoDeviceDiscovery(FidoTransportProtocol transport);
void NotifyDiscoveryStarted(bool success);
bool AddDevice(std::unique_ptr<FidoDevice> device);
bool RemoveDevice(base::StringPiece device_id);
FidoDeviceAuthenticator* GetAuthenticator(base::StringPiece authenticator_id);
// Subclasses should implement this to actually start the discovery when it is
// requested.
//
// The implementation should asynchronously invoke NotifyDiscoveryStarted when
// the discovery is s tarted.
virtual void StartInternal() = 0;
// Map of ID to authenticator. It is a guarantee to subclasses that the ID of
// the authenticator equals the ID of the device.
std::map<std::string, std::unique_ptr<FidoDeviceAuthenticator>, std::less<>>
authenticators_;
private:
void NotifyAuthenticatorAdded(FidoAuthenticator* authenticator);
void NotifyAuthenticatorRemoved(FidoAuthenticator* authenticator);
State state_ = State::kIdle;
base::WeakPtrFactory<FidoDeviceDiscovery> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FidoDeviceDiscovery);
};
} // namespace device
#endif // DEVICE_FIDO_FIDO_DEVICE_DISCOVERY_H_