| 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.h" | 9 #include "base/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 | 13 |
| 14 namespace printing { | 14 namespace printing { |
| 15 | 15 |
| 16 PrinterQuery::PrinterQuery() | 16 PrinterQuery::PrinterQuery() |
| 17 : io_message_loop_(MessageLoop::current()), | 17 : io_message_loop_(base::MessageLoop::current()), |
| 18 worker_(new PrintJobWorker(this)), | 18 worker_(new PrintJobWorker(this)), |
| 19 is_print_dialog_box_shown_(false), | 19 is_print_dialog_box_shown_(false), |
| 20 cookie_(PrintSettings::NewCookie()), | 20 cookie_(PrintSettings::NewCookie()), |
| 21 last_status_(PrintingContext::FAILED) { | 21 last_status_(PrintingContext::FAILED) { |
| 22 DCHECK_EQ(io_message_loop_->type(), MessageLoop::TYPE_IO); | 22 DCHECK_EQ(io_message_loop_->type(), base::MessageLoop::TYPE_IO); |
| 23 } | 23 } |
| 24 | 24 |
| 25 PrinterQuery::~PrinterQuery() { | 25 PrinterQuery::~PrinterQuery() { |
| 26 // The job should be finished (or at least canceled) when it is destroyed. | 26 // The job should be finished (or at least canceled) when it is destroyed. |
| 27 DCHECK(!is_print_dialog_box_shown_); | 27 DCHECK(!is_print_dialog_box_shown_); |
| 28 // If this fires, it is that this pending printer context has leaked. | 28 // If this fires, it is that this pending printer context has leaked. |
| 29 DCHECK(!worker_.get()); | 29 DCHECK(!worker_.get()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings, | 32 void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 int PrinterQuery::cookie() const { | 67 int PrinterQuery::cookie() const { |
| 68 return cookie_; | 68 return cookie_; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, | 71 void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, |
| 72 gfx::NativeView parent_view, | 72 gfx::NativeView parent_view, |
| 73 int expected_page_count, | 73 int expected_page_count, |
| 74 bool has_selection, | 74 bool has_selection, |
| 75 MarginType margin_type, | 75 MarginType margin_type, |
| 76 const base::Closure& callback) { | 76 const base::Closure& callback) { |
| 77 DCHECK_EQ(io_message_loop_, MessageLoop::current()); | 77 DCHECK_EQ(io_message_loop_, base::MessageLoop::current()); |
| 78 DCHECK(!is_print_dialog_box_shown_); | 78 DCHECK(!is_print_dialog_box_shown_); |
| 79 | 79 |
| 80 StartWorker(callback); | 80 StartWorker(callback); |
| 81 | 81 |
| 82 // Real work is done in PrintJobWorker::Init(). | 82 // Real work is done in PrintJobWorker::Init(). |
| 83 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; | 83 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; |
| 84 worker_->message_loop()->PostTask( | 84 worker_->message_loop()->PostTask( |
| 85 FROM_HERE, | 85 FROM_HERE, |
| 86 base::Bind(&PrintJobWorker::GetSettings, | 86 base::Bind(&PrintJobWorker::GetSettings, |
| 87 base::Unretained(worker_.get()), | 87 base::Unretained(worker_.get()), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 bool PrinterQuery::is_callback_pending() const { | 130 bool PrinterQuery::is_callback_pending() const { |
| 131 return !callback_.is_null(); | 131 return !callback_.is_null(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool PrinterQuery::is_valid() const { | 134 bool PrinterQuery::is_valid() const { |
| 135 return worker_.get() != NULL; | 135 return worker_.get() != NULL; |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace printing | 138 } // namespace printing |
| OLD | NEW |