Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/printing/print_job_worker.h" | 5 #include "chrome/browser/printing/print_job_worker.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/values.h" | |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/printing/print_job.h" | 11 #include "chrome/browser/printing/print_job.h" |
| 11 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 12 #include "printing/printed_document.h" | 13 #include "printing/printed_document.h" |
| 13 #include "printing/printed_page.h" | 14 #include "printing/printed_page.h" |
| 14 | 15 |
| 15 namespace printing { | 16 namespace printing { |
| 16 | 17 |
| 17 class PrintJobWorker::NotificationTask : public Task { | 18 class PrintJobWorker::NotificationTask : public Task { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 BrowserThread::UI, FROM_HERE, | 92 BrowserThread::UI, FROM_HERE, |
| 92 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, | 93 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, |
| 93 parent_view, document_page_count, | 94 parent_view, document_page_count, |
| 94 has_selection)); | 95 has_selection)); |
| 95 } else { | 96 } else { |
| 96 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 97 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 97 NewRunnableMethod(this, &PrintJobWorker::UseDefaultSettings)); | 98 NewRunnableMethod(this, &PrintJobWorker::UseDefaultSettings)); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 102 void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) { | |
| 103 DCHECK_EQ(message_loop(), MessageLoop::current()); | |
| 104 DCHECK_EQ(page_number_, PageNumber::npos()); | |
|
Lei Zhang
2011/03/02 23:28:54
Do we need this DCHECK here?
kmadhusu
2011/03/04 19:39:02
It is not required. Fixed.
| |
| 105 | |
| 106 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 107 NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings, | |
| 108 new_settings)); | |
| 109 } | |
| 110 | |
| 111 void PrintJobWorker::UpdatePrintSettings( | |
| 112 const DictionaryValue* const new_settings) { | |
| 113 // Create new PageRanges based on |new_settings|. | |
| 114 PageRanges new_ranges; | |
| 115 ListValue* pageRangeArray; | |
|
Lei Zhang
2011/03/02 23:28:54
nit: pageRangeArray -> page_range_array.
kmadhusu
2011/03/04 19:39:02
Done.
| |
| 116 if (new_settings->GetList("pageRange", &pageRangeArray)) { | |
| 117 for (size_t index = 0; index < pageRangeArray->GetSize(); index++) { | |
|
Lei Zhang
2011/03/02 23:28:54
index++ -> ++index
kmadhusu
2011/03/04 19:39:02
Done.
| |
| 118 DictionaryValue* dict; | |
| 119 pageRangeArray->GetDictionary(index, &dict); | |
| 120 if (dict) { | |
|
Lei Zhang
2011/03/02 23:28:54
This is not the right way to check if |dict| is va
kmadhusu
2011/03/04 19:39:02
Fixed.
| |
| 121 PageRange range; | |
| 122 if (dict->GetInteger("from", &range.from) && | |
| 123 dict->GetInteger("to", &range.to)) { | |
| 124 // Page numbers are 0-based. | |
| 125 range.from--; | |
| 126 range.to--; | |
| 127 new_ranges.push_back(range); | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 // We don't update any other print job settings now, so delete |new_settings|. | |
| 133 if (new_settings) | |
|
Lei Zhang
2011/03/02 23:28:54
You don't need this check, you've already assumed
kmadhusu
2011/03/04 19:39:02
Done.
| |
| 134 delete new_settings; | |
| 135 PrintingContext::Result result = | |
| 136 printing_context_->UpdatePrintSettings(new_ranges); | |
| 137 GetSettingsDone(result); | |
| 138 } | |
| 139 | |
| 101 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { | 140 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { |
| 102 // Most PrintingContext functions may start a message loop and process | 141 // Most PrintingContext functions may start a message loop and process |
| 103 // message recursively, so disable recursive task processing. | 142 // message recursively, so disable recursive task processing. |
| 104 // TODO(thestig): see above comment. SetNestableTasksAllowed(false) needs to | 143 // TODO(thestig): see above comment. SetNestableTasksAllowed(false) needs to |
| 105 // be called on the same thread as the previous call. See | 144 // be called on the same thread as the previous call. See |
| 106 // http://crbug.com/73466 | 145 // http://crbug.com/73466 |
| 107 // MessageLoop::current()->SetNestableTasksAllowed(false); | 146 // MessageLoop::current()->SetNestableTasksAllowed(false); |
| 108 | 147 |
| 109 // We can't use OnFailure() here since owner_ may not support notifications. | 148 // We can't use OnFailure() here since owner_ may not support notifications. |
| 110 | 149 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 printing::PrintJobWorker* obj) { | 355 printing::PrintJobWorker* obj) { |
| 317 DCHECK(!owner_.get()); | 356 DCHECK(!owner_.get()); |
| 318 owner_ = obj->owner_; | 357 owner_ = obj->owner_; |
| 319 } | 358 } |
| 320 | 359 |
| 321 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( | 360 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( |
| 322 printing::PrintJobWorker* obj) { | 361 printing::PrintJobWorker* obj) { |
| 323 DCHECK_EQ(owner_, obj->owner_); | 362 DCHECK_EQ(owner_, obj->owner_); |
| 324 owner_ = NULL; | 363 owner_ = NULL; |
| 325 } | 364 } |
| OLD | NEW |