Chromium Code Reviews| OLD | NEW |
|---|---|
| (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(std::vector<uint8_t> challenge_hash, | |
| 12 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 std::vector<uint8_t> challenge_hash, | |
| 24 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 if (request) | |
|
Reilly Grant (use Gerrit)
2017/04/21 17:19:16
base::MakeUnique cannot fail.
Casey Piper
2017/04/21 18:42:26
Acknowledged.
| |
| 29 request->Start(); | |
| 30 return request; | |
| 31 } | |
| 32 | |
| 33 void U2fRegister::TryDevice() { | |
| 34 if (!current_device_) | |
| 35 return; | |
|
Reilly Grant (use Gerrit)
2017/04/21 17:19:16
DCHECK?
Casey Piper
2017/04/21 18:42:26
Done.
| |
| 36 | |
| 37 current_device_->Register( | |
| 38 app_param_, challenge_hash_, | |
| 39 base::Bind(&U2fRegister::OnTryDevice, weak_factory_.GetWeakPtr())); | |
| 40 } | |
| 41 | |
| 42 void U2fRegister::OnTryDevice(U2fDevice::ReturnCode return_code, | |
| 43 std::vector<uint8_t> response_data) { | |
| 44 switch (return_code) { | |
| 45 case U2fDevice::ReturnCode::SUCCESS: | |
| 46 state_ = State::COMPLETE; | |
| 47 cb_.Run(static_cast<uint8_t>(return_code), response_data); | |
| 48 break; | |
| 49 case U2fDevice::ReturnCode::CONDITIONS_NOT_SATISFIED: | |
| 50 // Waiting for user touch, move on and try this device later | |
| 51 state_ = State::IDLE; | |
| 52 Transition(); | |
| 53 break; | |
| 54 default: | |
| 55 state_ = State::IDLE; | |
| 56 // An error has occured, quit trying this device | |
| 57 current_device_ = nullptr; | |
| 58 Transition(); | |
| 59 break; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 } // namespace device | |
| OLD | NEW |