Update printing code

This commit is contained in:
Cheng Zhao 2014-12-07 06:55:40 -08:00
parent 6d32db32ef
commit d309fd5a27
23 changed files with 665 additions and 485 deletions

View file

@ -22,11 +22,6 @@ PrintQueriesQueue::~PrintQueriesQueue() {
queued_queries_.clear();
}
void PrintQueriesQueue::SetDestination(PrintDestinationInterface* destination) {
base::AutoLock lock(lock_);
destination_ = destination;
}
void PrintQueriesQueue::QueuePrinterQuery(PrinterQuery* job) {
base::AutoLock lock(lock_);
DCHECK(job);
@ -49,17 +44,27 @@ scoped_refptr<PrinterQuery> PrintQueriesQueue::PopPrinterQuery(
return NULL;
}
scoped_refptr<PrinterQuery> PrintQueriesQueue::CreatePrinterQuery() {
scoped_refptr<PrinterQuery> job = new printing::PrinterQuery;
base::AutoLock lock(lock_);
job->SetWorkerDestination(destination_);
scoped_refptr<PrinterQuery> PrintQueriesQueue::CreatePrinterQuery(
int render_process_id,
int render_view_id) {
scoped_refptr<PrinterQuery> job =
new printing::PrinterQuery(render_process_id, render_view_id);
return job;
}
void PrintQueriesQueue::Shutdown() {
base::AutoLock lock(lock_);
queued_queries_.clear();
destination_ = NULL;
PrinterQueries queries_to_stop;
{
base::AutoLock lock(lock_);
queued_queries_.swap(queries_to_stop);
}
// Stop all pending queries, requests to generate print preview do not have
// corresponding PrintJob, so any pending preview requests are not covered
// by PrintJobManager::StopJobs and should be stopped explicitly.
for (PrinterQueries::iterator itr = queries_to_stop.begin();
itr != queries_to_stop.end(); ++itr) {
(*itr)->PostTask(FROM_HERE, base::Bind(&PrinterQuery::StopWorker, *itr));
}
}
PrintJobManager::PrintJobManager() : is_shutdown_(false) {
@ -72,7 +77,7 @@ PrintJobManager::~PrintJobManager() {
scoped_refptr<PrintQueriesQueue> PrintJobManager::queue() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (!queue_)
if (!queue_.get())
queue_ = new PrintQueriesQueue();
return queue_;
}
@ -83,7 +88,7 @@ void PrintJobManager::Shutdown() {
is_shutdown_ = true;
registrar_.RemoveAll();
StopJobs(true);
if (queue_)
if (queue_.get())
queue_->Shutdown();
queue_ = NULL;
}