Home | History | Annotate | Download | only in printing
      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
      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 <set>
      9 #include <vector>
     10 
     11 #include "base/memory/ref_counted.h"
     12 #include "base/synchronization/lock.h"
     13 #include "content/public/browser/notification_observer.h"
     14 #include "content/public/browser/notification_registrar.h"
     15 #include "printing/print_destination_interface.h"
     16 
     17 namespace printing {
     18 
     19 class JobEventDetails;
     20 class PrintJob;
     21 class PrinterQuery;
     22 
     23 class PrintJobManager : public content::NotificationObserver {
     24  public:
     25   PrintJobManager();
     26   virtual ~PrintJobManager();
     27 
     28   // On browser quit, we should wait to have the print job finished.
     29   void OnQuit();
     30 
     31   // Stops all printing jobs. If wait_for_finish is true, tries to give jobs
     32   // a chance to complete before stopping them.
     33   void StopJobs(bool wait_for_finish);
     34 
     35   // Sets the print destination to be set on the next print job.
     36   void SetPrintDestination(PrintDestinationInterface* destination);
     37 
     38   // Queues a semi-initialized worker thread. Can be called from any thread.
     39   // Current use case is queuing from the I/O thread.
     40   // TODO(maruel):  Have them vanish after a timeout (~5 minutes?)
     41   void QueuePrinterQuery(PrinterQuery* job);
     42 
     43   // Pops a queued PrintJobWorkerOwner object that was previously queued. Can be
     44   // called from any thread. Current use case is poping from the browser thread.
     45   void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job);
     46 
     47   // content::NotificationObserver
     48   virtual void Observe(int type,
     49                        const content::NotificationSource& source,
     50                        const content::NotificationDetails& details) OVERRIDE;
     51 
     52   // May return NULL when no destination was set.
     53   PrintDestinationInterface* destination() const { return destination_.get(); }
     54 
     55  private:
     56   typedef std::set<scoped_refptr<PrintJob> > PrintJobs;
     57   typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries;
     58 
     59   // Processes a NOTIFY_PRINT_JOB_EVENT notification.
     60   void OnPrintJobEvent(PrintJob* print_job,
     61                        const JobEventDetails& event_details);
     62 
     63   content::NotificationRegistrar registrar_;
     64 
     65   // Used to serialize access to queued_workers_.
     66   base::Lock lock_;
     67 
     68   PrinterQueries queued_queries_;
     69 
     70   scoped_refptr<PrintDestinationInterface> destination_;
     71 
     72   // Current print jobs that are active.
     73   PrintJobs current_jobs_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(PrintJobManager);
     76 };
     77 
     78 }  // namespace printing
     79 
     80 #endif  // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_
     81