diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 20:33:17 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 20:33:17 +0000 |
commit | 0f08bf3692c1db8ff2032a7e944335cb5bb6a453 (patch) | |
tree | 2348461db1b9ae039f92b810f6c44398532a6723 /chrome | |
parent | cbce8ffb3d90ed63e9fb36407d31f7f6ce8a991d (diff) | |
download | chromium_src-0f08bf3692c1db8ff2032a7e944335cb5bb6a453.zip chromium_src-0f08bf3692c1db8ff2032a7e944335cb5bb6a453.tar.gz chromium_src-0f08bf3692c1db8ff2032a7e944335cb5bb6a453.tar.bz2 |
Use a NotificationRegistrar to listen for notifications.
BUG=2381
Review URL: http://codereview.chromium.org/115647
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/printing/print_job.cc | 20 | ||||
-rw-r--r-- | chrome/browser/printing/print_job.h | 4 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.cc | 34 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 12 | ||||
-rw-r--r-- | chrome/browser/printing/print_view_manager.h | 4 |
7 files changed, 31 insertions, 57 deletions
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc index 4e727c7..17c4290 100644 --- a/chrome/browser/printing/print_job.cc +++ b/chrome/browser/printing/print_job.cc @@ -56,8 +56,8 @@ void PrintJob::Initialize(PrintJobWorkerOwner* job, UpdatePrintedDocument(new PrintedDocument(settings_, source_, job->cookie())); // Don't forget to register to our own messages. - NotificationService::current()->AddObserver( - this, NotificationType::PRINT_JOB_EVENT, Source<PrintJob>(this)); + registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, + Source<PrintJob>(this)); } void PrintJob::Observe(NotificationType type, @@ -152,8 +152,8 @@ void PrintJob::Stop() { ControlledWorkerShutdown(); is_job_pending_ = false; - NotificationService::current()->RemoveObserver( - this, NotificationType::PRINT_JOB_EVENT, Source<PrintJob>(this)); + registrar_.Remove(this, NotificationType::PRINT_JOB_EVENT, + Source<PrintJob>(this)); } // Flush the cached document. UpdatePrintedDocument(NULL); @@ -230,19 +230,15 @@ void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { return; // Unregisters. if (document_.get()) { - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(document_.get())); + registrar_.Remove(this, NotificationType::PRINTED_DOCUMENT_UPDATED, + Source<PrintedDocument>(document_.get())); } document_ = new_document; // Registers. if (document_.get()) { - NotificationService::current()->AddObserver( - this, - NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(document_.get())); + registrar_.Add(this, NotificationType::PRINTED_DOCUMENT_UPDATED, + Source<PrintedDocument>(document_.get())); settings_ = document_->settings(); } diff --git a/chrome/browser/printing/print_job.h b/chrome/browser/printing/print_job.h index 22c61de..45d5d12 100644 --- a/chrome/browser/printing/print_job.h +++ b/chrome/browser/printing/print_job.h @@ -10,7 +10,7 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "chrome/browser/printing/print_job_worker_owner.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" class GURL; class Thread; @@ -117,6 +117,8 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, // eventual deadlock. void ControlledWorkerShutdown(); + NotificationRegistrar registrar_; + // Main message loop reference. Used to send notifications in the right // thread. MessageLoop* const ui_message_loop_; diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc index ccfd22d..44d60de 100644 --- a/chrome/browser/printing/print_job_manager.cc +++ b/chrome/browser/printing/print_job_manager.cc @@ -17,34 +17,20 @@ namespace printing { PrintJobManager::PrintJobManager() : debug_dump_path_() { - NotificationService::current()->AddObserver( - this, - NotificationType::PRINT_JOB_EVENT, - NotificationService::AllSources()); - NotificationService::current()->AddObserver( - this, - NotificationType::PRINTED_DOCUMENT_UPDATED, - NotificationService::AllSources()); + registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::PRINTED_DOCUMENT_UPDATED, + NotificationService::AllSources()); } PrintJobManager::~PrintJobManager() { - // When this object is destroyed, the shared NotificationService instance is - // already destroyed. AutoLock lock(lock_); queued_queries_.clear(); - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINT_JOB_EVENT, - NotificationService::AllSources()); - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINTED_DOCUMENT_UPDATED, - NotificationService::AllSources()); } void PrintJobManager::OnQuit() { // Common case, no print job pending. - if (current_jobs_.size() == 0) + if (current_jobs_.empty()) return; { // Don't take a chance and copy the array since it can be modified in @@ -61,15 +47,7 @@ void PrintJobManager::OnQuit() { } } current_jobs_.clear(); - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINT_JOB_EVENT, - NotificationService::AllSources()); - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINTED_DOCUMENT_UPDATED, - NotificationService::AllSources()); - DCHECK_EQ(current_jobs_.size(), 0); + registrar_.RemoveAll(); } void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) { diff --git a/chrome/browser/printing/print_job_manager.h b/chrome/browser/printing/print_job_manager.h index 4286a2d..4262a15 100644 --- a/chrome/browser/printing/print_job_manager.h +++ b/chrome/browser/printing/print_job_manager.h @@ -10,7 +10,7 @@ #include "base/lock.h" #include "base/ref_counted.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" namespace printing { @@ -68,6 +68,8 @@ class PrintJobManager : public NotificationObserver { void OnPrintedDocumentUpdated(const PrintedDocument& document, const PrintedPage& page); + NotificationRegistrar registrar_; + // Used to serialize access to queued_workers_. Lock lock_; diff --git a/chrome/browser/printing/print_job_unittest.cc b/chrome/browser/printing/print_job_unittest.cc index 4a8ce5f..e3eead4 100644 --- a/chrome/browser/printing/print_job_unittest.cc +++ b/chrome/browser/printing/print_job_unittest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/printing/print_job.h" #include "chrome/browser/printing/print_job_worker.h" #include "chrome/browser/printing/printed_pages_source.h" +#include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -96,10 +97,10 @@ TEST(PrintJobTest, DISABLED_SimplePrint) { // This message loop is actually never run. MessageLoop current; + NotificationRegistrar registrar_; TestPrintNotifObserv observ; - NotificationService::current()->AddObserver( - &observ, NotificationType::ALL, - NotificationService::AllSources()); + registrar_.Add(&observ, NotificationType::ALL, + NotificationService::AllSources()); volatile bool check = false; scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); EXPECT_EQ(MessageLoop::current(), job->message_loop()); @@ -109,9 +110,6 @@ TEST(PrintJobTest, DISABLED_SimplePrint) { job->Stop(); job = NULL; EXPECT_TRUE(check); - NotificationService::current()->RemoveObserver( - &observ, NotificationType::ALL, - NotificationService::AllSources()); } TEST(PrintJobTest, SimplePrintLateInit) { diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index f717023..5976bf3 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -264,10 +264,8 @@ bool PrintViewManager::CreateNewPrintJob(PrintJobWorkerOwner* job) { print_job_ = new PrintJob(); print_job_->Initialize(job, this); - NotificationService::current()->AddObserver( - this, - NotificationType::PRINT_JOB_EVENT, - Source<PrintJob>(print_job_.get())); + registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, + Source<PrintJob>(print_job_.get())); return true; } @@ -315,11 +313,9 @@ void PrintViewManager::ReleasePrintJob() { DCHECK_EQ(waiting_to_print_, false); if (!print_job_.get()) return; - NotificationService::current()->RemoveObserver( - this, - NotificationType::PRINT_JOB_EVENT, - Source<PrintJob>(print_job_.get())); + registrar_.Remove(this, NotificationType::PRINT_JOB_EVENT, + Source<PrintJob>(print_job_.get())); print_job_->DisconnectSource(); // Don't close the worker thread. print_job_ = NULL; diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h index aec2601..2562885 100644 --- a/chrome/browser/printing/print_view_manager.h +++ b/chrome/browser/printing/print_view_manager.h @@ -7,7 +7,7 @@ #include "base/ref_counted.h" #include "chrome/browser/printing/printed_pages_source.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" class RenderViewHost; class TabContents; @@ -103,6 +103,8 @@ class PrintViewManager : public NotificationObserver, // print_job_ is initialized. bool OpportunisticallyCreatePrintJob(int cookie); + NotificationRegistrar registrar_; + // Manages the low-level talk to the printer. scoped_refptr<PrintJob> print_job_; |