| 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 #ifndef CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 5 #ifndef CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
| 6 #define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 6 #define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/chromeos_export.h" | 16 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 16 | 18 |
| 17 namespace chromeos { | 19 namespace chromeos { |
| 18 | 20 |
| 19 // This class is used to get the system salt from cryptohome and cache it. | 21 // This class is used to get the system salt from cryptohome and cache it. |
| 20 class CHROMEOS_EXPORT SystemSaltGetter { | 22 class CHROMEOS_EXPORT SystemSaltGetter { |
| 21 public: | 23 public: |
| 22 typedef base::Callback<void(const std::string& system_salt)> | 24 typedef base::Callback<void(const std::string& system_salt)> |
| 23 GetSystemSaltCallback; | 25 GetSystemSaltCallback; |
| 24 | 26 |
| 25 // Manage an explicitly initialized global instance. | 27 // Manage an explicitly initialized global instance. |
| 26 static void Initialize(); | 28 static void Initialize(); |
| 27 static bool IsInitialized(); | 29 static bool IsInitialized(); |
| 28 static void Shutdown(); | 30 static void Shutdown(); |
| 29 static SystemSaltGetter* Get(); | 31 static SystemSaltGetter* Get(); |
| 30 | 32 |
| 31 // Converts |salt| to a hex encoded string. | 33 // Converts |salt| to a hex encoded string. |
| 32 static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt); | 34 static std::string ConvertRawSaltToHexString( |
| 35 const std::vector<uint8_t>& salt); |
| 33 | 36 |
| 34 // Returns system hash in hex encoded ascii format. Note: this may return | 37 // Returns system hash in hex encoded ascii format. Note: this may return |
| 35 // an empty string (e.g. errors in D-Bus layer) | 38 // an empty string (e.g. errors in D-Bus layer) |
| 36 void GetSystemSalt(const GetSystemSaltCallback& callback); | 39 void GetSystemSalt(const GetSystemSaltCallback& callback); |
| 37 | 40 |
| 38 protected: | 41 protected: |
| 39 SystemSaltGetter(); | 42 SystemSaltGetter(); |
| 40 ~SystemSaltGetter(); | 43 ~SystemSaltGetter(); |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 // Used to implement GetSystemSalt(). | 46 // Used to implement GetSystemSalt(). |
| 44 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, | 47 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, |
| 45 bool service_is_available); | 48 bool service_is_available); |
| 46 void DidGetSystemSalt(const GetSystemSaltCallback& callback, | 49 void DidGetSystemSalt(const GetSystemSaltCallback& callback, |
| 47 DBusMethodCallStatus call_status, | 50 DBusMethodCallStatus call_status, |
| 48 const std::vector<uint8>& system_salt); | 51 const std::vector<uint8_t>& system_salt); |
| 49 | 52 |
| 50 std::string system_salt_; | 53 std::string system_salt_; |
| 51 | 54 |
| 52 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; | 55 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; |
| 53 | 56 |
| 54 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); | 57 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); |
| 55 }; | 58 }; |
| 56 | 59 |
| 57 } // namespace chromeos | 60 } // namespace chromeos |
| 58 | 61 |
| 59 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 62 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
| OLD | NEW |