Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_OS_CRYPT_LIBSECRET_UTIL_POSIX_H_ | |
| 6 #define COMPONENTS_OS_CRYPT_LIBSECRET_UTIL_POSIX_H_ | |
| 7 | |
| 8 #include <libsecret/secret.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 | |
| 15 // Utility for dynamically loading libsecret. | |
| 16 class LibsecretLoader { | |
| 17 public: | |
| 18 static decltype(&::secret_password_store_sync) secret_password_store_sync; | |
| 19 static decltype(&::secret_service_search_sync) secret_service_search_sync; | |
| 20 static decltype(&::secret_password_clear_sync) secret_password_clear_sync; | |
| 21 static decltype(&::secret_item_get_secret) secret_item_get_secret; | |
| 22 static decltype(&::secret_value_get_text) secret_value_get_text; | |
| 23 static decltype(&::secret_item_get_attributes) secret_item_get_attributes; | |
| 24 static decltype(&::secret_item_load_secret_sync) secret_item_load_secret_sync; | |
| 25 static decltype(&::secret_value_unref) secret_value_unref; | |
| 26 | |
| 27 // Loads the libsecret binaries and checks that it responds to queries. | |
|
vabr (Chromium)
2016/04/29 13:16:07
nit: Plural "binaries" vs. singular "it". What abo
cfroussios
2016/04/29 14:00:52
Done.
| |
| 28 // False if either step fails. | |
|
vabr (Chromium)
2016/04/29 13:16:07
optional nit: "Returns false" instead of just "fal
cfroussios
2016/04/29 14:00:52
Returns is redundant, but let's go with the norm.
| |
| 29 // Repeated calls check the responsiveness every time, but do not load the | |
| 30 // the library again if already successful. | |
| 31 static bool EnsureLibsecretLoaded() { | |
| 32 return LoadLibsecret() && LibsecretIsAvailable(); | |
|
vabr (Chromium)
2016/04/29 13:16:07
Please do not inline this method, define it in the
cfroussios
2016/04/29 14:00:52
Done.
| |
| 33 } | |
| 34 | |
| 35 protected: | |
| 36 static bool libsecret_loaded; | |
|
vabr (Chromium)
2016/04/29 13:16:07
nit: Even static data members should have a traili
cfroussios
2016/04/29 14:00:52
Done.
| |
| 37 | |
| 38 private: | |
| 39 struct FunctionInfo { | |
| 40 const char* name; | |
| 41 void** pointer; | |
| 42 }; | |
| 43 | |
| 44 static const FunctionInfo functions[]; | |
|
vabr (Chromium)
2016/04/29 13:16:07
nit: This is a constant, so let's call it kFunctio
cfroussios
2016/04/29 14:00:52
Done.
| |
| 45 | |
| 46 // Load the libsecret binaries. Returns true on success. | |
| 47 // If successful, the result is cached and the function can be safely called | |
| 48 // multiple times. | |
| 49 // Checking |LibsecretIsAvailable| is necessary after this to verify that the | |
| 50 // service responds to queries. | |
| 51 static bool LoadLibsecret(); | |
| 52 | |
| 53 // True if the libsecret binaries have been loaded and the library responds | |
| 54 // to queries. | |
| 55 static bool LibsecretIsAvailable(); | |
| 56 | |
| 57 DISALLOW_IMPLICIT_CONSTRUCTORS(LibsecretLoader); | |
| 58 }; | |
| 59 | |
| 60 class LibsecretAttributesBuilder { | |
| 61 public: | |
| 62 LibsecretAttributesBuilder(); | |
| 63 ~LibsecretAttributesBuilder(); | |
| 64 | |
| 65 void Append(const std::string& name, const std::string& value); | |
| 66 | |
| 67 void Append(const std::string& name, int64_t value); | |
| 68 | |
| 69 // GHashTable, its keys and values returned from Get() are destroyed in | |
| 70 // |LibsecretAttributesBuilder| destructor. | |
| 71 GHashTable* Get() { return attrs_; } | |
| 72 | |
| 73 private: | |
| 74 // |name_values_| is a storage for strings referenced in |attrs_|. | |
| 75 std::vector<std::string> name_values_; | |
| 76 GHashTable* attrs_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(LibsecretAttributesBuilder); | |
| 79 }; | |
| 80 | |
| 81 #endif // COMPONENTS_OS_CRYPT_LIBSECRET_UTIL_POSIX_H_ | |
| OLD | NEW |