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

Unified Diff: base/power_monitor/power_monitor.cc

Issue 502003003: Check to ensure PowerObservers are added and removed on the same thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « no previous file | base/power_monitor/power_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/power_monitor/power_monitor.cc
diff --git a/base/power_monitor/power_monitor.cc b/base/power_monitor/power_monitor.cc
index 14dc4b517832785c07153abfed2bcc4a3a738940..87ba2a656732762b1b0d50987023dc440bac8c64 100644
--- a/base/power_monitor/power_monitor.cc
+++ b/base/power_monitor/power_monitor.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/power_monitor/power_monitor.h"
+#include "base/logging.h"
#include "base/power_monitor/power_monitor_source.h"
namespace base {
@@ -27,11 +28,16 @@ PowerMonitor* PowerMonitor::Get() {
}
void PowerMonitor::AddObserver(PowerObserver* obs) {
+ CHECK (obs->power_monitor_thread_ == 0);
scottmg 2014/08/25 21:43:16 nit; no space before (
+ obs->power_monitor_thread_ = base::PlatformThread::CurrentId();
observers_->AddObserver(obs);
}
void PowerMonitor::RemoveObserver(PowerObserver* obs) {
+ // PowerObservers must be removed on the same thread on which they were added.
+ CHECK (base::PlatformThread::CurrentId() == obs->power_monitor_thread_);
scottmg 2014/08/25 21:43:16 no space, and CHECK_EQ instead
observers_->RemoveObserver(obs);
+ obs->power_monitor_thread_ = 0;
}
PowerMonitorSource* PowerMonitor::Source() {
« no previous file with comments | « no previous file | base/power_monitor/power_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698