[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / metrics / keychain_metric.py
blob4950186de78b534df8a93d4b3716bd1c950921de
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.
5 import logging
6 import sys
8 from telemetry.util.mac import keychain_helper
9 from telemetry.value import histogram_util
10 from telemetry.value import scalar
12 from metrics import Metric
15 class KeychainMetric(Metric):
16 """KeychainMetric gathers keychain statistics from the browser object.
18 This includes the number of times that the keychain was accessed.
19 """
21 DISPLAY_NAME = 'OSX_Keychain_Access'
22 HISTOGRAM_NAME = 'OSX.Keychain.Access'
24 @staticmethod
25 def _CheckKeychainConfiguration():
26 """
27 On OSX, it is possible for a misconfigured keychain to cause the
28 Telemetry tests to stall. This method confirms that the keychain is in a
29 sane state that will not cause this behavior. Three conditions are checked:
30 - The keychain is unlocked.
31 - The keychain will not auto-lock after a period of time.
32 - The ACLs are correctly configured on the relevant keychain items.
33 """
34 warning_suffix = ('which will cause some Telemetry tests to stall when run'
35 ' on a headless machine (e.g. perf bot).')
36 if keychain_helper.IsKeychainLocked():
37 logging.warning('The default keychain is locked, %s', warning_suffix)
39 if keychain_helper.DoesKeychainHaveTimeout():
40 logging.warning('The default keychain is configured to automatically'
41 ' lock itself have a period of time, %s', warning_suffix)
43 chrome_acl_configured = (keychain_helper.
44 IsKeychainConfiguredForBotsWithChrome())
45 chromium_acl_configured = (keychain_helper.
46 IsKeychainConfiguredForBotsWithChromium())
47 acl_warning = ('A commonly used %s key stored in the default keychain does'
48 ' not give decryption access to all applications, %s')
49 if not chrome_acl_configured:
50 logging.warning(acl_warning, 'Chrome', warning_suffix)
51 if not chromium_acl_configured:
52 logging.warning(acl_warning, 'Chromium', warning_suffix)
54 @classmethod
55 def CustomizeBrowserOptions(cls, options):
56 """Adds a browser argument that allows for the collection of keychain
57 metrics. Has no effect on non-Mac platforms."""
58 if sys.platform != 'darwin':
59 return
61 KeychainMetric._CheckKeychainConfiguration()
63 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
65 def AddResults(self, tab, results):
66 """Adds the number of times that the keychain was accessed to |results|.
67 Has no effect on non-Mac platforms."""
68 if sys.platform != 'darwin':
69 return
71 access_count = histogram_util.GetHistogramSum(
72 histogram_util.BROWSER_HISTOGRAM, KeychainMetric.HISTOGRAM_NAME, tab)
73 results.AddValue(scalar.ScalarValue(
74 results.current_page, KeychainMetric.DISPLAY_NAME, 'count',
75 access_count))