diff options
author | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 15:27:15 +0000 |
---|---|---|
committer | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 15:27:15 +0000 |
commit | e1504d80b03baf88f01709157c94806d94add2c0 (patch) | |
tree | 67e5708fcca34da70c25665d8f556dd43da05be2 /chrome/browser/printing | |
parent | a21767477fef894a75d0b13a8da3da6cdc2f5e3e (diff) | |
download | chromium_src-e1504d80b03baf88f01709157c94806d94add2c0.zip chromium_src-e1504d80b03baf88f01709157c94806d94add2c0.tar.gz chromium_src-e1504d80b03baf88f01709157c94806d94add2c0.tar.bz2 |
Remove unused notification in print code to simplify before refactoring.
Removed the PRINTED_DOCUMENT_UPDATED notification and move the debug output from PrintJobManager to PrintedDocument.
Also made the --debug-print startup parameter only active in non-official builds.
BUG=none
TEST=Should have no functional affect.
Review URL: http://codereview.chromium.org/149148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r-- | chrome/browser/printing/print_job.cc | 24 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.cc | 34 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_manager.h | 23 | ||||
-rw-r--r-- | chrome/browser/printing/printed_document.cc | 78 | ||||
-rw-r--r-- | chrome/browser/printing/printed_document.h | 8 | ||||
-rw-r--r-- | chrome/browser/printing/win_printing_context.cc | 11 |
6 files changed, 69 insertions, 109 deletions
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc index 1e35ef5..88f68e1 100644 --- a/chrome/browser/printing/print_job.cc +++ b/chrome/browser/printing/print_job.cc @@ -66,21 +66,6 @@ void PrintJob::Observe(NotificationType type, const NotificationDetails& details) { DCHECK_EQ(ui_message_loop_, MessageLoop::current()); switch (type.value) { - case NotificationType::PRINTED_DOCUMENT_UPDATED: { - DCHECK(Source<PrintedDocument>(source).ptr() == - document_.get()); - - // This notification may happens even if no job is started (i.e. print - // preview) - if (is_job_pending_ == true && - Source<PrintedDocument>(source).ptr() == document_.get() && - Details<PrintedPage>(details).ptr() != NULL) { - // Are we waiting for a page to print? The worker will know. - worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - worker_.get(), &PrintJobWorker::OnNewPage)); - } - break; - } case NotificationType::PRINT_JOB_EVENT: { OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); break; @@ -229,17 +214,10 @@ PrintedDocument* PrintJob::document() const { void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { if (document_.get() == new_document) return; - // Unregisters. - if (document_.get()) { - registrar_.Remove(this, NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(document_.get())); - } + document_ = new_document; - // Registers. if (document_.get()) { - registrar_.Add(this, NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(document_.get())); settings_ = document_->settings(); } diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc index 44d60de..c6f4ac3 100644 --- a/chrome/browser/printing/print_job_manager.cc +++ b/chrome/browser/printing/print_job_manager.cc @@ -4,8 +4,6 @@ #include "chrome/browser/printing/print_job_manager.h" -#include "base/file_util.h" -#include "base/string_util.h" #include "chrome/browser/printing/print_job.h" #include "chrome/browser/printing/printer_query.h" #include "chrome/browser/printing/printed_document.h" @@ -15,12 +13,9 @@ namespace printing { -PrintJobManager::PrintJobManager() - : debug_dump_path_() { +PrintJobManager::PrintJobManager() { registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, NotificationService::AllSources()); - registrar_.Add(this, NotificationType::PRINTED_DOCUMENT_UPDATED, - NotificationService::AllSources()); } PrintJobManager::~PrintJobManager() { @@ -84,13 +79,6 @@ void PrintJobManager::Observe(NotificationType type, *Details<JobEventDetails>(details).ptr()); break; } - case NotificationType::PRINTED_DOCUMENT_UPDATED: { - PrintedPage* printed_page = Details<PrintedPage>(details).ptr(); - if (printed_page) - OnPrintedDocumentUpdated(*Source<PrintedDocument>(source).ptr(), - *printed_page); - break; - } default: { NOTREACHED(); break; @@ -152,24 +140,4 @@ void PrintJobManager::OnPrintJobEvent( } } -void PrintJobManager::OnPrintedDocumentUpdated(const PrintedDocument& document, - const PrintedPage& page) { - if (debug_dump_path_.empty()) - return; - - std::wstring filename; - filename += document.date(); - filename += L"_"; - filename += document.time(); - filename += L"_"; - filename += document.name(); - filename += L"_"; - filename += StringPrintf(L"%02d", page.page_number()); - filename += L"_.emf"; - file_util::ReplaceIllegalCharacters(&filename, '_'); - std::wstring path(debug_dump_path_); - file_util::AppendToPath(&path, filename); - page.emf()->SaveTo(path); -} - } // namespace printing diff --git a/chrome/browser/printing/print_job_manager.h b/chrome/browser/printing/print_job_manager.h index 4262a15..ec5febb 100644 --- a/chrome/browser/printing/print_job_manager.h +++ b/chrome/browser/printing/print_job_manager.h @@ -42,18 +42,6 @@ class PrintJobManager : public NotificationObserver { const NotificationSource& source, const NotificationDetails& details); - // Sets a path where to dump EMF data files. This enables debug behavior where - // every rendered pages are dumped as-is. By default the path is empty, which - // disables the dumping. - // TODO(maruel): Remove me once printing is awesome. - void set_debug_dump_path(const std::wstring& debug_dump_path) { - debug_dump_path_ = debug_dump_path; - } - - const std::wstring& debug_dump_path() const { - return debug_dump_path_; - } - private: typedef std::vector<scoped_refptr<PrintJob> > PrintJobs; typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries; @@ -62,12 +50,6 @@ class PrintJobManager : public NotificationObserver { void OnPrintJobEvent(PrintJob* print_job, const JobEventDetails& event_details); - // Processes a NOTIFY_PRINTED_DOCUMENT_UPDATED notification. When - // debug_dump_path_ is not empty, it is processed to detect newly rendered - // pages and to dump their EMF buffer. - void OnPrintedDocumentUpdated(const PrintedDocument& document, - const PrintedPage& page); - NotificationRegistrar registrar_; // Used to serialize access to queued_workers_. @@ -78,11 +60,6 @@ class PrintJobManager : public NotificationObserver { // Current print jobs that are active. PrintJobs current_jobs_; - // Path where debug dump of EMF buffer are saved. Empty by default. When - // empty, EMF dumping is disabled. - // TODO(maruel): Remove me once printing is awesome. - std::wstring debug_dump_path_; - DISALLOW_EVIL_CONSTRUCTORS(PrintJobManager); }; diff --git a/chrome/browser/printing/printed_document.cc b/chrome/browser/printing/printed_document.cc index c5ea1d9..a366a95 100644 --- a/chrome/browser/printing/printed_document.cc +++ b/chrome/browser/printing/printed_document.cc @@ -9,20 +9,36 @@ #include "app/gfx/font.h" #include "app/gfx/text_elider.h" #include "app/win_util.h" +#include "base/file_util.h" #include "base/message_loop.h" +#include "base/singleton.h" +#include "base/string_util.h" #include "base/time.h" #include "chrome/browser/printing/page_number.h" #include "chrome/browser/printing/page_overlays.h" #include "chrome/browser/printing/printed_pages_source.h" #include "chrome/browser/printing/printed_page.h" #include "chrome/common/gfx/emf.h" -#include "chrome/common/time_format.h" -#include "chrome/common/notification_service.h" #include "printing/units.h" #include "skia/ext/platform_device.h" using base::Time; +namespace { + +struct PrintDebugDumpPath { + PrintDebugDumpPath() + : enabled(false) { + } + + bool enabled; + std::wstring debug_dump_path; +}; + +Singleton<PrintDebugDumpPath> g_debug_dump_info; + +} // namespace + namespace printing { PrintedDocument::PrintedDocument(const PrintSettings& settings, @@ -59,10 +75,7 @@ void PrintedDocument::SetPage(int page_number, gfx::Emf* emf, double shrink) { DCHECK_EQ(mutable_.shrink_factor, shrink); } } - NotificationService::current()->Notify( - NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(this), - Details<PrintedPage>(page)); + DebugDump(*page); } bool PrintedDocument::GetPage(int page_number, @@ -195,22 +208,16 @@ size_t PrintedDocument::MemoryUsage() const { } void PrintedDocument::set_page_count(int max_page) { - { - AutoLock lock(lock_); - DCHECK_EQ(0, mutable_.page_count_); - mutable_.page_count_ = max_page; - if (immutable_.settings_.ranges.empty()) { - mutable_.expected_page_count_ = max_page; - } else { - // If there is a range, don't bother since expected_page_count_ is already - // initialized. - DCHECK_NE(mutable_.expected_page_count_, 0); - } + AutoLock lock(lock_); + DCHECK_EQ(0, mutable_.page_count_); + mutable_.page_count_ = max_page; + if (immutable_.settings_.ranges.empty()) { + mutable_.expected_page_count_ = max_page; + } else { + // If there is a range, don't bother since expected_page_count_ is already + // initialized. + DCHECK_NE(mutable_.expected_page_count_, 0); } - NotificationService::current()->Notify( - NotificationType::PRINTED_DOCUMENT_UPDATED, - Source<PrintedDocument>(this), - NotificationService::NoDetails()); } int PrintedDocument::page_count() const { @@ -297,6 +304,35 @@ void PrintedDocument::PrintHeaderFooter(HDC context, DCHECK_NE(res, 0); } +void PrintedDocument::DebugDump(const PrintedPage& page) +{ + if (!g_debug_dump_info->enabled) + return; + + std::wstring filename; + filename += date(); + filename += L"_"; + filename += time(); + filename += L"_"; + filename += name(); + filename += L"_"; + filename += StringPrintf(L"%02d", page.page_number()); + filename += L"_.emf"; + file_util::ReplaceIllegalCharacters(&filename, '_'); + std::wstring path(g_debug_dump_info->debug_dump_path); + file_util::AppendToPath(&path, filename); + page.emf()->SaveTo(path); +} + +void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { + g_debug_dump_info->enabled = !debug_dump_path.empty(); + g_debug_dump_info->debug_dump_path = debug_dump_path; +} + +const std::wstring& PrintedDocument::debug_dump_path() { + return g_debug_dump_info->debug_dump_path; +} + PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) : source_(source), expected_page_count_(0), diff --git a/chrome/browser/printing/printed_document.h b/chrome/browser/printing/printed_document.h index c78f57a..5efc415 100644 --- a/chrome/browser/printing/printed_document.h +++ b/chrome/browser/printing/printed_document.h @@ -96,6 +96,12 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { const std::wstring& time() const { return immutable_.time_; } const int cookie() const { return immutable_.cookie_; } + // Sets a path where to dump printing output files for debugging. If never set + // no files are generated. + static void set_debug_dump_path(const std::wstring& debug_dump_path); + + static const std::wstring& debug_dump_path(); + private: // Array of EMF data for each print previewed page. typedef std::map<int, scoped_refptr<PrintedPage>> PrintedPages; @@ -166,6 +172,8 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { PageOverlays::VerticalPosition y, const gfx::Font& font) const; + void DebugDump(const PrintedPage& page); + // All writable data member access must be guarded by this lock. Needs to be // mutable since it can be acquired from const member functions. mutable Lock lock_; diff --git a/chrome/browser/printing/win_printing_context.cc b/chrome/browser/printing/win_printing_context.cc index 1d0ad0e..0182417 100644 --- a/chrome/browser/printing/win_printing_context.cc +++ b/chrome/browser/printing/win_printing_context.cc @@ -11,7 +11,7 @@ #include "base/time.h" #include "base/time_format.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/printing/print_job_manager.h" +#include "chrome/browser/printing/printed_document.h" #include "skia/ext/platform_device_win.h" using base::Time; @@ -272,14 +272,7 @@ PrintingContext::Result PrintingContext::NewDocument( di.lpszDocName = document_name.c_str(); // Is there a debug dump directory specified? If so, force to print to a file. - std::wstring debug_dump_path; - if (!g_browser_process || !g_browser_process->print_job_manager()) { - // Happens only inside a unit test. - debug_dump_path = L"."; - } else { - debug_dump_path = g_browser_process->print_job_manager()->debug_dump_path(); - } - + std::wstring debug_dump_path = PrintedDocument::debug_dump_path(); if (!debug_dump_path.empty()) { // Create a filename. std::wstring filename; |