Use PlaybackToMemory for BitmapRasterWorkerPool playback
[chromium-blink-merge.git] / chromeos / tpm_token_info_getter.h
blobdd3d5109187bb650831c7a6d63a895896682740f
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_TPM_TOKEN_INFO_GETTER_H_
6 #define CHROMEOS_TPM_TOKEN_INFO_GETTER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_method_call_status.h"
17 namespace base {
18 class TaskRunner;
21 namespace chromeos {
22 class CryptohomeClient;
25 namespace chromeos {
27 // Information retrieved from cryptohome by TPMTokenInfoGetter.
28 struct TPMTokenInfo {
29 // Default constructor creates token info for disabled TPM.
30 TPMTokenInfo();
31 ~TPMTokenInfo();
33 bool tpm_is_enabled;
34 std::string token_name;
35 std::string user_pin;
36 int token_slot_id;
39 // Class for getting a user or the system TPM token info from cryptohome during
40 // TPM token loading.
41 class CHROMEOS_EXPORT TPMTokenInfoGetter {
42 public:
43 using TPMTokenInfoCallback = base::Callback<void(const TPMTokenInfo& info)>;
45 // Factory method for TPMTokenInfoGetter for a user token.
46 static scoped_ptr<TPMTokenInfoGetter> CreateForUserToken(
47 const std::string& user_id,
48 CryptohomeClient* cryptohome_client,
49 const scoped_refptr<base::TaskRunner>& delayed_task_runner);
51 // Factory method for TPMTokenGetter for the system token.
52 static scoped_ptr<TPMTokenInfoGetter> CreateForSystemToken(
53 CryptohomeClient* cryptohome_client,
54 const scoped_refptr<base::TaskRunner>& delayed_task_runner);
56 ~TPMTokenInfoGetter();
58 // Starts getting TPM token info. Should be called at most once.
59 // |callback| will be called when all the info is fetched.
60 // The object may get deleted before |callback| is called, which is equivalent
61 // to cancelling the info getting (in which case |callback| will never get
62 // called).
63 void Start(const TPMTokenInfoCallback& callback);
65 private:
66 enum Type {
67 TYPE_SYSTEM,
68 TYPE_USER
71 enum State {
72 STATE_INITIAL,
73 STATE_STARTED,
74 STATE_TPM_ENABLED,
75 STATE_DONE
78 TPMTokenInfoGetter(
79 Type type,
80 const std::string& user_id,
81 CryptohomeClient* cryptohome_client,
82 const scoped_refptr<base::TaskRunner>& delayed_task_runner);
84 // Continues TPM token info getting procedure by starting the task associated
85 // with the current TPMTokenInfoGetter state.
86 void Continue();
88 // If token initialization step fails (e.g. if tpm token is not yet ready)
89 // schedules the initialization step retry attempt after a timeout.
90 void RetryLater();
92 // Cryptohome methods callbacks.
93 void OnTpmIsEnabled(DBusMethodCallStatus call_status,
94 bool tpm_is_enabled);
95 void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status,
96 const std::string& token_name,
97 const std::string& user_pin,
98 int token_slot_id);
100 // The task runner used to run delayed tasks when retrying failed Cryptohome
101 // calls.
102 scoped_refptr<base::TaskRunner> delayed_task_runner_;
104 Type type_;
105 State state_;
107 // The user id associated with the TPMTokenInfoGetter. Empty for system token.
108 std::string user_id_;
110 TPMTokenInfoCallback callback_;
112 // The current request delay before the next attempt to initialize the
113 // TPM. Will be adapted after each attempt.
114 base::TimeDelta tpm_request_delay_;
116 CryptohomeClient* cryptohome_client_;
118 base::WeakPtrFactory<TPMTokenInfoGetter> weak_factory_;
120 DISALLOW_COPY_AND_ASSIGN(TPMTokenInfoGetter);
123 } // namespace chromeos
125 #endif // CHROMEOS_TPM_TOKEN_INFO_GETTER_H_