OLD | NEW |
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/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/printing/print_job.h" | 10 #include "chrome/browser/printing/print_job.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 bool use_overlays) { | 77 bool use_overlays) { |
78 DCHECK_EQ(message_loop(), MessageLoop::current()); | 78 DCHECK_EQ(message_loop(), MessageLoop::current()); |
79 DCHECK_EQ(page_number_, PageNumber::npos()); | 79 DCHECK_EQ(page_number_, PageNumber::npos()); |
80 | 80 |
81 // Recursive task processing is needed for the dialog in case it needs to be | 81 // Recursive task processing is needed for the dialog in case it needs to be |
82 // destroyed by a task. | 82 // destroyed by a task. |
83 MessageLoop::current()->SetNestableTasksAllowed(true); | 83 MessageLoop::current()->SetNestableTasksAllowed(true); |
84 printing_context_->set_use_overlays(use_overlays); | 84 printing_context_->set_use_overlays(use_overlays); |
85 | 85 |
86 if (ask_user_for_settings) { | 86 if (ask_user_for_settings) { |
87 #if defined(OS_MACOSX) || defined(USE_X11) | 87 #if defined(OS_POSIX) |
88 BrowserThread::PostTask( | 88 BrowserThread::PostTask( |
89 BrowserThread::UI, FROM_HERE, | 89 BrowserThread::UI, FROM_HERE, |
90 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, | 90 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, |
91 parent_view, document_page_count, | 91 parent_view, document_page_count, |
92 has_selection)); | 92 has_selection)); |
93 #else | 93 #else |
94 printing_context_->AskUserForSettings( | 94 printing_context_->AskUserForSettings( |
95 parent_view, | 95 parent_view, |
96 document_page_count, | 96 document_page_count, |
97 has_selection, | 97 has_selection, |
98 NewCallback(this, &PrintJobWorker::GetSettingsDone)); | 98 NewCallback(this, &PrintJobWorker::GetSettingsDone)); |
99 #endif // defined(OS_MACOSX) || defined(USE_X11) | 99 #endif // defined(OS_POSIX) |
100 } else { | 100 } else { |
101 PrintingContext::Result result = printing_context_->UseDefaultSettings(); | 101 PrintingContext::Result result = printing_context_->UseDefaultSettings(); |
102 GetSettingsDone(result); | 102 GetSettingsDone(result); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { | 106 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { |
107 // Most PrintingContext functions may start a message loop and process | 107 // Most PrintingContext functions may start a message loop and process |
108 // message recursively, so disable recursive task processing. | 108 // message recursively, so disable recursive task processing. |
109 MessageLoop::current()->SetNestableTasksAllowed(false); | 109 MessageLoop::current()->SetNestableTasksAllowed(false); |
110 | 110 |
111 // We can't use OnFailure() here since owner_ may not support notifications. | 111 // We can't use OnFailure() here since owner_ may not support notifications. |
112 | 112 |
113 // PrintJob will create the new PrintedDocument. | 113 // PrintJob will create the new PrintedDocument. |
114 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 114 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
115 owner_, | 115 owner_, |
116 &PrintJobWorkerOwner::GetSettingsDone, | 116 &PrintJobWorkerOwner::GetSettingsDone, |
117 printing_context_->settings(), | 117 printing_context_->settings(), |
118 result)); | 118 result)); |
119 } | 119 } |
120 | 120 |
121 #if defined(OS_MACOSX) || defined(USE_X11) | 121 #if defined(OS_POSIX) |
122 void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view, | 122 void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view, |
123 int document_page_count, | 123 int document_page_count, |
124 bool has_selection) { | 124 bool has_selection) { |
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
126 | 126 |
127 printing_context_->AskUserForSettings( | 127 printing_context_->AskUserForSettings( |
128 parent_view, | 128 parent_view, |
129 document_page_count, | 129 document_page_count, |
130 has_selection, | 130 has_selection, |
131 NewCallback(this, &PrintJobWorker::GetSettingsWithUIDone)); | 131 NewCallback(this, &PrintJobWorker::GetSettingsWithUIDone)); |
132 } | 132 } |
133 | 133 |
134 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { | 134 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { |
135 message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 135 message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
136 this, &PrintJobWorker::GetSettingsDone, result)); | 136 this, &PrintJobWorker::GetSettingsDone, result)); |
137 } | 137 } |
138 #endif // defined(OS_MACOSX) || defined(USE_X11) | 138 #endif // defined(OS_POSIX) |
139 | 139 |
140 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 140 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
141 DCHECK_EQ(message_loop(), MessageLoop::current()); | 141 DCHECK_EQ(message_loop(), MessageLoop::current()); |
142 DCHECK_EQ(page_number_, PageNumber::npos()); | 142 DCHECK_EQ(page_number_, PageNumber::npos()); |
143 DCHECK_EQ(document_, new_document); | 143 DCHECK_EQ(document_, new_document); |
144 DCHECK(document_.get()); | 144 DCHECK(document_.get()); |
145 DCHECK(new_document->settings().Equals(printing_context_->settings())); | 145 DCHECK(new_document->settings().Equals(printing_context_->settings())); |
146 | 146 |
147 if (!document_.get() || page_number_ != PageNumber::npos() || | 147 if (!document_.get() || page_number_ != PageNumber::npos() || |
148 document_ != new_document) { | 148 document_ != new_document) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 printing::PrintJobWorker* obj) { | 315 printing::PrintJobWorker* obj) { |
316 DCHECK(!owner_.get()); | 316 DCHECK(!owner_.get()); |
317 owner_ = obj->owner_; | 317 owner_ = obj->owner_; |
318 } | 318 } |
319 | 319 |
320 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( | 320 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( |
321 printing::PrintJobWorker* obj) { | 321 printing::PrintJobWorker* obj) { |
322 DCHECK_EQ(owner_, obj->owner_); | 322 DCHECK_EQ(owner_, obj->owner_); |
323 owner_ = NULL; | 323 owner_ = NULL; |
324 } | 324 } |
OLD | NEW |