Index: chrome/browser/sync/util/extensions_activity_monitor.cc |
=================================================================== |
--- chrome/browser/sync/util/extensions_activity_monitor.cc (revision 30162) |
+++ chrome/browser/sync/util/extensions_activity_monitor.cc (working copy) |
@@ -19,14 +19,12 @@ |
class RegistrationTask : public Task { |
public: |
RegistrationTask(ExtensionsActivityMonitor* monitor, |
- MessageLoop* ui_loop, |
NotificationRegistrar* registrar) |
- : monitor_(monitor), ui_loop_(ui_loop), registrar_(registrar) {} |
+ : monitor_(monitor), registrar_(registrar) {} |
virtual ~RegistrationTask() {} |
virtual void Run() { |
- DCHECK_EQ(MessageLoop::current(), |
- ChromeThread::GetMessageLoop(ChromeThread::UI)); |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
// It would be nice if we could specify a Source for each specific function |
// we wanted to observe, but the actual function objects are allocated on |
@@ -39,23 +37,31 @@ |
private: |
ExtensionsActivityMonitor* monitor_; |
- MessageLoop* const ui_loop_; |
NotificationRegistrar* registrar_; |
DISALLOW_COPY_AND_ASSIGN(RegistrationTask); |
}; |
} // namespace |
-ExtensionsActivityMonitor::ExtensionsActivityMonitor(MessageLoop* ui_loop) |
- : ui_loop_(ui_loop) { |
- ui_loop_->PostTask(FROM_HERE, new RegistrationTask(this, ui_loop, |
- ®istrar_)); |
+ExtensionsActivityMonitor::ExtensionsActivityMonitor() { |
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, |
+ new RegistrationTask(this, ®istrar_)); |
} |
ExtensionsActivityMonitor::~ExtensionsActivityMonitor() { |
- DCHECK_EQ(MessageLoop::current(), ui_loop_); |
- // The registrar calls RemoveAll in its dtor (which would happen in a moment) |
- // but explicitly call this so it is clear why we need to be on the ui_loop_. |
- registrar_.RemoveAll(); |
+ // In some unrelated unit tests, there is no running UI loop. In this case, |
+ // the PostTask in our ctor will not result in anything running, so |this| |
+ // won't be used for anything. In this case (or whenever no registration took |
+ // place) and only this case we allow destruction on another loop, but this |
+ // isn't something a client of this class can control; it happens implicitly |
+ // by not having a running UI thread. |
+ if (!registrar_.IsEmpty()) { |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
+ |
+ // The registrar calls RemoveAll in its dtor (which would happen in a |
+ // moment but explicitly call this so it is clear why we need to be on the |
+ // ui_loop_. |
+ registrar_.RemoveAll(); |
+ } |
} |
void ExtensionsActivityMonitor::GetAndClearRecords(Records* buffer) { |
@@ -76,7 +82,7 @@ |
const NotificationSource& source, |
const NotificationDetails& details) { |
AutoLock lock(records_lock_); |
- DCHECK_EQ(MessageLoop::current(), ui_loop_); |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
const Extension* extension = Source<const Extension>(source).ptr(); |
const BookmarksFunction* f = Details<const BookmarksFunction>(details).ptr(); |
if (f->name() == "bookmarks.update" || |