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

Side by Side Diff: crypto/mock_apple_keychain.cc

Issue 714273004: mac: Expose keychain access frequency to Telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mock_keychain_sleep
Patch Set: Move GetEncryptionPassword so that it gets compiled on iOS. Created 5 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « crypto/mock_apple_keychain.h ('k') | tools/perf/benchmarks/speedometer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/histogram.h"
6 #include "base/time/time.h" 7 #include "base/time/time.h"
7 #include "crypto/mock_apple_keychain.h" 8 #include "crypto/mock_apple_keychain.h"
8 9
10 namespace {
11
12 // Adds an entry to a local histogram to indicate that the Apple Keychain would
13 // have been accessed, if this class were not a mock of the Apple Keychain.
14 void IncrementKeychainAccessHistogram() {
15 // This local histogram is accessed by Telemetry to track the number of times
16 // the keychain is accessed, since keychain access is known to be synchronous
17 // and slow.
18 LOCAL_HISTOGRAM_BOOLEAN("OSX.Keychain.Access", true);
19 }
20
21 } // namespace
22
9 namespace crypto { 23 namespace crypto {
10 24
11 OSStatus MockAppleKeychain::FindGenericPassword( 25 OSStatus MockAppleKeychain::FindGenericPassword(
12 CFTypeRef keychainOrArray, 26 CFTypeRef keychainOrArray,
13 UInt32 serviceNameLength, 27 UInt32 serviceNameLength,
14 const char* serviceName, 28 const char* serviceName,
15 UInt32 accountNameLength, 29 UInt32 accountNameLength,
16 const char* accountName, 30 const char* accountName,
17 UInt32* passwordLength, 31 UInt32* passwordLength,
18 void** passwordData, 32 void** passwordData,
19 SecKeychainItemRef* itemRef) const { 33 SecKeychainItemRef* itemRef) const {
34 IncrementKeychainAccessHistogram();
35
20 // When simulating |noErr|, return canned |passwordData| and 36 // When simulating |noErr|, return canned |passwordData| and
21 // |passwordLength|. Otherwise, just return given code. 37 // |passwordLength|. Otherwise, just return given code.
22 if (find_generic_result_ == noErr) { 38 if (find_generic_result_ == noErr) {
23 static const char kPassword[] = "my_password"; 39 static const char kPassword[] = "my_password";
24 DCHECK(passwordData); 40 DCHECK(passwordData);
25 // The function to free this data is mocked so the cast is fine. 41 // The function to free this data is mocked so the cast is fine.
26 *passwordData = const_cast<char*>(kPassword); 42 *passwordData = const_cast<char*>(kPassword);
27 DCHECK(passwordLength); 43 DCHECK(passwordLength);
28 *passwordLength = arraysize(kPassword); 44 *passwordLength = arraysize(kPassword);
29 password_data_count_++; 45 password_data_count_++;
(...skipping 11 matching lines...) Expand all
41 57
42 OSStatus MockAppleKeychain::AddGenericPassword( 58 OSStatus MockAppleKeychain::AddGenericPassword(
43 SecKeychainRef keychain, 59 SecKeychainRef keychain,
44 UInt32 serviceNameLength, 60 UInt32 serviceNameLength,
45 const char* serviceName, 61 const char* serviceName,
46 UInt32 accountNameLength, 62 UInt32 accountNameLength,
47 const char* accountName, 63 const char* accountName,
48 UInt32 passwordLength, 64 UInt32 passwordLength,
49 const void* passwordData, 65 const void* passwordData,
50 SecKeychainItemRef* itemRef) const { 66 SecKeychainItemRef* itemRef) const {
67 IncrementKeychainAccessHistogram();
68
51 called_add_generic_ = true; 69 called_add_generic_ = true;
52 70
53 DCHECK_GT(passwordLength, 0U); 71 DCHECK_GT(passwordLength, 0U);
54 DCHECK(passwordData); 72 DCHECK(passwordData);
55 add_generic_password_ = 73 add_generic_password_ =
56 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), 74 std::string(const_cast<char*>(static_cast<const char*>(passwordData)),
57 passwordLength); 75 passwordLength);
58 return noErr; 76 return noErr;
59 } 77 }
60 78
79 std::string MockAppleKeychain::GetEncryptionPassword() const {
80 IncrementKeychainAccessHistogram();
81 return "mock_password";
82 }
83
61 } // namespace crypto 84 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/mock_apple_keychain.h ('k') | tools/perf/benchmarks/speedometer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698