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

Unified Diff: chrome/browser/sync/util/extensions_activity_monitor.cc

Issue 333041: Take 2 at browser_sync::ExtensionsActivityMonitor.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
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,
- &registrar_));
+ExtensionsActivityMonitor::ExtensionsActivityMonitor() {
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
+ new RegistrationTask(this, &registrar_));
}
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" ||

Powered by Google App Engine
This is Rietveld 408576698