| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/tpm/tpm_token_info_getter.h" | 5 #include "chromeos/tpm/tpm_token_info_getter.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "chromeos/dbus/cryptohome_client.h" | 11 #include "chromeos/dbus/cryptohome_client.h" |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 | 14 |
| 13 const int64 kInitialRequestDelayMs = 100; | 15 const int64_t kInitialRequestDelayMs = 100; |
| 14 const int64 kMaxRequestDelayMs = 300000; // 5 minutes | 16 const int64_t kMaxRequestDelayMs = 300000; // 5 minutes |
| 15 | 17 |
| 16 // Calculates the delay before running next attempt to initiatialize the TPM | 18 // Calculates the delay before running next attempt to initiatialize the TPM |
| 17 // token, if |last_delay| was the last or initial delay. | 19 // token, if |last_delay| was the last or initial delay. |
| 18 base::TimeDelta GetNextRequestDelayMs(base::TimeDelta last_delay) { | 20 base::TimeDelta GetNextRequestDelayMs(base::TimeDelta last_delay) { |
| 19 // This implements an exponential backoff, as we don't know in which order of | 21 // This implements an exponential backoff, as we don't know in which order of |
| 20 // magnitude the TPM token changes it's state. | 22 // magnitude the TPM token changes it's state. |
| 21 base::TimeDelta next_delay = last_delay * 2; | 23 base::TimeDelta next_delay = last_delay * 2; |
| 22 | 24 |
| 23 // Cap the delay to prevent an overflow. This threshold is arbitrarily chosen. | 25 // Cap the delay to prevent an overflow. This threshold is arbitrarily chosen. |
| 24 const base::TimeDelta max_delay = | 26 const base::TimeDelta max_delay = |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 TPMTokenInfo token_info; | 155 TPMTokenInfo token_info; |
| 154 token_info.tpm_is_enabled = true; | 156 token_info.tpm_is_enabled = true; |
| 155 token_info.token_name = token_name; | 157 token_info.token_name = token_name; |
| 156 token_info.user_pin = user_pin; | 158 token_info.user_pin = user_pin; |
| 157 token_info.token_slot_id = token_slot_id; | 159 token_info.token_slot_id = token_slot_id; |
| 158 | 160 |
| 159 callback_.Run(token_info); | 161 callback_.Run(token_info); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace chromeos | 164 } // namespace chromeos |
| OLD | NEW |