Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cryptohome/system_salt_getter.h" | 5 #include "chromeos/cryptohome/system_salt_getter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 FROM_HERE, base::Bind(callback, system_salt_)); | 35 FROM_HERE, base::Bind(callback, system_salt_)); |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( | 39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( |
| 40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable, | 40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable, |
| 41 weak_ptr_factory_.GetWeakPtr(), | 41 weak_ptr_factory_.GetWeakPtr(), |
| 42 callback)); | 42 callback)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SystemSaltGetter::AddOnSystemSaltReady(const base::Closure& closure) { | |
| 46 on_system_salt_ready_.push_back(closure); | |
|
Darren Krahn
2016/08/05 18:54:56
Should the closure be called if salt is already av
Alexander Alekseev
2016/08/06 05:00:12
Done.
| |
| 47 } | |
| 48 | |
| 45 const SystemSaltGetter::RawSalt* SystemSaltGetter::GetRawSalt() const { | 49 const SystemSaltGetter::RawSalt* SystemSaltGetter::GetRawSalt() const { |
| 46 return raw_salt_.empty() ? nullptr : &raw_salt_; | 50 return raw_salt_.empty() ? nullptr : &raw_salt_; |
| 47 } | 51 } |
| 48 | 52 |
| 49 void SystemSaltGetter::SetRawSaltForTesting( | 53 void SystemSaltGetter::SetRawSaltForTesting( |
| 50 const SystemSaltGetter::RawSalt& raw_salt) { | 54 const SystemSaltGetter::RawSalt& raw_salt) { |
| 51 raw_salt_ = raw_salt; | 55 raw_salt_ = raw_salt; |
| 52 } | 56 } |
| 53 | 57 |
| 54 void SystemSaltGetter::DidWaitForServiceToBeAvailable( | 58 void SystemSaltGetter::DidWaitForServiceToBeAvailable( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 67 | 71 |
| 68 void SystemSaltGetter::DidGetSystemSalt( | 72 void SystemSaltGetter::DidGetSystemSalt( |
| 69 const GetSystemSaltCallback& callback, | 73 const GetSystemSaltCallback& callback, |
| 70 DBusMethodCallStatus call_status, | 74 DBusMethodCallStatus call_status, |
| 71 const std::vector<uint8_t>& system_salt) { | 75 const std::vector<uint8_t>& system_salt) { |
| 72 if (call_status == DBUS_METHOD_CALL_SUCCESS && | 76 if (call_status == DBUS_METHOD_CALL_SUCCESS && |
| 73 !system_salt.empty() && | 77 !system_salt.empty() && |
| 74 system_salt.size() % 2 == 0U) { | 78 system_salt.size() % 2 == 0U) { |
| 75 raw_salt_ = system_salt; | 79 raw_salt_ = system_salt; |
| 76 system_salt_ = ConvertRawSaltToHexString(system_salt); | 80 system_salt_ = ConvertRawSaltToHexString(system_salt); |
| 81 | |
| 82 std::vector<base::Closure> callbacks; | |
| 83 callbacks.swap(on_system_salt_ready_); | |
| 84 for (const base::Closure& callback : callbacks) { | |
| 85 callback.Run(); | |
| 86 } | |
| 77 } else { | 87 } else { |
| 78 LOG(WARNING) << "System salt not available"; | 88 LOG(WARNING) << "System salt not available"; |
| 79 } | 89 } |
| 80 | 90 |
| 81 callback.Run(system_salt_); | 91 callback.Run(system_salt_); |
| 82 } | 92 } |
| 83 | 93 |
| 84 // static | 94 // static |
| 85 void SystemSaltGetter::Initialize() { | 95 void SystemSaltGetter::Initialize() { |
| 86 CHECK(!g_system_salt_getter); | 96 CHECK(!g_system_salt_getter); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 107 } | 117 } |
| 108 | 118 |
| 109 // static | 119 // static |
| 110 std::string SystemSaltGetter::ConvertRawSaltToHexString( | 120 std::string SystemSaltGetter::ConvertRawSaltToHexString( |
| 111 const std::vector<uint8_t>& salt) { | 121 const std::vector<uint8_t>& salt) { |
| 112 return base::ToLowerASCII( | 122 return base::ToLowerASCII( |
| 113 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); | 123 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); |
| 114 } | 124 } |
| 115 | 125 |
| 116 } // namespace chromeos | 126 } // namespace chromeos |
| OLD | NEW |