OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Extract UserMetrics "actions" strings from the Chrome source. | 6 """Extract UserMetrics "actions" strings from the Chrome source. |
7 | 7 |
8 This program generates the list of known actions we expect to see in the | 8 This program generates the list of known actions we expect to see in the |
9 user behavior logs. It walks the Chrome source, looking for calls to | 9 user behavior logs. It walks the Chrome source, looking for calls to |
10 UserMetrics functions, extracting actions and warning on improper calls, | 10 UserMetrics functions, extracting actions and warning on improper calls, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 attrs = dict(attrs) | 277 attrs = dict(attrs) |
278 if not 'metric' in attrs: | 278 if not 'metric' in attrs: |
279 return | 279 return |
280 | 280 |
281 # Boolean metrics have two corresponding actions. All other metrics have | 281 # Boolean metrics have two corresponding actions. All other metrics have |
282 # just one corresponding action. By default, we check the 'dataType' | 282 # just one corresponding action. By default, we check the 'dataType' |
283 # attribute. | 283 # attribute. |
284 is_boolean = ('dataType' in attrs and attrs['dataType'] == 'boolean') | 284 is_boolean = ('dataType' in attrs and attrs['dataType'] == 'boolean') |
285 if 'type' in attrs and attrs['type'] in ('checkbox', 'radio'): | 285 if 'type' in attrs and attrs['type'] in ('checkbox', 'radio'): |
286 if attrs['type'] == 'checkbox': | 286 if attrs['type'] == 'checkbox': |
287 # Checkboxes are boolean by default. However, their 'value-type' can | 287 is_boolean = True |
288 # instead be set to 'integer'. | |
289 if 'value-type' not in attrs or attrs['value-type'] in ['', 'boolean']: | |
290 is_boolean = True | |
291 else: | 288 else: |
292 # Radio buttons are boolean if and only if their values are 'true' or | 289 # Radio buttons are boolean if and only if their values are 'true' or |
293 # 'false'. | 290 # 'false'. |
294 assert(attrs['type'] == 'radio') | 291 assert(attrs['type'] == 'radio') |
295 if 'value' in attrs and attrs['value'] in ['true', 'false']: | 292 if 'value' in attrs and attrs['value'] in ['true', 'false']: |
296 is_boolean = True | 293 is_boolean = True |
297 | 294 |
298 if is_boolean: | 295 if is_boolean: |
299 self.actions.add(attrs['metric'] + '_Enable') | 296 self.actions.add(attrs['metric'] + '_Enable') |
300 self.actions.add(attrs['metric'] + '_Disable') | 297 self.actions.add(attrs['metric'] + '_Disable') |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 else: | 440 else: |
444 print action | 441 print action |
445 | 442 |
446 if hash_output: | 443 if hash_output: |
447 print "Done. Do not forget to add chromeactions.txt to your changelist" | 444 print "Done. Do not forget to add chromeactions.txt to your changelist" |
448 return 0 | 445 return 0 |
449 | 446 |
450 | 447 |
451 if '__main__' == __name__: | 448 if '__main__' == __name__: |
452 sys.exit(main(sys.argv)) | 449 sys.exit(main(sys.argv)) |
OLD | NEW |