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