This source file includes following definitions.
- last_status_
- GetSettingsDone
- DetachWorker
- message_loop
- settings
- cookie
- GetSettings
- SetSettings
- SetWorkerDestination
- StartWorker
- StopWorker
- is_callback_pending
- is_valid
#include "chrome/browser/printing/printer_query.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "chrome/browser/printing/print_job_worker.h"
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
namespace printing {
PrinterQuery::PrinterQuery()
: io_message_loop_(base::MessageLoop::current()),
worker_(new PrintJobWorker(this)),
is_print_dialog_box_shown_(false),
cookie_(PrintSettings::NewCookie()),
last_status_(PrintingContext::FAILED) {
DCHECK(base::MessageLoopForIO::IsCurrent());
}
PrinterQuery::~PrinterQuery() {
DCHECK(!is_print_dialog_box_shown_);
DCHECK(!worker_.get());
}
void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings,
PrintingContext::Result result) {
is_print_dialog_box_shown_ = false;
last_status_ = result;
if (result != PrintingContext::FAILED) {
settings_ = new_settings;
cookie_ = PrintSettings::NewCookie();
} else {
cookie_ = 0;
}
if (!callback_.is_null()) {
callback_.Run();
callback_.Reset();
}
}
PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) {
DCHECK(callback_.is_null());
DCHECK(worker_.get());
worker_->SetNewOwner(new_owner);
return worker_.release();
}
base::MessageLoop* PrinterQuery::message_loop() {
return io_message_loop_;
}
const PrintSettings& PrinterQuery::settings() const {
return settings_;
}
int PrinterQuery::cookie() const {
return cookie_;
}
void PrinterQuery::GetSettings(
GetSettingsAskParam ask_user_for_settings,
scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer,
int expected_page_count,
bool has_selection,
MarginType margin_type,
const base::Closure& callback) {
DCHECK_EQ(io_message_loop_, base::MessageLoop::current());
DCHECK(!is_print_dialog_box_shown_);
StartWorker(callback);
is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER;
worker_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PrintJobWorker::GetSettings,
base::Unretained(worker_.get()),
is_print_dialog_box_shown_,
base::Passed(&web_contents_observer),
expected_page_count,
has_selection,
margin_type));
}
void PrinterQuery::SetSettings(const base::DictionaryValue& new_settings,
const base::Closure& callback) {
StartWorker(callback);
worker_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PrintJobWorker::SetSettings,
base::Unretained(worker_.get()),
new_settings.DeepCopy()));
}
void PrinterQuery::SetWorkerDestination(
PrintDestinationInterface* destination) {
worker_->SetPrintDestination(destination);
}
void PrinterQuery::StartWorker(const base::Closure& callback) {
DCHECK(callback_.is_null());
DCHECK(worker_.get());
if (!worker_->message_loop())
worker_->Start();
callback_ = callback;
}
void PrinterQuery::StopWorker() {
if (worker_.get()) {
base::ThreadRestrictions::ScopedAllowIO allow_io;
worker_->Stop();
worker_.reset();
}
}
bool PrinterQuery::is_callback_pending() const {
return !callback_.is_null();
}
bool PrinterQuery::is_valid() const {
return worker_.get() != NULL;
}
}