diff options
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/extensions/dispatcher.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/pepper/pepper_pdf_host.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/pepper/ppb_pdf_impl.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/plugins/chrome_plugin_placeholder.cc | 5 | ||||
-rw-r--r-- | components/plugins/renderer/plugin_placeholder.cc | 7 | ||||
-rw-r--r-- | content/content_common.gypi | 1 | ||||
-rw-r--r-- | content/public/browser/user_metrics.h | 10 | ||||
-rw-r--r-- | content/public/common/user_metrics_action.h | 29 | ||||
-rw-r--r-- | content/public/renderer/render_thread.h | 19 | ||||
-rw-r--r-- | content/public/test/mock_render_thread.cc | 5 | ||||
-rw-r--r-- | content/public/test/mock_render_thread.h | 3 | ||||
-rw-r--r-- | content/renderer/npapi/webplugin_impl.cc | 3 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.cc | 6 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.h | 3 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rwxr-xr-x | tools/metrics/actions/extract_actions.py | 46 |
17 files changed, 89 insertions, 67 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index dfbab66..26c2e49 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -115,6 +115,7 @@ using autofill::AutofillAgent; using autofill::PasswordAutofillAgent; using autofill::PasswordGenerationAgent; using content::RenderThread; +using content::UserMetricsAction; using content::WebPluginInfo; using extensions::Extension; using blink::WebCache; @@ -663,7 +664,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( return render_view->CreatePlugin(frame, plugin, params); } case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: { - RenderThread::Get()->RecordUserMetrics("Plugin_NPAPINotSupported"); + RenderThread::Get()->RecordAction( + UserMetricsAction("Plugin_NPAPINotSupported")); placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( render_view, frame, @@ -751,7 +753,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( IDR_CLICK_TO_PLAY_PLUGIN_HTML, l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD, group_name)); placeholder->set_allow_loading(true); - RenderThread::Get()->RecordUserMetrics("Plugin_ClickToPlay"); + RenderThread::Get()->RecordAction( + UserMetricsAction("Plugin_ClickToPlay")); observer->DidBlockContentType(content_type, identifier); break; } @@ -766,7 +769,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( IDR_BLOCKED_PLUGIN_HTML, l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); placeholder->set_allow_loading(true); - RenderThread::Get()->RecordUserMetrics("Plugin_Blocked"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked")); observer->DidBlockContentType(content_type, identifier); break; } diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc index a3414cf..5014ca8 100644 --- a/chrome/renderer/extensions/dispatcher.cc +++ b/chrome/renderer/extensions/dispatcher.cc @@ -112,6 +112,7 @@ using blink::WebVector; using blink::WebView; using content::RenderThread; using content::RenderView; +using content::UserMetricsAction; namespace extensions { @@ -1097,7 +1098,8 @@ void Dispatcher::DidCreateScriptContext( // "invalid". This isn't interesting. if (extension_id != "invalid") { LOG(ERROR) << "Extension \"" << extension_id << "\" not found"; - RenderThread::Get()->RecordUserMetrics("ExtensionNotFound_ED"); + RenderThread::Get()->RecordAction( + UserMetricsAction("ExtensionNotFound_ED")); } extension_id = ""; diff --git a/chrome/renderer/pepper/pepper_pdf_host.cc b/chrome/renderer/pepper/pepper_pdf_host.cc index dbf4404..dffb169 100644 --- a/chrome/renderer/pepper/pepper_pdf_host.cc +++ b/chrome/renderer/pepper/pepper_pdf_host.cc @@ -219,7 +219,7 @@ int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( NOTREACHED(); return PP_ERROR_FAILED; } - content::RenderThread::Get()->RecordUserMetrics(action); + content::RenderThread::Get()->RecordComputedAction(action); return PP_OK; } diff --git a/chrome/renderer/pepper/ppb_pdf_impl.cc b/chrome/renderer/pepper/ppb_pdf_impl.cc index 78777a9..ad5e8d4 100644 --- a/chrome/renderer/pepper/ppb_pdf_impl.cc +++ b/chrome/renderer/pepper/ppb_pdf_impl.cc @@ -321,7 +321,7 @@ void UserMetricsRecordAction(PP_Instance instance, PP_Var action) { scoped_refptr<ppapi::StringVar> action_str( ppapi::StringVar::FromPPVar(action)); if (action_str.get()) - RenderThread::Get()->RecordUserMetrics(action_str->value()); + RenderThread::Get()->RecordComputedAction(action_str->value()); } void HasUnsupportedFeature(PP_Instance instance_id) { diff --git a/chrome/renderer/plugins/chrome_plugin_placeholder.cc b/chrome/renderer/plugins/chrome_plugin_placeholder.cc index 7b7506d..70f97311 100644 --- a/chrome/renderer/plugins/chrome_plugin_placeholder.cc +++ b/chrome/renderer/plugins/chrome_plugin_placeholder.cc @@ -27,6 +27,7 @@ using content::RenderThread; using content::RenderView; +using content::UserMetricsAction; using blink::WebDocument; using blink::WebElement; using blink::WebFrame; @@ -297,12 +298,12 @@ void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) { return; switch (action) { case chrome::MENU_COMMAND_PLUGIN_RUN: { - RenderThread::Get()->RecordUserMetrics("Plugin_Load_Menu"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Menu")); LoadPlugin(); break; } case chrome::MENU_COMMAND_PLUGIN_HIDE: { - RenderThread::Get()->RecordUserMetrics("Plugin_Hide_Menu"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Menu")); HidePlugin(); break; } diff --git a/components/plugins/renderer/plugin_placeholder.cc b/components/plugins/renderer/plugin_placeholder.cc index aa82135..671d2e0 100644 --- a/components/plugins/renderer/plugin_placeholder.cc +++ b/components/plugins/renderer/plugin_placeholder.cc @@ -25,6 +25,7 @@ #include "third_party/re2/re2/re2.h" using content::RenderThread; +using content::UserMetricsAction; using blink::WebElement; using blink::WebFrame; using blink::WebMouseEvent; @@ -176,7 +177,7 @@ void PluginPlaceholder::OnLoadBlockedPlugins(const std::string& identifier) { if (!identifier.empty() && identifier != identifier_) return; - RenderThread::Get()->RecordUserMetrics("Plugin_Load_UI"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_UI")); LoadPlugin(); } @@ -208,13 +209,13 @@ void PluginPlaceholder::LoadPlugin() { void PluginPlaceholder::LoadCallback(const CppArgumentList& args, CppVariant* result) { - RenderThread::Get()->RecordUserMetrics("Plugin_Load_Click"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); LoadPlugin(); } void PluginPlaceholder::HideCallback(const CppArgumentList& args, CppVariant* result) { - RenderThread::Get()->RecordUserMetrics("Plugin_Hide_Click"); + RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click")); HidePlugin(); } diff --git a/content/content_common.gypi b/content/content_common.gypi index 51e29b9..7d6214c 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -101,6 +101,7 @@ 'public/common/url_fetcher.h', 'public/common/url_utils.cc', 'public/common/url_utils.h', + 'public/common/user_metrics_action.h', 'public/common/webplugininfo.cc', 'public/common/webplugininfo.h', 'public/common/zygote_fork_delegate_linux.h', diff --git a/content/public/browser/user_metrics.h b/content/public/browser/user_metrics.h index 4691ca0..e9480ac 100644 --- a/content/public/browser/user_metrics.h +++ b/content/public/browser/user_metrics.h @@ -9,21 +9,13 @@ #include "base/callback.h" #include "content/common/content_export.h" +#include "content/public/common/user_metrics_action.h" namespace content { // This module provides some helper functions for logging actions tracked by // the user metrics system. - -// UserMetricsAction exist purely to standardize on the paramters passed to -// UserMetrics. That way, our toolset can scan the sourcecode reliable for -// constructors and extract the associated string constants -struct UserMetricsAction { - const char* str_; - explicit UserMetricsAction(const char* str) : str_(str) {} -}; - // Record that the user performed an action. // "Action" here means a user-generated event: // good: "Reload", "CloseTab", and "IMEInvoked" diff --git a/content/public/common/user_metrics_action.h b/content/public/common/user_metrics_action.h new file mode 100644 index 0000000..3b604ef --- /dev/null +++ b/content/public/common/user_metrics_action.h @@ -0,0 +1,29 @@ +// Copyright 2013 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. + +#ifndef CONTENT_PUBLIC_COMMON_USER_METRICS_ACTION_H_ +#define CONTENT_PUBLIC_COMMON_USER_METRICS_ACTION_H_ + +namespace content { + +// UserMetricsAction exists purely to standardize on the parameters passed to +// UserMetrics. That way, our toolset can scan the source code reliable for +// constructors and extract the associated string constants. +// WARNING: When using UserMetricsAction, UserMetricsAction and a string literal +// parameter must be on the same line, e.g. +// RecordAction( +// UserMetricsAction("my extremely long action name")); +// or +// RenderThread::Get()->RecordAction( +// UserMetricsAction("my extremely long action name")); +// because otherwise our processing scripts won't pick up on new actions. +// Please see tools/metrics/actions/extract_actions.py for details. +struct UserMetricsAction { + const char* str_; + explicit UserMetricsAction(const char* str) : str_(str) {} +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_COMMON_USER_METRICS_ACTION_H_ diff --git a/content/public/renderer/render_thread.h b/content/public/renderer/render_thread.h index 23ca0af..4693da3 100644 --- a/content/public/renderer/render_thread.h +++ b/content/public/renderer/render_thread.h @@ -9,6 +9,7 @@ #include "base/callback.h" #include "base/memory/shared_memory.h" #include "content/common/content_export.h" +#include "content/public/common/user_metrics_action.h" #include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_sender.h" @@ -78,8 +79,22 @@ class CONTENT_EXPORT RenderThread : public IPC::Sender { // initialization. virtual void EnsureWebKitInitialized() = 0; - // Helper function to send over a string to be recorded by user metrics - virtual void RecordUserMetrics(const std::string& action) = 0; + // Sends over a UserMetricsAction to be recorded by user metrics as an action. + // Once a new user metric is added, run + // tools/metrics/actions/extract_actions.py --hash + // to generate a new mapping of [action hashes -> metric names] and send it + // out for review to be updated. + // WARNING: When using UserMetricsAction, UserMetricsAction and a string + // literal parameter must be on the same line, e.g. + // RenderThread::Get()->RecordAction( + // UserMetricsAction("my extremely long action name")); + // because otherwise our processing scripts won't pick up on new actions. + virtual void RecordAction(const UserMetricsAction& action) = 0; + + // Sends over a string to be recorded by user metrics as a computed action. + // When you use this you need to also update the rules for extracting known + // actions in chrome/tools/extract_actions.py. + virtual void RecordComputedAction(const std::string& action) = 0; // Asks the host to create a block of shared memory for the renderer. // The shared memory allocated by the host is returned back. diff --git a/content/public/test/mock_render_thread.cc b/content/public/test/mock_render_thread.cc index 9da66ac..54758ea 100644 --- a/content/public/test/mock_render_thread.cc +++ b/content/public/test/mock_render_thread.cc @@ -144,7 +144,10 @@ void MockRenderThread::WidgetRestored() { void MockRenderThread::EnsureWebKitInitialized() { } -void MockRenderThread::RecordUserMetrics(const std::string& action) { +void MockRenderThread::RecordAction(const UserMetricsAction& action) { +} + +void MockRenderThread::RecordComputedAction(const std::string& action) { } scoped_ptr<base::SharedMemory> diff --git a/content/public/test/mock_render_thread.h b/content/public/test/mock_render_thread.h index dc5b82a..fd3f58a 100644 --- a/content/public/test/mock_render_thread.h +++ b/content/public/test/mock_render_thread.h @@ -58,7 +58,8 @@ class MockRenderThread : public RenderThread { virtual void WidgetHidden() OVERRIDE; virtual void WidgetRestored() OVERRIDE; virtual void EnsureWebKitInitialized() OVERRIDE; - virtual void RecordUserMetrics(const std::string& action) OVERRIDE; + virtual void RecordAction(const UserMetricsAction& action) OVERRIDE; + virtual void RecordComputedAction(const std::string& action) OVERRIDE; virtual scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( size_t buffer_size) OVERRIDE; virtual void RegisterExtension(v8::Extension* extension) OVERRIDE; diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index 5cde6c9..b38d884 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -968,7 +968,8 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, &upper_bound, &instance_size); } else if (response.httpStatusCode() == kHttpResponseSuccessStatusCode) { - RenderThreadImpl::current()->RecordUserMetrics("Plugin_200ForByteRange"); + RenderThreadImpl::current()->RecordAction( + UserMetricsAction("Plugin_200ForByteRange")); // If the client issued a byte range request and the server responds with // HTTP 200 OK, it indicates that the server does not support byte range // requests. diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index ab1545f..13a9737 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -734,7 +734,11 @@ void RenderThreadImpl::RegisterSchemes() { WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme); } -void RenderThreadImpl::RecordUserMetrics(const std::string& action) { +void RenderThreadImpl::RecordAction(const UserMetricsAction& action) { + Send(new ViewHostMsg_UserMetricsRecordAction(action.str_)); +} + +void RenderThreadImpl::RecordComputedAction(const std::string& action) { Send(new ViewHostMsg_UserMetricsRecordAction(action)); } diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 391911d..73981fc 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -140,7 +140,8 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, virtual void WidgetHidden() OVERRIDE; virtual void WidgetRestored() OVERRIDE; virtual void EnsureWebKitInitialized() OVERRIDE; - virtual void RecordUserMetrics(const std::string& action) OVERRIDE; + virtual void RecordAction(const UserMetricsAction& action) OVERRIDE; + virtual void RecordComputedAction(const std::string& action) OVERRIDE; virtual scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( size_t buffer_size) OVERRIDE; virtual void RegisterExtension(v8::Extension* extension) OVERRIDE; diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index fe704b2..1be2ce4 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2501,7 +2501,7 @@ void RenderViewImpl::didExecuteCommand(const WebString& command_name) { StartsWithASCII(name, "Insert", true) || StartsWithASCII(name, "Delete", true)) return; - RenderThreadImpl::current()->RecordUserMetrics(name); + RenderThreadImpl::current()->RecordComputedAction(name); } bool RenderViewImpl::handleCurrentKeyboardEvent() { diff --git a/tools/metrics/actions/extract_actions.py b/tools/metrics/actions/extract_actions.py index 05f8096..8b003d2 100755 --- a/tools/metrics/actions/extract_actions.py +++ b/tools/metrics/actions/extract_actions.py @@ -47,7 +47,13 @@ KNOWN_COMPUTED_USERS = ( 'about_flags.cc', # do not generate a warning; see AddAboutFlagsActions() 'external_metrics.cc', # see AddChromeOSActions() 'core_options_handler.cc', # see AddWebUIActions() - 'browser_render_process_host.cc' # see AddRendererActions() + 'browser_render_process_host.cc', # see AddRendererActions() + 'render_thread_impl.cc', # impl of RenderThread::RecordComputedAction() + 'render_process_host_impl.cc', # browser side impl for + # RenderThread::RecordComputedAction() + 'mock_render_thread.cc', # mock of RenderThread::RecordComputedAction() + 'ppb_pdf_impl.cc', # see AddClosedSourceActions() + 'pepper_pdf_host.cc', # see AddClosedSourceActions() ) # Language codes used in Chrome. The list should be updated when a new @@ -486,28 +492,6 @@ def WalkDirectory(root_path, actions, extensions, callback): if ext in extensions: callback(os.path.join(path, file), actions) -def GrepForRendererActions(path, actions): - """Grep a source file for calls to RenderThread::RecordUserMetrics. - - Arguments: - path: path to the file - actions: set of actions to add to - """ - # We look for the ViewHostMsg_UserMetricsRecordAction constructor. - # This should be on one line. - action_re = re.compile( - r'[^a-zA-Z]RenderThread::Get\(\)->RecordUserMetrics\("([^"]*)') - action_re2 = re.compile( - r'[^a-zA-Z]RenderThreadImpl::current\(\)->RecordUserMetrics\("([^"]*)') - for line in open(path): - match = action_re.search(line) - if match: # Call to RecordUserMetrics through Content API - actions.add(match.group(1)) - continue - match = action_re2.search(line) - if match: # Call to RecordUserMetrics inside Content - actions.add(match.group(1)) - def AddLiteralActions(actions): """Add literal actions specified via calls to UserMetrics functions. @@ -537,21 +521,6 @@ def AddWebUIActions(actions): 'resources') WalkDirectory(resources_root, actions, ('.html'), GrepForWebUIActions) -def AddRendererActions(actions): - """Add user actions sent via calls to RenderThread::RecordUserMetrics. - - Arguments: - actions: set of actions to add to. - """ - EXTENSIONS = ('.cc', '.mm', '.c', '.m') - - chrome_renderer_root = os.path.join(REPOSITORY_ROOT, 'chrome', 'renderer') - content_renderer_root = os.path.join(REPOSITORY_ROOT, 'content', 'renderer') - WalkDirectory(chrome_renderer_root, actions, EXTENSIONS, - GrepForRendererActions) - WalkDirectory(content_renderer_root, actions, EXTENSIONS, - GrepForRendererActions) - def AddHistoryPageActions(actions): """Add actions that are used in History page. @@ -601,7 +570,6 @@ def main(argv): # AddWebKitEditorActions(actions) AddAboutFlagsActions(actions) AddWebUIActions(actions) - AddRendererActions(actions) AddLiteralActions(actions) |