Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Unified Diff: device/u2f/u2f_request.h

Issue 2821263005: Add U2F request state machines (Closed)
Patch Set: Call Start before adding devices Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/u2f/u2f_register_unittest.cc ('k') | device/u2f/u2f_request.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/u2f/u2f_request.h
diff --git a/device/u2f/u2f_request.h b/device/u2f/u2f_request.h
new file mode 100644
index 0000000000000000000000000000000000000000..902a2ca84d6f51275e2a93b97c9c37a6722dff72
--- /dev/null
+++ b/device/u2f/u2f_request.h
@@ -0,0 +1,65 @@
+// 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_U2F_U2F_REQUEST_H_
+#define DEVICE_U2F_U2F_REQUEST_H_
+
+#include "base/cancelable_callback.h"
+#include "base/scoped_observer.h"
+#include "device/hid/hid_device_filter.h"
+#include "device/hid/hid_service.h"
+#include "u2f_device.h"
+
+namespace device {
+class U2fRequest : HidService::Observer {
+ public:
+ using ResponseCallback = base::Callback<void(U2fReturnCode status_code,
+ std::vector<uint8_t> response)>;
+
+ U2fRequest(const ResponseCallback& callback);
+ virtual ~U2fRequest();
+
+ void Start();
+ void AddDeviceForTesting(std::unique_ptr<U2fDevice> device);
+
+ protected:
+ enum class State {
+ INIT,
+ BUSY,
+ WINK,
+ IDLE,
+ OFF,
+ COMPLETE,
+ };
+
+ void Transition();
+ virtual void TryDevice() = 0;
+
+ std::unique_ptr<U2fDevice> current_device_;
+ State state_;
+ ResponseCallback cb_;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestAddRemoveDevice);
+ FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestIterateDevice);
+ FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestBasicMachine);
+
+ void Enumerate();
+ void IterateDevice();
+ void OnWaitComplete();
+ void AddDevice(std::unique_ptr<U2fDevice> device);
+ void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override;
+ void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override;
+ void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices);
+
+ std::list<std::unique_ptr<U2fDevice>> devices_;
+ std::list<std::unique_ptr<U2fDevice>> attempted_devices_;
+ base::CancelableClosure delay_callback_;
+ HidDeviceFilter filter_;
+ ScopedObserver<HidService, HidService::Observer> hid_service_observer_;
+ base::WeakPtrFactory<U2fRequest> weak_factory_;
+};
+} // namespace device
+
+#endif // DEVICE_U2F_U2F_REQUEST_H_
« no previous file with comments | « device/u2f/u2f_register_unittest.cc ('k') | device/u2f/u2f_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698