| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/browser/user_metrics.h" | 5 #include "content/public/browser/user_metrics.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" |
| 9 #include "base/observer_list.h" |
| 8 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/notification_service.h" | |
| 10 #include "content/public/browser/notification_types.h" | |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 base::LazyInstance<ObserverList<UserMetricsObserver> > g_observers = |
| 16 LAZY_INSTANCE_INITIALIZER; |
| 17 |
| 15 // Forward declare because of circular dependency. | 18 // Forward declare because of circular dependency. |
| 16 void CallRecordOnUI(const std::string& action); | 19 void CallRecordOnUI(const std::string& action); |
| 17 | 20 |
| 18 void Record(const char *action) { | 21 void Record(const char *action) { |
| 19 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 22 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 20 BrowserThread::PostTask( | 23 BrowserThread::PostTask( |
| 21 BrowserThread::UI, | 24 BrowserThread::UI, |
| 22 FROM_HERE, | 25 FROM_HERE, |
| 23 base::Bind(&CallRecordOnUI, action)); | 26 base::Bind(&CallRecordOnUI, action)); |
| 24 return; | 27 return; |
| 25 } | 28 } |
| 26 | 29 |
| 27 NotificationService::current()->Notify( | 30 FOR_EACH_OBSERVER(UserMetricsObserver, g_observers.Get(), UserAction(action)); |
| 28 NOTIFICATION_USER_ACTION, | |
| 29 NotificationService::AllSources(), | |
| 30 Details<const char*>(&action)); | |
| 31 } | 31 } |
| 32 | 32 |
| 33 void CallRecordOnUI(const std::string& action) { | 33 void CallRecordOnUI(const std::string& action) { |
| 34 Record(action.c_str()); | 34 Record(action.c_str()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 void RecordAction(const UserMetricsAction& action) { | 39 void RecordAction(const UserMetricsAction& action) { |
| 40 Record(action.str_); | 40 Record(action.str_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void RecordComputedAction(const std::string& action) { | 43 void RecordComputedAction(const std::string& action) { |
| 44 Record(action.c_str()); | 44 Record(action.c_str()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void UserMetricsObserver::UserAction(const std::string& action) { |
| 48 } |
| 49 |
| 50 UserMetricsObserver::UserMetricsObserver() { |
| 51 g_observers.Get().AddObserver(this); |
| 52 } |
| 53 |
| 54 UserMetricsObserver::~UserMetricsObserver() { |
| 55 g_observers.Get().RemoveObserver(this); |
| 56 } |
| 57 |
| 47 } // namespace content | 58 } // namespace content |
| OLD | NEW |