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

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

Issue 125082: Add Print Selection support to Chrome. This change is fairly involved since ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/printing/print_job.h" 8 #include "chrome/browser/printing/print_job.h"
9 #include "chrome/browser/printing/printed_document.h" 9 #include "chrome/browser/printing/printed_document.h"
10 #include "chrome/browser/printing/printed_page.h" 10 #include "chrome/browser/printing/printed_page.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // The job which originates this notification. 44 // The job which originates this notification.
45 scoped_refptr<PrintJobWorkerOwner> print_job_; 45 scoped_refptr<PrintJobWorkerOwner> print_job_;
46 scoped_refptr<JobEventDetails> details_; 46 scoped_refptr<JobEventDetails> details_;
47 }; 47 };
48 48
49 49
50 PrintJobWorker::PrintJobWorker(PrintJobWorkerOwner* owner) 50 PrintJobWorker::PrintJobWorker(PrintJobWorkerOwner* owner)
51 : Thread("Printing_Worker"), 51 : Thread("Printing_Worker"),
52 owner_(owner) { 52 owner_(owner) {
53 // The object is created in the UI thread. 53 // The object is created in the IO thread.
54 DCHECK_EQ(owner_->message_loop(), MessageLoop::current()); 54 DCHECK_EQ(owner_->message_loop(), MessageLoop::current());
55 } 55 }
56 56
57 PrintJobWorker::~PrintJobWorker() { 57 PrintJobWorker::~PrintJobWorker() {
58 // The object is deleted in the UI thread. 58 // The object is deleted in the UI thread.
59 DCHECK_EQ(owner_->message_loop(), MessageLoop::current()); 59 DCHECK_EQ(owner_->message_loop(), MessageLoop::current());
60 } 60 }
61 61
62 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { 62 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
63 DCHECK(page_number_ == PageNumber::npos()); 63 DCHECK(page_number_ == PageNumber::npos());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 // We have enough information to initialize page_number_. 161 // We have enough information to initialize page_number_.
162 page_number_.Init(document_->settings(), page_count); 162 page_number_.Init(document_->settings(), page_count);
163 } 163 }
164 DCHECK_NE(page_number_, PageNumber::npos()); 164 DCHECK_NE(page_number_, PageNumber::npos());
165 165
166 for (;;) { 166 for (;;) {
167 // Is the page available? 167 // Is the page available?
168 scoped_refptr<PrintedPage> page; 168 scoped_refptr<PrintedPage> page;
169 if (!document_->GetPage(page_number_.ToInt(), &page)) { 169 if (!document_->GetPage(page_number_.ToInt(), &page)) {
170 // The page is implictly requested. 170 // The page is implicitly requested.
171 break; 171 break;
172 } 172 }
173 // The page is there, print it. 173 // The page is there, print it.
174 SpoolPage(*page); 174 SpoolPage(*page);
175 ++page_number_; 175 ++page_number_;
176 if (page_number_ == PageNumber::npos()) { 176 if (page_number_ == PageNumber::npos()) {
177 OnDocumentDone(); 177 OnDocumentDone();
178 // Don't touch this anymore since the instance could be destroyed. 178 // Don't touch this anymore since the instance could be destroyed.
179 break; 179 break;
180 } 180 }
181 } 181 }
182 } 182 }
183 183
184 void PrintJobWorker::Cancel() { 184 void PrintJobWorker::Cancel() {
185 // This is the only function that can be called from any thread. 185 // This is the only function that can be called from any thread.
186 printing_context_.Cancel(); 186 printing_context_.Cancel();
187 // Cannot touch any member variable since we don't know in which thread 187 // Cannot touch any member variable since we don't know in which thread
188 // context we run. 188 // context we run.
189 } 189 }
190 190
191 void PrintJobWorker::DismissDialog() { 191 void PrintJobWorker::DismissDialog() {
192 printing_context_.DismissDialog(); 192 printing_context_.DismissDialog();
193 } 193 }
194 194
195 void PrintJobWorker::RequestMissingPages() {
196 DCHECK_EQ(message_loop(), MessageLoop::current());
197 // It may arrive out of order. Don't mind about it.
198 if (page_number_ != PageNumber::npos()) {
199 // We are printing.
200 document_->RequestMissingPages();
201 }
202 NotificationTask* task = new NotificationTask();
203 task->Init(owner_,
204 JobEventDetails::ALL_PAGES_REQUESTED,
205 document_.get(),
206 NULL);
207 owner_->message_loop()->PostTask(FROM_HERE, task);
208 }
209
210 void PrintJobWorker::OnDocumentDone() { 195 void PrintJobWorker::OnDocumentDone() {
211 DCHECK_EQ(message_loop(), MessageLoop::current()); 196 DCHECK_EQ(message_loop(), MessageLoop::current());
212 DCHECK_EQ(page_number_, PageNumber::npos()); 197 DCHECK_EQ(page_number_, PageNumber::npos());
213 DCHECK(document_.get()); 198 DCHECK(document_.get());
214 DCHECK(printing_context_.context()); 199 DCHECK(printing_context_.context());
215 200
216 if (printing_context_.DocumentDone() != PrintingContext::OK) { 201 if (printing_context_.DocumentDone() != PrintingContext::OK) {
217 OnFailure(); 202 OnFailure();
218 return; 203 return;
219 } 204 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 printing::PrintJobWorker* obj) { 279 printing::PrintJobWorker* obj) {
295 DCHECK(!owner_.get()); 280 DCHECK(!owner_.get());
296 owner_ = obj->owner_; 281 owner_ = obj->owner_;
297 } 282 }
298 283
299 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( 284 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee(
300 printing::PrintJobWorker* obj) { 285 printing::PrintJobWorker* obj) {
301 DCHECK_EQ(owner_, obj->owner_); 286 DCHECK_EQ(owner_, obj->owner_);
302 owner_ = NULL; 287 owner_ = NULL;
303 } 288 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_worker.h ('k') | chrome/browser/printing/print_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698