• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/memory/ref_counted.h"
12 #include "base/synchronization/lock.h"
13 #include "content/common/notification_observer.h"
14 #include "content/common/notification_registrar.h"
15 
16 namespace printing {
17 
18 class JobEventDetails;
19 class PrintedDocument;
20 class PrintJob;
21 class PrintedPage;
22 class PrinterQuery;
23 
24 class 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   // Stops all printing jobs. If wait_for_finish is true, tries to give jobs
33   // a chance to complete before stopping them.
34   void StopJobs(bool wait_for_finish);
35 
36   // Queues a semi-initialized worker thread. Can be called from any thread.
37   // Current use case is queuing from the I/O thread.
38   // TODO(maruel):  Have them vanish after a timeout (~5 minutes?)
39   void QueuePrinterQuery(PrinterQuery* job);
40 
41   // Pops a queued PrintJobWorkerOwner object that was previously queued. Can be
42   // called from any thread. Current use case is poping from the browser thread.
43   void PopPrinterQuery(int document_cookie, scoped_refptr<PrinterQuery>* job);
44 
45   // NotificationObserver
46   virtual void Observe(NotificationType type,
47                        const NotificationSource& source,
48                        const NotificationDetails& details);
49 
50   bool printing_enabled();
51 
52   void set_printing_enabled(bool printing_enabled);
53 
54  private:
55   typedef std::vector<scoped_refptr<PrintJob> > PrintJobs;
56   typedef std::vector<scoped_refptr<PrinterQuery> > PrinterQueries;
57 
58   // Processes a NOTIFY_PRINT_JOB_EVENT notification.
59   void OnPrintJobEvent(PrintJob* print_job,
60                        const JobEventDetails& event_details);
61 
62   NotificationRegistrar registrar_;
63 
64   // Used to serialize access to queued_workers_.
65   base::Lock lock_;
66 
67   // Used to serialize access to printing_enabled_
68   base::Lock enabled_lock_;
69 
70   PrinterQueries queued_queries_;
71 
72   // Current print jobs that are active.
73   PrintJobs current_jobs_;
74 
75   // Printing is enabled/disabled. This variable is checked at only one place,
76   // by RenderMessageFilter::OnGetDefaultPrintSettings. If its value is true
77   // at that point, then the initiated print flow will complete itself,
78   // even if the value of this variable changes afterwards.
79   bool printing_enabled_;
80 
81   DISALLOW_COPY_AND_ASSIGN(PrintJobManager);
82 };
83 
84 }  // namespace printing
85 
86 #endif  // CHROME_BROWSER_PRINTING_PRINT_JOB_MANAGER_H_
87