| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/perf_util.h" | 6 #include "base/perf_util.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "crypto/mock_apple_keychain.h" | 8 #include "crypto/mock_apple_keychain.h" |
| 9 | 9 |
| 10 namespace crypto { | 10 namespace crypto { |
| 11 | 11 |
| 12 OSStatus MockAppleKeychain::FindGenericPassword( | 12 OSStatus MockAppleKeychain::FindGenericPassword( |
| 13 CFTypeRef keychainOrArray, | 13 CFTypeRef keychainOrArray, |
| 14 UInt32 serviceNameLength, | 14 UInt32 serviceNameLength, |
| 15 const char* serviceName, | 15 const char* serviceName, |
| 16 UInt32 accountNameLength, | 16 UInt32 accountNameLength, |
| 17 const char* accountName, | 17 const char* accountName, |
| 18 UInt32* passwordLength, | 18 UInt32* passwordLength, |
| 19 void** passwordData, | 19 void** passwordData, |
| 20 SecKeychainItemRef* itemRef) const { | 20 SecKeychainItemRef* itemRef) const { |
| 21 // Through manual testing, each call to SecKeychainFindGenericPassword takes | 21 // Through manual testing, each call to SecKeychainFindGenericPassword takes |
| 22 // 4.6ms with a SSD, 3 GHz Intel Xeon. On a slower processor with a HDD, this | 22 // 4.6ms with a SSD, 3 GHz Intel Xeon. On a slower processor with a HDD, this |
| 23 // probably takes 4x as long. | 23 // probably takes 4x as long. |
| 24 base::SpinCpuMicroseconds(18400); | 24 base::SpinCpuMicroseconds(18400); |
| 25 base::EmitAccessKeychainHistogram(); |
| 25 | 26 |
| 26 // When simulating |noErr|, return canned |passwordData| and | 27 // When simulating |noErr|, return canned |passwordData| and |
| 27 // |passwordLength|. Otherwise, just return given code. | 28 // |passwordLength|. Otherwise, just return given code. |
| 28 if (find_generic_result_ == noErr) { | 29 if (find_generic_result_ == noErr) { |
| 29 static const char kPassword[] = "my_password"; | 30 static const char kPassword[] = "my_password"; |
| 30 DCHECK(passwordData); | 31 DCHECK(passwordData); |
| 31 // The function to free this data is mocked so the cast is fine. | 32 // The function to free this data is mocked so the cast is fine. |
| 32 *passwordData = const_cast<char*>(kPassword); | 33 *passwordData = const_cast<char*>(kPassword); |
| 33 DCHECK(passwordLength); | 34 DCHECK(passwordLength); |
| 34 *passwordLength = arraysize(kPassword); | 35 *passwordLength = arraysize(kPassword); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 const char* serviceName, | 52 const char* serviceName, |
| 52 UInt32 accountNameLength, | 53 UInt32 accountNameLength, |
| 53 const char* accountName, | 54 const char* accountName, |
| 54 UInt32 passwordLength, | 55 UInt32 passwordLength, |
| 55 const void* passwordData, | 56 const void* passwordData, |
| 56 SecKeychainItemRef* itemRef) const { | 57 SecKeychainItemRef* itemRef) const { |
| 57 // Through manual testing, each call to SecKeychainAddGenericPassword takes | 58 // Through manual testing, each call to SecKeychainAddGenericPassword takes |
| 58 // 6ms with a SSD, 3 GHz Intel Xeon. On a slower processor with a HDD, this | 59 // 6ms with a SSD, 3 GHz Intel Xeon. On a slower processor with a HDD, this |
| 59 // probably takes 4x as long. | 60 // probably takes 4x as long. |
| 60 base::SpinCpuMicroseconds(24000); | 61 base::SpinCpuMicroseconds(24000); |
| 62 base::EmitAccessKeychainHistogram(); |
| 61 | 63 |
| 62 called_add_generic_ = true; | 64 called_add_generic_ = true; |
| 63 | 65 |
| 64 DCHECK_GT(passwordLength, 0U); | 66 DCHECK_GT(passwordLength, 0U); |
| 65 DCHECK(passwordData); | 67 DCHECK(passwordData); |
| 66 add_generic_password_ = | 68 add_generic_password_ = |
| 67 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), | 69 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), |
| 68 passwordLength); | 70 passwordLength); |
| 69 return noErr; | 71 return noErr; |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace crypto | 74 } // namespace crypto |
| OLD | NEW |