Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2206)

Unified Diff: dbus/dbus_statistics.cc

Issue 11761015: Make DBusStatistics only run on the main thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CHECK -> DCHECK Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/dbus_statistics.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/dbus_statistics.cc
diff --git a/dbus/dbus_statistics.cc b/dbus/dbus_statistics.cc
index 015e20ea61c769896940ea4bfc7071da677fec3a..8368c4c0aef81cab65fd7a0c14f023c3e3f98ec0 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);
};
« no previous file with comments | « dbus/dbus_statistics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698