Chromecast ATV: distinguish actual shutdown vs. lifecycle from sleep.
[chromium-blink-merge.git] / chromeos / cryptohome / cryptohome_util.cc
blob5e2b310ba631cb417256896aea0bd2cb1130988b
1 // Copyright 2013 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 #include "chromeos/cryptohome/cryptohome_util.h"
7 #include "base/logging.h"
8 #include "chromeos/dbus/cryptohome_client.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
11 namespace chromeos {
12 namespace cryptohome_util {
14 bool TpmIsEnabled() {
15 bool result = false;
16 DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsEnabledAndBlock(
17 &result);
18 return result;
21 bool TpmIsOwned() {
22 bool result = false;
23 DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsOwnedAndBlock(
24 &result);
25 return result;
28 bool TpmIsBeingOwned() {
29 bool result = false;
30 DBusThreadManager::Get()->GetCryptohomeClient()->
31 CallTpmIsBeingOwnedAndBlock(&result);
32 return result;
35 bool InstallAttributesGet(
36 const std::string& name, std::string* value) {
37 std::vector<uint8> buf;
38 bool success = false;
39 DBusThreadManager::Get()->GetCryptohomeClient()->
40 InstallAttributesGet(name, &buf, &success);
41 if (success) {
42 // Cryptohome returns 'buf' with a terminating '\0' character.
43 DCHECK(!buf.empty());
44 DCHECK_EQ(buf.back(), 0);
45 value->assign(reinterpret_cast<char*>(buf.data()), buf.size() - 1);
47 return success;
50 bool InstallAttributesSet(
51 const std::string& name, const std::string& value) {
52 std::vector<uint8> buf(value.c_str(), value.c_str() + value.size() + 1);
53 bool success = false;
54 DBusThreadManager::Get()->GetCryptohomeClient()->
55 InstallAttributesSet(name, buf, &success);
56 return success;
59 bool InstallAttributesFinalize() {
60 bool success = false;
61 DBusThreadManager::Get()->GetCryptohomeClient()->
62 InstallAttributesFinalize(&success);
63 return success;
66 bool InstallAttributesIsInvalid() {
67 bool result = false;
68 DBusThreadManager::Get()->GetCryptohomeClient()->
69 InstallAttributesIsInvalid(&result);
70 return result;
73 bool InstallAttributesIsFirstInstall() {
74 bool result = false;
75 DBusThreadManager::Get()->GetCryptohomeClient()->
76 InstallAttributesIsFirstInstall(&result);
77 return result;
80 } // namespace cryptohome_util
81 } // namespace chromeos