print_job_manager.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ 6#define CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ 7#pragma once 8 9#include <vector> 10 11#include "base/lock.h" 12#include "base/ref_counted.h" 13#include "chrome/common/notification_observer.h" 14#include "chrome/common/notification_registrar.h" 15 16namespace printing { 17 18class JobEventDetails; 19class PrintedDocument; 20class PrintJob; 21class PrintedPage; 22class PrinterQuery; 23 24class PrintJobManager : public NotificationObserver { 25 public: 26 PrintJobManager(); 27 ~PrintJobManager(); 28 29 // On browser quit, we should wait to have the print job finished. 30 void OnQuit(); 31 32 // Queues a semi-initialized worker thread. Can be called from any thread. 33 // Current use case is queuing from the I/O thread. 34 // TODO(maruel): Have them vanish after a timeout (~5 minutes?) 35 void QueuePrinterQuery(PrinterQuery* job); 36 37 // Pops a queued PrintJobWorkerOwner object that was previously queued. Can be 38 // called from any thread. Current use case is poping from the browser thread. 39 void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job); 40 41 // NotificationObserver 42 virtual void Observe(NotificationType type, 43 const NotificationSource& source, 44 const NotificationDetails& details); 45 46 private: 47 typedef std::vector<scoped_refptr<PrintJob> > PrintJobs; 48 typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries; 49 50 // Processes a NOTIFY_PRINT_JOB_EVENT notification. 51 void OnPrintJobEvent(PrintJob* print_job, 52 const JobEventDetails& event_details); 53 54 NotificationRegistrar registrar_; 55 56 // Used to serialize access to queued_workers_. 57 Lock lock_; 58 59 PrinterQueries queued_queries_; 60 61 // Current print jobs that are active. 62 PrintJobs current_jobs_; 63 64 DISALLOW_COPY_AND_ASSIGN(PrintJobManager); 65}; 66 67} // namespace printing 68 69#endif // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_ 70