diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 04:41:04 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 04:41:04 +0000 |
commit | 787e639c1306ca968a4651145133e2b22919f893 (patch) | |
tree | 0937672570e54ff57aebcaeda265f19b92e68c9b /dbus/dbus_statistics.cc | |
parent | f707c3466c8ecd9767d8fbc26daa12797e0e2dfc (diff) | |
download | chromium_src-787e639c1306ca968a4651145133e2b22919f893.zip chromium_src-787e639c1306ca968a4651145133e2b22919f893.tar.gz chromium_src-787e639c1306ca968a4651145133e2b22919f893.tar.bz2 |
Make DBusStatistics only run on the main thread and add additional CHECKs to ensure thread safety.
Calls from other threads will be ignored. Currently the only DBus calls from other threads are for Geolocation. Supporting statistics gathering across multiple threads is unnecessary overhead that we don't currently need.
BUG=168134
Review URL: https://chromiumcodereview.appspot.com/11761015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/dbus_statistics.cc')
-rw-r--r-- | dbus/dbus_statistics.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/dbus/dbus_statistics.cc b/dbus/dbus_statistics.cc index 015e20e..8368c4c 100644 --- a/dbus/dbus_statistics.cc +++ b/dbus/dbus_statistics.cc @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" #include "base/stringprintf.h" +#include "base/threading/platform_thread.h" #include "base/time.h" namespace dbus { @@ -60,10 +61,13 @@ typedef std::set<Stat*, Stat::PtrCompare> StatSet; // Simple class for gathering DBus usage statistics. class DBusStatistics { public: - DBusStatistics() : start_time_(base::Time::Now()) { + DBusStatistics() + : start_time_(base::Time::Now()), + origin_thread_id_(base::PlatformThread::CurrentId()) { } ~DBusStatistics() { + DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId()); STLDeleteContainerPointers(stats_.begin(), stats_.end()); } @@ -79,6 +83,11 @@ class DBusStatistics { const std::string& interface, const std::string& method, StatType type) { + if (base::PlatformThread::CurrentId() != origin_thread_id_) { + DLOG(WARNING) << "Ignoring DBusStatistics::AddStat call from thread: " + << base::PlatformThread::CurrentId(); + return; + } Stat* stat = GetStat(service, interface, method, true); DCHECK(stat); if (type == TYPE_SENT_METHOD_CALLS) @@ -97,6 +106,7 @@ class DBusStatistics { const std::string& interface, const std::string& method, bool add_stat) { + DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId()); scoped_ptr<Stat> stat(new Stat(service, interface, method)); StatSet::iterator found = stats_.find(stat.get()); if (found != stats_.end()) @@ -113,6 +123,7 @@ class DBusStatistics { private: StatSet stats_; base::Time start_time_; + base::PlatformThreadId origin_thread_id_; DISALLOW_COPY_AND_ASSIGN(DBusStatistics); }; |