Index: chrome/browser/printing/printer_query.cc |
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc |
index f39960f89ff0fd2db6c1802881b730a2bcfe29d4..1fea29cc3cc36a9c0452fe723d0f8c8331f7cb56 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,39 @@ 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; |
+ |
+ scoped_ptr<DictionaryValue> new_settings_copy(new_settings.DeepCopy()); |
Lei Zhang
2011/03/03 00:22:44
Probably don't need the scoped_ptr if you are allo
kmadhusu
2011/03/04 19:39:02
Done.
|
+ worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
+ worker_.get(), |
+ &PrintJobWorker::SetSettings, |
+ new_settings_copy.release())); |
+} |
+ |
+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 +120,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() { |