Roll src/third_party/WebKit 75a2fa9:2546356 (svn 202272:202273)
[chromium-blink-merge.git] / crypto / capi_util.cc
blob1a3e139b50e0bd309efcb7d4f2f18d2d0c21f3d4
1 // Copyright (c) 2011 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 "crypto/capi_util.h"
7 #include "base/basictypes.h"
8 #include "base/memory/singleton.h"
9 #include "base/synchronization/lock.h"
11 namespace {
13 class CAPIUtilSingleton {
14 public:
15 static CAPIUtilSingleton* GetInstance() {
16 return base::Singleton<CAPIUtilSingleton>::get();
19 // Returns a lock to guard calls to CryptAcquireContext with
20 // CRYPT_DELETEKEYSET or CRYPT_NEWKEYSET.
21 base::Lock& acquire_context_lock() {
22 return acquire_context_lock_;
25 private:
26 friend class base::Singleton<CAPIUtilSingleton>;
27 friend struct base::DefaultSingletonTraits<CAPIUtilSingleton>;
29 CAPIUtilSingleton() {}
31 base::Lock acquire_context_lock_;
33 DISALLOW_COPY_AND_ASSIGN(CAPIUtilSingleton);
36 } // namespace
38 namespace crypto {
40 BOOL CryptAcquireContextLocked(HCRYPTPROV* prov,
41 LPCWSTR container,
42 LPCWSTR provider,
43 DWORD prov_type,
44 DWORD flags) {
45 base::AutoLock lock(CAPIUtilSingleton::GetInstance()->acquire_context_lock());
46 return CryptAcquireContext(prov, container, provider, prov_type, flags);
49 void* WINAPI CryptAlloc(size_t size) {
50 return malloc(size);
53 void WINAPI CryptFree(void* p) {
54 free(p);
57 } // namespace crypto