diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-13 21:24:39 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-13 21:24:39 +0000 |
commit | e6e30ac7da61cf09099d861344b3c22e5d5d158c (patch) | |
tree | 3d6df38aeec8737b3aac899ab2079d77511a96e6 /content/browser/user_metrics.cc | |
parent | 662e95081cfe6aa20be3a367d7e12b71f9d790b3 (diff) | |
download | chromium_src-e6e30ac7da61cf09099d861344b3c22e5d5d158c.zip chromium_src-e6e30ac7da61cf09099d861344b3c22e5d5d158c.tar.gz chromium_src-e6e30ac7da61cf09099d861344b3c22e5d5d158c.tar.bz2 |
Move the guts of user_metrics to a new static lib in //base/metrics.
I retained a couple of wrapper functions in content that post back to the UI thread if they are called from another thread. All existing code will continue to use these wrappers. The intent is that some code that I don't want to depend on content that only lives on the UI thread can now call //base/metrics code directly.
R=isherman@chromium.org, jam@chromium.org
http://crbug.com/332504
Review URL: https://codereview.chromium.org/129223004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/user_metrics.cc')
-rw-r--r-- | content/browser/user_metrics.cc | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/content/browser/user_metrics.cc b/content/browser/user_metrics.cc index a1c7819..200c851 100644 --- a/content/browser/user_metrics.cc +++ b/content/browser/user_metrics.cc @@ -7,56 +7,33 @@ #include <vector> #include "base/bind.h" -#include "base/lazy_instance.h" +#include "base/metrics/user_metrics.h" #include "content/public/browser/browser_thread.h" namespace content { -namespace { -base::LazyInstance<std::vector<ActionCallback> > g_action_callbacks = - LAZY_INSTANCE_INITIALIZER; - -// Forward declare because of circular dependency. -void CallRecordOnUI(const std::string& action); - -void Record(const char *action) { +void RecordAction(const base::UserMetricsAction& action) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&CallRecordOnUI, action)); + base::Bind(&RecordAction, action)); return; } - for (size_t i = 0; i < g_action_callbacks.Get().size(); i++) - g_action_callbacks.Get()[i].Run(action); -} - -void CallRecordOnUI(const std::string& action) { - Record(action.c_str()); -} - -} // namespace - -void RecordAction(const UserMetricsAction& action) { - Record(action.str_); + base::RecordAction(action); } void RecordComputedAction(const std::string& action) { - Record(action.c_str()); -} - -void AddActionCallback(const ActionCallback& callback) { - g_action_callbacks.Get().push_back(callback); -} - -void RemoveActionCallback(const ActionCallback& callback) { - for (size_t i = 0; i < g_action_callbacks.Get().size(); i++) { - if (g_action_callbacks.Get()[i].Equals(callback)) { - g_action_callbacks.Get().erase(g_action_callbacks.Get().begin() + i); - return; - } + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + base::Bind(&RecordComputedAction, action)); + return; } + + base::RecordComputedAction(action); } } // namespace content |