OLD | NEW |
1 // Copyright (c) 2010 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/printer_query.h" | 5 #include "chrome/browser/printing/printer_query.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "chrome/browser/printing/print_job_worker.h" | 9 #include "chrome/browser/printing/print_job_worker.h" |
10 | 10 |
11 namespace printing { | 11 namespace printing { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 100 worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
101 worker_.get(), | 101 worker_.get(), |
102 &PrintJobWorker::GetSettings, | 102 &PrintJobWorker::GetSettings, |
103 is_print_dialog_box_shown_, | 103 is_print_dialog_box_shown_, |
104 parent_view, | 104 parent_view, |
105 expected_page_count, | 105 expected_page_count, |
106 has_selection, | 106 has_selection, |
107 use_overlays)); | 107 use_overlays)); |
108 } | 108 } |
109 | 109 |
| 110 void PrinterQuery::SetSettings(const std::string& new_settings, |
| 111 CancelableTask* callback) { |
| 112 DCHECK(!callback_.get()); |
| 113 DCHECK(worker_.get()); |
| 114 if (!worker_.get()) |
| 115 return; |
| 116 |
| 117 // Lazy create the worker thread. There is one worker thread per print job. |
| 118 if (!worker_->message_loop()) { |
| 119 if (!worker_->Start()) { |
| 120 if (callback) { |
| 121 callback->Cancel(); |
| 122 delete callback; |
| 123 } |
| 124 NOTREACHED(); |
| 125 return; |
| 126 } |
| 127 } |
| 128 |
| 129 callback_.reset(callback); |
| 130 worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 131 worker_.get(), |
| 132 &PrintJobWorker::SetSettings, |
| 133 new_settings)); |
| 134 } |
| 135 |
110 void PrinterQuery::StopWorker() { | 136 void PrinterQuery::StopWorker() { |
111 if (worker_.get()) { | 137 if (worker_.get()) { |
112 // http://crbug.com/66082: We're blocking on the PrinterQuery's worker | 138 // http://crbug.com/66082: We're blocking on the PrinterQuery's worker |
113 // thread. It's not clear to me if this may result in blocking the current | 139 // thread. It's not clear to me if this may result in blocking the current |
114 // thread for an unacceptable time. We should probably fix it. | 140 // thread for an unacceptable time. We should probably fix it. |
115 base::ThreadRestrictions::ScopedAllowIO allow_io; | 141 base::ThreadRestrictions::ScopedAllowIO allow_io; |
116 worker_->Stop(); | 142 worker_->Stop(); |
117 worker_.reset(); | 143 worker_.reset(); |
118 } | 144 } |
119 } | 145 } |
120 | 146 |
121 bool PrinterQuery::is_callback_pending() const { | 147 bool PrinterQuery::is_callback_pending() const { |
122 return callback_.get() != NULL; | 148 return callback_.get() != NULL; |
123 } | 149 } |
124 | 150 |
125 bool PrinterQuery::is_valid() const { | 151 bool PrinterQuery::is_valid() const { |
126 return worker_.get() != NULL; | 152 return worker_.get() != NULL; |
127 } | 153 } |
128 | 154 |
129 } // namespace printing | 155 } // namespace printing |
OLD | NEW |