| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Extract UserMetrics "actions" strings from the Chrome source. | 7 """Extract UserMetrics "actions" strings from the Chrome source. |
| 8 | 8 |
| 9 This program generates the list of known actions we expect to see in the | 9 This program generates the list of known actions we expect to see in the |
| 10 user behavior logs. It walks the Chrome source, looking for calls to | 10 user behavior logs. It walks the Chrome source, looking for calls to |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 # generate the known actions to AddComputedActions() below. | 84 # generate the known actions to AddComputedActions() below. |
| 85 KNOWN_COMPUTED_USERS = ( | 85 KNOWN_COMPUTED_USERS = ( |
| 86 'back_forward_menu_model.cc', | 86 'back_forward_menu_model.cc', |
| 87 'options_page_view.cc', | 87 'options_page_view.cc', |
| 88 'render_view_host.cc', # called using webkit identifiers | 88 'render_view_host.cc', # called using webkit identifiers |
| 89 'user_metrics.cc', # method definition | 89 'user_metrics.cc', # method definition |
| 90 'new_tab_ui.cc', # most visited clicks 1-9 | 90 'new_tab_ui.cc', # most visited clicks 1-9 |
| 91 'extension_metrics_module.cc', # extensions hook for user metrics | 91 'extension_metrics_module.cc', # extensions hook for user metrics |
| 92 'language_options_handler_common.cc', # languages and input methods in CrOS | 92 'language_options_handler_common.cc', # languages and input methods in CrOS |
| 93 'cros_language_options_handler.cc', # languages and input methods in CrOS | 93 'cros_language_options_handler.cc', # languages and input methods in CrOS |
| 94 'about_flags.cc', # do not generate a warning; see AddAboutFlagsActions() | |
| 95 'external_metrics.cc', # see AddChromeOSActions() | 94 'external_metrics.cc', # see AddChromeOSActions() |
| 96 'core_options_handler.cc', # see AddWebUIActions() | 95 'core_options_handler.cc', # see AddWebUIActions() |
| 97 'browser_render_process_host.cc', # see AddRendererActions() | 96 'browser_render_process_host.cc', # see AddRendererActions() |
| 98 'render_thread_impl.cc', # impl of RenderThread::RecordComputedAction() | 97 'render_thread_impl.cc', # impl of RenderThread::RecordComputedAction() |
| 99 'render_process_host_impl.cc', # browser side impl for | 98 'render_process_host_impl.cc', # browser side impl for |
| 100 # RenderThread::RecordComputedAction() | 99 # RenderThread::RecordComputedAction() |
| 101 'mock_render_thread.cc', # mock of RenderThread::RecordComputedAction() | 100 'mock_render_thread.cc', # mock of RenderThread::RecordComputedAction() |
| 102 'ppb_pdf_impl.cc', # see AddClosedSourceActions() | 101 'ppb_pdf_impl.cc', # see AddClosedSourceActions() |
| 103 'pepper_pdf_host.cc', # see AddClosedSourceActions() | 102 'pepper_pdf_host.cc', # see AddClosedSourceActions() |
| 104 'record_user_action.cc', # see RecordUserAction.java | 103 'record_user_action.cc', # see RecordUserAction.java |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 actions.add('MostVisited%d' % i) | 188 actions.add('MostVisited%d' % i) |
| 190 | 189 |
| 191 # Actions for language_options_handler.cc (Chrome OS specific). | 190 # Actions for language_options_handler.cc (Chrome OS specific). |
| 192 for input_method_id in INPUT_METHOD_IDS: | 191 for input_method_id in INPUT_METHOD_IDS: |
| 193 actions.add('LanguageOptions_DisableInputMethod_%s' % input_method_id) | 192 actions.add('LanguageOptions_DisableInputMethod_%s' % input_method_id) |
| 194 actions.add('LanguageOptions_EnableInputMethod_%s' % input_method_id) | 193 actions.add('LanguageOptions_EnableInputMethod_%s' % input_method_id) |
| 195 for language_code in LANGUAGE_CODES: | 194 for language_code in LANGUAGE_CODES: |
| 196 actions.add('LanguageOptions_UiLanguageChange_%s' % language_code) | 195 actions.add('LanguageOptions_UiLanguageChange_%s' % language_code) |
| 197 actions.add('LanguageOptions_SpellCheckLanguageChange_%s' % language_code) | 196 actions.add('LanguageOptions_SpellCheckLanguageChange_%s' % language_code) |
| 198 | 197 |
| 199 def AddWebKitEditorActions(actions): | |
| 200 """Add editor actions from editor_client_impl.cc. | |
| 201 | |
| 202 Arguments: | |
| 203 actions: set of actions to add to. | |
| 204 """ | |
| 205 action_re = re.compile(r'''\{ [\w']+, +\w+, +"(.*)" +\},''') | |
| 206 | |
| 207 editor_file = os.path.join(REPOSITORY_ROOT, 'webkit', 'api', 'src', | |
| 208 'EditorClientImpl.cc') | |
| 209 for line in open(editor_file): | |
| 210 match = action_re.search(line) | |
| 211 if match: # Plain call to RecordAction | |
| 212 actions.add(match.group(1)) | |
| 213 | 198 |
| 214 def AddPDFPluginActions(actions): | 199 def AddPDFPluginActions(actions): |
| 215 """Add actions that are sent by the PDF plugin. | 200 """Add actions that are sent by the PDF plugin. |
| 216 | 201 |
| 217 Arguments | 202 Arguments |
| 218 actions: set of actions to add to. | 203 actions: set of actions to add to. |
| 219 """ | 204 """ |
| 220 actions.add('PDF.LoadFailure') | 205 actions.add('PDF.LoadFailure') |
| 221 actions.add('PDF.LoadSuccess') | 206 actions.add('PDF.LoadSuccess') |
| 222 actions.add('PDF.PreviewDocumentLoadFailure') | 207 actions.add('PDF.PreviewDocumentLoadFailure') |
| 223 actions.add('PDF.PrintPage') | 208 actions.add('PDF.PrintPage') |
| 224 actions.add('PDF.ZoomFromBrowser') | 209 actions.add('PDF.ZoomFromBrowser') |
| 225 actions.add('PDF_Unsupported_3D') | 210 actions.add('PDF_Unsupported_3D') |
| 226 actions.add('PDF_Unsupported_Attachment') | 211 actions.add('PDF_Unsupported_Attachment') |
| 227 actions.add('PDF_Unsupported_Bookmarks') | 212 actions.add('PDF_Unsupported_Bookmarks') |
| 228 actions.add('PDF_Unsupported_Digital_Signature') | 213 actions.add('PDF_Unsupported_Digital_Signature') |
| 229 actions.add('PDF_Unsupported_Movie') | 214 actions.add('PDF_Unsupported_Movie') |
| 230 actions.add('PDF_Unsupported_Portfolios_Packages') | 215 actions.add('PDF_Unsupported_Portfolios_Packages') |
| 231 actions.add('PDF_Unsupported_Rights_Management') | 216 actions.add('PDF_Unsupported_Rights_Management') |
| 232 actions.add('PDF_Unsupported_Screen') | 217 actions.add('PDF_Unsupported_Screen') |
| 233 actions.add('PDF_Unsupported_Shared_Form') | 218 actions.add('PDF_Unsupported_Shared_Form') |
| 234 actions.add('PDF_Unsupported_Shared_Review') | 219 actions.add('PDF_Unsupported_Shared_Review') |
| 235 actions.add('PDF_Unsupported_Sound') | 220 actions.add('PDF_Unsupported_Sound') |
| 236 actions.add('PDF_Unsupported_XFA') | 221 actions.add('PDF_Unsupported_XFA') |
| 237 | 222 |
| 238 def AddAboutFlagsActions(actions): | |
| 239 """This parses the experimental feature flags for UMA actions. | |
| 240 | |
| 241 Arguments: | |
| 242 actions: set of actions to add to. | |
| 243 """ | |
| 244 about_flags = os.path.join(REPOSITORY_ROOT, 'chrome', 'browser', | |
| 245 'about_flags.cc') | |
| 246 flag_name_re = re.compile(r'\s*"([0-9a-zA-Z\-_]+)",\s*// FLAGS:RECORD_UMA') | |
| 247 for line in open(about_flags): | |
| 248 match = flag_name_re.search(line) | |
| 249 if match: | |
| 250 actions.add("AboutFlags_" + match.group(1)) | |
| 251 # If the line contains the marker but was not matched by the regex, put up | |
| 252 # an error if the line is not a comment. | |
| 253 elif 'FLAGS:RECORD_UMA' in line and line[0:2] != '//': | |
| 254 print >>sys.stderr, 'WARNING: This line is marked for recording ' + \ | |
| 255 'about:flags metrics, but is not in the proper format:\n' + line | |
| 256 | |
| 257 def AddBookmarkManagerActions(actions): | 223 def AddBookmarkManagerActions(actions): |
| 258 """Add actions that are used by BookmarkManager. | 224 """Add actions that are used by BookmarkManager. |
| 259 | 225 |
| 260 Arguments | 226 Arguments |
| 261 actions: set of actions to add to. | 227 actions: set of actions to add to. |
| 262 """ | 228 """ |
| 263 actions.add('BookmarkManager_Command_AddPage') | 229 actions.add('BookmarkManager_Command_AddPage') |
| 264 actions.add('BookmarkManager_Command_Copy') | 230 actions.add('BookmarkManager_Command_Copy') |
| 265 actions.add('BookmarkManager_Command_Cut') | 231 actions.add('BookmarkManager_Command_Cut') |
| 266 actions.add('BookmarkManager_Command_Delete') | 232 actions.add('BookmarkManager_Command_Delete') |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 actions_element.appendChild( | 713 actions_element.appendChild( |
| 748 _CreateActionTag(doc, action, actions_dict.get(action, None))) | 714 _CreateActionTag(doc, action, actions_dict.get(action, None))) |
| 749 | 715 |
| 750 return print_style.GetPrintStyle().PrettyPrintNode(doc) | 716 return print_style.GetPrintStyle().PrettyPrintNode(doc) |
| 751 | 717 |
| 752 | 718 |
| 753 def UpdateXml(original_xml): | 719 def UpdateXml(original_xml): |
| 754 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) | 720 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) |
| 755 | 721 |
| 756 AddComputedActions(actions) | 722 AddComputedActions(actions) |
| 757 # TODO(fmantek): bring back webkit editor actions. | |
| 758 # AddWebKitEditorActions(actions) | |
| 759 AddAboutFlagsActions(actions) | |
| 760 AddWebUIActions(actions) | 723 AddWebUIActions(actions) |
| 761 | 724 |
| 762 AddLiteralActions(actions) | 725 AddLiteralActions(actions) |
| 763 | 726 |
| 764 # print "Scanned {0} number of files".format(number_of_files_total) | 727 # print "Scanned {0} number of files".format(number_of_files_total) |
| 765 # print "Found {0} entries".format(len(actions)) | 728 # print "Found {0} entries".format(len(actions)) |
| 766 | 729 |
| 767 AddAutomaticResetBannerActions(actions) | 730 AddAutomaticResetBannerActions(actions) |
| 768 AddBookmarkManagerActions(actions) | 731 AddBookmarkManagerActions(actions) |
| 769 AddChromeOSActions(actions) | 732 AddChromeOSActions(actions) |
| 770 AddExtensionActions(actions) | 733 AddExtensionActions(actions) |
| 771 AddHistoryPageActions(actions) | 734 AddHistoryPageActions(actions) |
| 772 AddPDFPluginActions(actions) | 735 AddPDFPluginActions(actions) |
| 773 | 736 |
| 774 return PrettyPrint(actions, actions_dict, comment_nodes) | 737 return PrettyPrint(actions, actions_dict, comment_nodes) |
| 775 | 738 |
| 776 | 739 |
| 777 def main(argv): | 740 def main(argv): |
| 778 presubmit_util.DoPresubmitMain(argv, 'actions.xml', 'actions.old.xml', | 741 presubmit_util.DoPresubmitMain(argv, 'actions.xml', 'actions.old.xml', |
| 779 'extract_actions.py', UpdateXml) | 742 'extract_actions.py', UpdateXml) |
| 780 | 743 |
| 781 if '__main__' == __name__: | 744 if '__main__' == __name__: |
| 782 sys.exit(main(sys.argv)) | 745 sys.exit(main(sys.argv)) |
| OLD | NEW |