Chromium Code Reviews| Index: chrome/browser/printing/print_job_worker.cc |
| diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc |
| index 77ca7dfb18317a367d3b5b3e71801d1e51404691..491ceee66757bd6cf6bada4026e2e33ca6403766 100644 |
| --- a/chrome/browser/printing/print_job_worker.cc |
| +++ b/chrome/browser/printing/print_job_worker.cc |
| @@ -4,7 +4,9 @@ |
| #include "chrome/browser/printing/print_job_worker.h" |
| +#include "base/json/json_reader.h" |
| #include "base/message_loop.h" |
| +#include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/browser_thread.h" |
| #include "chrome/browser/printing/print_job.h" |
| @@ -98,6 +100,50 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings, |
| } |
| } |
| +void PrintJobWorker::SetSettings(const std::string& new_settings) { |
| + DCHECK_EQ(message_loop(), MessageLoop::current()); |
| + DCHECK_EQ(page_number_, PageNumber::npos()); |
| + |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings, |
| + new_settings)); |
| +} |
| + |
| +void PrintJobWorker::UpdatePrintSettings(const std::string& new_settings) { |
|
Lei Zhang
2011/02/24 03:49:32
Have you considered parsing (and maybe validating)
kmadhusu
2011/03/01 01:55:50
Fixed. Now UpdatePrintSettings() has a dictionary
|
| + scoped_ptr<Value> parsed_value(base::JSONReader::Read(new_settings, false)); |
| + if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) { |
| + NOTREACHED() << "Unable to parse print params"; |
| + return; |
| + } |
| + DictionaryValue* settings = |
|
Lei Zhang
2011/02/24 03:49:32
nit: you don't need separate |settings| and |parse
kmadhusu
2011/03/01 01:55:50
Done.
|
| + static_cast<DictionaryValue*>(parsed_value.get()); |
| + |
| + // Create new PageRanges based on |new_settings|. |
| + PageRanges new_ranges; |
| + ListValue* pageRangeArray = NULL; |
|
Lei Zhang
2011/02/24 03:49:32
you don't need this assignment or the ones below f
kmadhusu
2011/03/01 01:55:50
Done.
|
| + if (settings->GetList("pageRange", &pageRangeArray)) { |
| + for (size_t index = 0; index < pageRangeArray->GetSize(); index++) { |
| + DictionaryValue* dict = NULL; |
| + pageRangeArray->GetDictionary(index, &dict); |
| + if (dict) { |
| + int printFrom = 0; |
|
Lei Zhang
2011/02/24 03:49:32
Can you get rid of |printFrom| and |printTo|, inst
kmadhusu
2011/03/01 01:55:50
Done.
|
| + int printTo = 0; |
| + if (dict->GetInteger("from", &printFrom) && |
| + dict->GetInteger("to", &printTo)) { |
| + PageRange range; |
| + // Page numbers are 0-based. |
| + range.from = printFrom - 1; |
| + range.to = printTo - 1; |
| + new_ranges.push_back(range); |
| + } |
| + } |
| + } |
| + } |
| + PrintingContext::Result result = |
| + printing_context_->UpdatePrintSettings(new_ranges); |
| + GetSettingsDone(result); |
| +} |
| + |
| void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { |
| // Most PrintingContext functions may start a message loop and process |
| // message recursively, so disable recursive task processing. |