| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/printing/print_job_worker.h" | 12 #include "chrome/browser/printing/print_job_worker.h" |
| 13 #include "chrome/browser/printing/printing_ui_web_contents_observer.h" |
| 13 | 14 |
| 14 namespace printing { | 15 namespace printing { |
| 15 | 16 |
| 16 PrinterQuery::PrinterQuery() | 17 PrinterQuery::PrinterQuery() |
| 17 : io_message_loop_(base::MessageLoop::current()), | 18 : io_message_loop_(base::MessageLoop::current()), |
| 18 worker_(new PrintJobWorker(this)), | 19 worker_(new PrintJobWorker(this)), |
| 19 is_print_dialog_box_shown_(false), | 20 is_print_dialog_box_shown_(false), |
| 20 cookie_(PrintSettings::NewCookie()), | 21 cookie_(PrintSettings::NewCookie()), |
| 21 last_status_(PrintingContext::FAILED) { | 22 last_status_(PrintingContext::FAILED) { |
| 22 DCHECK_EQ(io_message_loop_->type(), base::MessageLoop::TYPE_IO); | 23 DCHECK_EQ(io_message_loop_->type(), base::MessageLoop::TYPE_IO); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 62 } |
| 62 | 63 |
| 63 const PrintSettings& PrinterQuery::settings() const { | 64 const PrintSettings& PrinterQuery::settings() const { |
| 64 return settings_; | 65 return settings_; |
| 65 } | 66 } |
| 66 | 67 |
| 67 int PrinterQuery::cookie() const { | 68 int PrinterQuery::cookie() const { |
| 68 return cookie_; | 69 return cookie_; |
| 69 } | 70 } |
| 70 | 71 |
| 71 void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, | 72 void PrinterQuery::GetSettings( |
| 72 gfx::NativeView parent_view, | 73 GetSettingsAskParam ask_user_for_settings, |
| 73 int expected_page_count, | 74 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, |
| 74 bool has_selection, | 75 int expected_page_count, |
| 75 MarginType margin_type, | 76 bool has_selection, |
| 76 const base::Closure& callback) { | 77 MarginType margin_type, |
| 78 const base::Closure& callback) { |
| 77 DCHECK_EQ(io_message_loop_, base::MessageLoop::current()); | 79 DCHECK_EQ(io_message_loop_, base::MessageLoop::current()); |
| 78 DCHECK(!is_print_dialog_box_shown_); | 80 DCHECK(!is_print_dialog_box_shown_); |
| 79 | 81 |
| 80 StartWorker(callback); | 82 StartWorker(callback); |
| 81 | 83 |
| 82 // Real work is done in PrintJobWorker::Init(). | 84 // Real work is done in PrintJobWorker::Init(). |
| 83 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; | 85 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; |
| 84 worker_->message_loop()->PostTask( | 86 worker_->message_loop()->PostTask( |
| 85 FROM_HERE, | 87 FROM_HERE, |
| 86 base::Bind(&PrintJobWorker::GetSettings, | 88 base::Bind(&PrintJobWorker::GetSettings, |
| 87 base::Unretained(worker_.get()), | 89 base::Unretained(worker_.get()), |
| 88 is_print_dialog_box_shown_, parent_view, | 90 is_print_dialog_box_shown_, |
| 89 expected_page_count, has_selection, margin_type)); | 91 base::Passed(&web_contents_observer), |
| 92 expected_page_count, |
| 93 has_selection, |
| 94 margin_type)); |
| 90 } | 95 } |
| 91 | 96 |
| 92 void PrinterQuery::SetSettings(const DictionaryValue& new_settings, | 97 void PrinterQuery::SetSettings(const DictionaryValue& new_settings, |
| 93 const base::Closure& callback) { | 98 const base::Closure& callback) { |
| 94 StartWorker(callback); | 99 StartWorker(callback); |
| 95 | 100 |
| 96 worker_->message_loop()->PostTask( | 101 worker_->message_loop()->PostTask( |
| 97 FROM_HERE, | 102 FROM_HERE, |
| 98 base::Bind(&PrintJobWorker::SetSettings, | 103 base::Bind(&PrintJobWorker::SetSettings, |
| 99 base::Unretained(worker_.get()), | 104 base::Unretained(worker_.get()), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 129 | 134 |
| 130 bool PrinterQuery::is_callback_pending() const { | 135 bool PrinterQuery::is_callback_pending() const { |
| 131 return !callback_.is_null(); | 136 return !callback_.is_null(); |
| 132 } | 137 } |
| 133 | 138 |
| 134 bool PrinterQuery::is_valid() const { | 139 bool PrinterQuery::is_valid() const { |
| 135 return worker_.get() != NULL; | 140 return worker_.get() != NULL; |
| 136 } | 141 } |
| 137 | 142 |
| 138 } // namespace printing | 143 } // namespace printing |
| OLD | NEW |