1 # Copyright 2014 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.
8 from metrics
import Metric
9 from telemetry
.util
.mac
import keychain_helper
10 from telemetry
.value
import histogram_util
11 from telemetry
.value
import scalar
14 class KeychainMetric(Metric
):
15 """KeychainMetric gathers keychain statistics from the browser object.
17 This includes the number of times that the keychain was accessed.
20 DISPLAY_NAME
= 'OSX_Keychain_Access'
21 HISTOGRAM_NAME
= 'OSX.Keychain.Access'
24 def _CheckKeychainConfiguration():
26 On OSX, it is possible for a misconfigured keychain to cause the
27 Telemetry tests to stall. This method confirms that the keychain is in a
28 sane state that will not cause this behavior. Three conditions are checked:
29 - The keychain is unlocked.
30 - The keychain will not auto-lock after a period of time.
31 - The ACLs are correctly configured on the relevant keychain items.
33 warning_suffix
= ('which will cause some Telemetry tests to stall when run'
34 ' on a headless machine (e.g. perf bot).')
35 if keychain_helper
.IsKeychainLocked():
36 logging
.warning('The default keychain is locked, %s', warning_suffix
)
38 if keychain_helper
.DoesKeychainHaveTimeout():
39 logging
.warning('The default keychain is configured to automatically'
40 ' lock itself have a period of time, %s', warning_suffix
)
42 chrome_acl_configured
= (keychain_helper
.
43 IsKeychainConfiguredForBotsWithChrome())
44 chromium_acl_configured
= (keychain_helper
.
45 IsKeychainConfiguredForBotsWithChromium())
46 acl_warning
= ('A commonly used %s key stored in the default keychain does'
47 ' not give decryption access to all applications, %s')
48 if not chrome_acl_configured
:
49 logging
.warning(acl_warning
, 'Chrome', warning_suffix
)
50 if not chromium_acl_configured
:
51 logging
.warning(acl_warning
, 'Chromium', warning_suffix
)
54 def CustomizeBrowserOptions(cls
, options
):
55 """Adds a browser argument that allows for the collection of keychain
56 metrics. Has no effect on non-Mac platforms."""
57 if sys
.platform
!= 'darwin':
60 KeychainMetric
._CheckKeychainConfiguration
()
62 options
.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
64 def AddResults(self
, tab
, results
):
65 """Adds the number of times that the keychain was accessed to |results|.
66 Has no effect on non-Mac platforms."""
67 if sys
.platform
!= 'darwin':
70 access_count
= histogram_util
.GetHistogramSum(
71 histogram_util
.BROWSER_HISTOGRAM
, KeychainMetric
.HISTOGRAM_NAME
, tab
)
72 results
.AddValue(scalar
.ScalarValue(
73 results
.current_page
, KeychainMetric
.DISPLAY_NAME
, 'count',