Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Unified Diff: components/os_crypt/os_crypt_mac.mm

Issue 2472743002: Make GetEncryptionKey thread-safe (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/os_crypt/os_crypt_mac.mm
diff --git a/components/os_crypt/os_crypt_mac.mm b/components/os_crypt/os_crypt_mac.mm
index 5b97726ae83f4ebe2b183446d3314fbbdd1f50b1..f999d25654e1300bf7a5f239f7a7dc1f3fac57b7 100644
--- a/components/os_crypt/os_crypt_mac.mm
+++ b/components/os_crypt/os_crypt_mac.mm
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
@@ -40,14 +41,16 @@ static bool use_mock_keychain = false;
// this and migrate to different encryption without data loss.
const char kEncryptionVersionPrefix[] = "v10";
+// This lock is used to make the GetEncrytionKey method thread-safe.
+base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
+
// Generates a newly allocated SymmetricKey object based on the password found
// in the Keychain. The generated key is for AES encryption. Returns NULL key
// in the case password access is denied or key generation error occurs.
crypto::SymmetricKey* GetEncryptionKey() {
static crypto::SymmetricKey* cached_encryption_key = NULL;
static bool key_is_cached = false;
- static base::Lock lock;
- base::AutoLock auto_lock(lock);
+ base::AutoLock auto_lock(g_lock.Get());
if (key_is_cached)
return cached_encryption_key;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698