Commit 787e639c authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

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
parent f707c346
......@@ -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);
};
......
......@@ -9,6 +9,11 @@
#include "dbus/dbus_export.h"
// The functions defined here are used to gather DBus statistics, and
// provide them in a format convenient for debugging. These functions are only
// valid when called from the main thread (the thread which Initialize() was
// called from). Calls from other threads will be ignored.
namespace dbus {
namespace statistics {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment