diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 00:12:53 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 00:12:53 +0000 |
commit | 7868ecabafc39bcd917276899742be136cca2ae3 (patch) | |
tree | b008edd73081d0df868eae216e18cc6dc56d382d /chrome/browser/printing/printer_query.cc | |
parent | f41067c4ff04b9552c48e89169b28cf078c1a8ba (diff) | |
download | chromium_src-7868ecabafc39bcd917276899742be136cca2ae3.zip chromium_src-7868ecabafc39bcd917276899742be136cca2ae3.tar.gz chromium_src-7868ecabafc39bcd917276899742be136cca2ae3.tar.bz2 |
(1) Hook up the print button to send the pages to the default printer for printing without displaying a native dialog.
(2) Made code changes to accept a print page range from the user and to print only those specified pages.
BUG=none
TEST=Enable print preview on mac, provide a valid page range and make sure print button in print preview works.
Review URL: http://codereview.chromium.org/6533006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing/printer_query.cc')
-rw-r--r-- | chrome/browser/printing/printer_query.cc | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc index f39960f..e20ebc5 100644 --- a/chrome/browser/printing/printer_query.cc +++ b/chrome/browser/printing/printer_query.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "base/threading/thread_restrictions.h" +#include "base/values.h" #include "chrome/browser/printing/print_job_worker.h" namespace printing { @@ -78,10 +79,38 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, CancelableTask* callback) { DCHECK_EQ(io_message_loop_, MessageLoop::current()); DCHECK(!is_print_dialog_box_shown_); + if (!StartWorker(callback)) + return; + + // Real work is done in PrintJobWorker::Init(). + is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; + worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + worker_.get(), + &PrintJobWorker::GetSettings, + is_print_dialog_box_shown_, + parent_view, + expected_page_count, + has_selection, + use_overlays)); +} + +void PrinterQuery::SetSettings(const DictionaryValue& new_settings, + CancelableTask* callback) { + if (!StartWorker(callback)) + return; + + worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + worker_.get(), + &PrintJobWorker::SetSettings, + new_settings.DeepCopy())); +} + +bool PrinterQuery::StartWorker(CancelableTask* callback) { DCHECK(!callback_.get()); DCHECK(worker_.get()); if (!worker_.get()) - return; + return false; + // Lazy create the worker thread. There is one worker thread per print job. if (!worker_->message_loop()) { if (!worker_->Start()) { @@ -90,21 +119,11 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, delete callback; } NOTREACHED(); - return; + return false; } } - callback_.reset(callback); - // Real work is done in PrintJobWorker::Init(). - is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; - worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - worker_.get(), - &PrintJobWorker::GetSettings, - is_print_dialog_box_shown_, - parent_view, - expected_page_count, - has_selection, - use_overlays)); + return true; } void PrinterQuery::StopWorker() { |