diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 07:09:21 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 07:09:21 +0000 |
commit | 97880c8bbb79a14eff349d8a128ccea48d6c4314 (patch) | |
tree | 1f62918f77fd9be58d0a9174f0a09094ea5678c4 /content | |
parent | 6cea1821712e08df4dc9d5e0a31cdce8187b121b (diff) | |
download | chromium_src-97880c8bbb79a14eff349d8a128ccea48d6c4314.zip chromium_src-97880c8bbb79a14eff349d8a128ccea48d6c4314.tar.gz chromium_src-97880c8bbb79a14eff349d8a128ccea48d6c4314.tar.bz2 |
Use UserMetricsAction for renderer user metrics.
Benefits of this change:
- Unified action recording. We don't need special renderer treatment in
extract_actions.py.
- UserMetricsAction() is shorter than RenderThread::Get()->RecordAction(). So
that we can have longer action names (since the action name must be on the
same line and we have 80 chars limit).
- Rename RecordUserMetrics() to RecordAction() to be consistent.
- Separate RecordComputedAction() from RecordAction() so that we can catch
unhandled computed actions.
TBR=bauerb@chromium.org
R=isherman@chromium.org
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/102073005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-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 |
10 files changed, 64 insertions, 17 deletions
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() { |