Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/browser/printing/print_job_worker.cc

Issue 6533006: Print Preview: Hook up the print button to initiate printing without displaying a print dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed review comments. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_job_worker.h ('k') | chrome/browser/printing/printer_query.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/printing/print_job.h" 10 #include "chrome/browser/printing/print_job.h"
10 #include "chrome/common/notification_service.h" 11 #include "chrome/common/notification_service.h"
11 #include "content/browser/browser_thread.h" 12 #include "content/browser/browser_thread.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
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
105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
106 NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings,
107 new_settings));
108 }
109
110 void PrintJobWorker::UpdatePrintSettings(
111 const DictionaryValue* const new_settings) {
112 // Create new PageRanges based on |new_settings|.
113 PageRanges new_ranges;
114 ListValue* page_range_array;
115 if (new_settings->GetList("pageRange", &page_range_array)) {
116 for (size_t index = 0; index < page_range_array->GetSize(); ++index) {
117 DictionaryValue* dict;
118 if (page_range_array->GetDictionary(index, &dict)) {
119 PageRange range;
120 if (dict->GetInteger("from", &range.from) &&
121 dict->GetInteger("to", &range.to)) {
122 // Page numbers are 0-based.
123 range.from--;
124 range.to--;
125 new_ranges.push_back(range);
126 }
127 }
128 }
129 }
130 // We don't update any other print job settings now, so delete |new_settings|.
131 delete new_settings;
132 PrintingContext::Result result =
133 printing_context_->UpdatePrintSettings(new_ranges);
134 GetSettingsDone(result);
135 }
136
101 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { 137 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
102 // Most PrintingContext functions may start a message loop and process 138 // Most PrintingContext functions may start a message loop and process
103 // message recursively, so disable recursive task processing. 139 // message recursively, so disable recursive task processing.
104 // TODO(thestig): see above comment. SetNestableTasksAllowed(false) needs to 140 // TODO(thestig): see above comment. SetNestableTasksAllowed(false) needs to
105 // be called on the same thread as the previous call. See 141 // be called on the same thread as the previous call. See
106 // http://crbug.com/73466 142 // http://crbug.com/73466
107 // MessageLoop::current()->SetNestableTasksAllowed(false); 143 // MessageLoop::current()->SetNestableTasksAllowed(false);
108 144
109 // We can't use OnFailure() here since owner_ may not support notifications. 145 // We can't use OnFailure() here since owner_ may not support notifications.
110 146
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 printing::PrintJobWorker* obj) { 352 printing::PrintJobWorker* obj) {
317 DCHECK(!owner_.get()); 353 DCHECK(!owner_.get());
318 owner_ = obj->owner_; 354 owner_ = obj->owner_;
319 } 355 }
320 356
321 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( 357 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee(
322 printing::PrintJobWorker* obj) { 358 printing::PrintJobWorker* obj) {
323 DCHECK_EQ(owner_, obj->owner_); 359 DCHECK_EQ(owner_, obj->owner_);
324 owner_ = NULL; 360 owner_ = NULL;
325 } 361 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_worker.h ('k') | chrome/browser/printing/printer_query.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698