Add UMA to identify where a hotword trigger comes from.
[chromium-blink-merge.git] / chromeos / tpm_password_fetcher.h
blob71a4fc2d3af9cf68ecb1c3b96e79eee502e3e9fa
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_PASSWORD_FETCHER_H_
6 #define CHROMEOS_TPM_PASSWORD_FETCHER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_method_call_status.h"
15 namespace chromeos {
17 // Interface which TpmPasswordFetcher uses to notify that password has been
18 // fetched.
19 class CHROMEOS_EXPORT TpmPasswordFetcherDelegate {
20 public:
21 virtual ~TpmPasswordFetcherDelegate() {}
22 virtual void OnPasswordFetched(const std::string& tpm_password) = 0;
25 // Class for fetching TPM password from the Cryptohome.
26 class CHROMEOS_EXPORT TpmPasswordFetcher {
27 public:
28 // Creates fetcher with the given delegate to be notified every time fetching
29 // is done.
30 explicit TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate);
31 ~TpmPasswordFetcher();
33 // Fetches TPM password and stores the result. Also notifies |delegate_| with
34 // OnPasswordFetched() call.
35 void Fetch();
37 private:
38 // Used to implement Fetch().
39 void OnTpmIsReady(DBusMethodCallStatus call_status, bool tpm_is_ready);
41 // Used to implement Fetch().
42 void OnTpmGetPassword(DBusMethodCallStatus call_status,
43 const std::string& password);
45 // Posts a task to call Fetch() later.
46 void RescheduleFetch();
48 TpmPasswordFetcherDelegate* delegate_;
50 base::WeakPtrFactory<TpmPasswordFetcher> weak_factory_;
52 DISALLOW_COPY_AND_ASSIGN(TpmPasswordFetcher);
55 } // namespace chromeos
57 #endif // CHROMEOS_TPM_PASSWORD_FETCHER_H_