Index: tools/metrics/histograms/update_extension_permission.py |
diff --git a/tools/metrics/histograms/update_extension_permission.py b/tools/metrics/histograms/update_extension_permission.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..20a078c9932d62ae9748ca49cf98aaad90e24374 |
--- /dev/null |
+++ b/tools/metrics/histograms/update_extension_permission.py |
@@ -0,0 +1,34 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+'''Updates ExtensionPermission enum in histograms.xml file with values read from |
+permission_message.h. |
+ |
+If the file was pretty-printed, the updated version is pretty-printed too. |
+''' |
+ |
+import re |
+ |
+from update_histogram_enum import UpdateHistogramEnum |
+ |
+def StyleLabel(label): |
+ '''Transforms labels of form "kLabelName" to "LABEL_NAME" |
Ilya Sherman
2014/03/10 22:21:54
Why is this transformation useful? Why not just u
ahernandez
2014/03/13 19:11:25
The ExtensionPermission enum already has it's entr
|
+ ''' |
+ uiIndex = label.find('UI') |
+ pattern = '([A-Z])' |
+ |
+ assert label.startswith('k') and label[1].isupper() |
+ |
+ if uiIndex != -1 and label[uiIndex - 1].islower(): |
+ pattern = '([A-HJ-Z])' |
Jeffrey Yasskin
2014/03/10 20:53:23
This looks flaky: Consider (and test!) "kUIWasIsol
|
+ |
+ return label[1] + re.sub(pattern, r'_\1', label[2:]).upper() |
+ |
+if __name__ == '__main__': |
+ UpdateHistogramEnum(histogram_enum_name='ExtensionPermission', |
+ source_enum_path=('../../../extensions/common/permissions' |
Ilya Sherman
2014/03/10 22:21:54
Have you verified that the forward slashes work on
|
+ '/permission_message.h'), |
Ilya Sherman
2014/03/10 22:21:54
nit: Why does this string start with a slash?
|
+ start_marker='^enum ID {', |
+ end_marker='^kEnumBoundary', |
+ labelTransformer=StyleLabel) |