Commit e1504d80 authored by sverrir@google.com's avatar sverrir@google.com

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
parent a2176747
......@@ -89,7 +89,7 @@
#include "chrome/browser/jankometer.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/printed_document.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/views/user_data_dir_dialog.h"
......@@ -757,9 +757,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
}
InstallJankometer(parsed_command_line);
#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
if (parsed_command_line.HasSwitch(switches::kDebugPrint)) {
browser_process->print_job_manager()->set_debug_dump_path(
printing::PrintedDocument::set_debug_dump_path(
parsed_command_line.GetSwitchValue(switches::kDebugPrint));
}
#endif
......
......@@ -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();
}
......
......@@ -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
......@@ -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);
};
......
......@@ -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),
......
......@@ -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_;
......
......@@ -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;
......
......@@ -527,12 +527,6 @@ class NotificationType {
// Printing ----------------------------------------------------------------
// Notification from a PrintedDocument that it has been updated. It may be
// that a printed page has just been generated or that the document's
// number of pages has been calculated. Details is the new page or NULL if
// only the number of pages in the document has been updated.
PRINTED_DOCUMENT_UPDATED,
// Notification from PrintJob that an event occured. It can be that a page
// finished printing or that the print job failed. Details is
// PrintJob::EventDetails.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment