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 #include "chrome/browser/printing/printing_ui_web_contents_observer.h" |
14 | 14 |
15 namespace printing { | 15 namespace printing { |
16 | 16 |
17 PrinterQuery::PrinterQuery() | 17 PrinterQuery::PrinterQuery(int render_process_id, int render_view_id) |
18 : worker_(new PrintJobWorker(this)), | 18 : worker_(new PrintJobWorker(render_process_id, render_view_id, 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(base::MessageLoopForIO::IsCurrent()); | 22 DCHECK(base::MessageLoopForIO::IsCurrent()); |
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. |
(...skipping 30 matching lines...) Expand all Loading... |
59 const PrintSettings& PrinterQuery::settings() const { | 59 const PrintSettings& PrinterQuery::settings() const { |
60 return settings_; | 60 return settings_; |
61 } | 61 } |
62 | 62 |
63 int PrinterQuery::cookie() const { | 63 int PrinterQuery::cookie() const { |
64 return cookie_; | 64 return cookie_; |
65 } | 65 } |
66 | 66 |
67 void PrinterQuery::GetSettings( | 67 void PrinterQuery::GetSettings( |
68 GetSettingsAskParam ask_user_for_settings, | 68 GetSettingsAskParam ask_user_for_settings, |
69 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, | |
70 int expected_page_count, | 69 int expected_page_count, |
71 bool has_selection, | 70 bool has_selection, |
72 MarginType margin_type, | 71 MarginType margin_type, |
73 const base::Closure& callback) { | 72 const base::Closure& callback) { |
74 DCHECK(RunsTasksOnCurrentThread()); | 73 DCHECK(RunsTasksOnCurrentThread()); |
75 DCHECK(!is_print_dialog_box_shown_); | 74 DCHECK(!is_print_dialog_box_shown_); |
76 | 75 |
77 StartWorker(callback); | 76 StartWorker(callback); |
78 | 77 |
79 // Real work is done in PrintJobWorker::GetSettings(). | 78 // Real work is done in PrintJobWorker::GetSettings(). |
80 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; | 79 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; |
81 worker_->PostTask(FROM_HERE, | 80 worker_->PostTask(FROM_HERE, |
82 base::Bind(&PrintJobWorker::GetSettings, | 81 base::Bind(&PrintJobWorker::GetSettings, |
83 base::Unretained(worker_.get()), | 82 base::Unretained(worker_.get()), |
84 is_print_dialog_box_shown_, | 83 is_print_dialog_box_shown_, |
85 base::Passed(&web_contents_observer), | |
86 expected_page_count, | 84 expected_page_count, |
87 has_selection, | 85 has_selection, |
88 margin_type)); | 86 margin_type)); |
89 } | 87 } |
90 | 88 |
91 void PrinterQuery::SetSettings(scoped_ptr<base::DictionaryValue> new_settings, | 89 void PrinterQuery::SetSettings(scoped_ptr<base::DictionaryValue> new_settings, |
92 const base::Closure& callback) { | 90 const base::Closure& callback) { |
93 StartWorker(callback); | 91 StartWorker(callback); |
94 | 92 |
95 worker_->PostTask(FROM_HERE, | 93 worker_->PostTask(FROM_HERE, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 125 |
128 bool PrinterQuery::is_callback_pending() const { | 126 bool PrinterQuery::is_callback_pending() const { |
129 return !callback_.is_null(); | 127 return !callback_.is_null(); |
130 } | 128 } |
131 | 129 |
132 bool PrinterQuery::is_valid() const { | 130 bool PrinterQuery::is_valid() const { |
133 return worker_.get() != NULL; | 131 return worker_.get() != NULL; |
134 } | 132 } |
135 | 133 |
136 } // namespace printing | 134 } // namespace printing |
OLD | NEW |