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

Side by Side Diff: device/u2f/u2f_register.cc

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 unified diff | Download patch
« no previous file with comments | « device/u2f/u2f_register.h ('k') | device/u2f/u2f_register_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "u2f_register.h"
6
7 #include "base/memory/ptr_util.h"
8
9 namespace device {
10
11 U2fRegister::U2fRegister(const std::vector<uint8_t>& challenge_hash,
12 const std::vector<uint8_t>& app_param,
13 const ResponseCallback& cb)
14 : U2fRequest(cb),
15 challenge_hash_(challenge_hash),
16 app_param_(app_param),
17 weak_factory_(this) {}
18
19 U2fRegister::~U2fRegister() {}
20
21 // static
22 std::unique_ptr<U2fRequest> U2fRegister::TryRegistration(
23 const std::vector<uint8_t>& challenge_hash,
24 const std::vector<uint8_t>& app_param,
25 const ResponseCallback& cb) {
26 std::unique_ptr<U2fRequest> request =
27 base::MakeUnique<U2fRegister>(challenge_hash, app_param, cb);
28 request->Start();
29 return request;
30 }
31
32 void U2fRegister::TryDevice() {
33 DCHECK(current_device_);
34
35 current_device_->Register(
36 app_param_, challenge_hash_,
37 base::Bind(&U2fRegister::OnTryDevice, weak_factory_.GetWeakPtr()));
38 }
39
40 void U2fRegister::OnTryDevice(U2fReturnCode return_code,
41 std::vector<uint8_t> response_data) {
42 switch (return_code) {
43 case U2fReturnCode::SUCCESS:
44 state_ = State::COMPLETE;
45 cb_.Run(return_code, response_data);
46 break;
47 case U2fReturnCode::CONDITIONS_NOT_SATISFIED:
48 // Waiting for user touch, move on and try this device later
49 state_ = State::IDLE;
50 Transition();
51 break;
52 default:
53 state_ = State::IDLE;
54 // An error has occured, quit trying this device
55 current_device_ = nullptr;
56 Transition();
57 break;
58 }
59 }
60
61 } // namespace device
OLDNEW
« no previous file with comments | « device/u2f/u2f_register.h ('k') | device/u2f/u2f_register_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698