| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/gfx/native_widget_types.h" | 9 #include "base/gfx/native_widget_types.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // PrintingContext though PrintJob::Worker. Hides access to PrintingContext in a | 31 // PrintingContext though PrintJob::Worker. Hides access to PrintingContext in a |
| 32 // worker thread so the caller never blocks. PrintJob will send notifications on | 32 // worker thread so the caller never blocks. PrintJob will send notifications on |
| 33 // any state change. While printing, the PrintJobManager instance keeps a | 33 // any state change. While printing, the PrintJobManager instance keeps a |
| 34 // reference to the job to be sure it is kept alive. All the code in this class | 34 // reference to the job to be sure it is kept alive. All the code in this class |
| 35 // runs in the UI thread. | 35 // runs in the UI thread. |
| 36 class PrintJob : public base::RefCountedThreadSafe<PrintJob>, | 36 class PrintJob : public base::RefCountedThreadSafe<PrintJob>, |
| 37 public NotificationObserver, | 37 public NotificationObserver, |
| 38 public PrintJobWorkerOwner, | 38 public PrintJobWorkerOwner, |
| 39 public MessageLoop::DestructionObserver { | 39 public MessageLoop::DestructionObserver { |
| 40 public: | 40 public: |
| 41 // GetSettings() UI parameter. | |
| 42 enum GetSettingsAskParam { | |
| 43 DEFAULTS, | |
| 44 ASK_USER, | |
| 45 }; | |
| 46 | |
| 47 // Create a standalone PrintJob. When initializing with this constructor, | |
| 48 // Initialize() must not be called. | |
| 49 PrintJob(PrintedPagesSource* source); | |
| 50 // Create a empty PrintJob. When initializing with this constructor, | 41 // Create a empty PrintJob. When initializing with this constructor, |
| 51 // post-constructor initialization must be done with Initialize(). | 42 // post-constructor initialization must be done with Initialize(). |
| 52 PrintJob(); | 43 PrintJob(); |
| 53 virtual ~PrintJob(); | 44 virtual ~PrintJob(); |
| 54 | 45 |
| 55 // Grabs the ownership of the PrintJobWorker from another job, which is | 46 // Grabs the ownership of the PrintJobWorker from another job, which is |
| 56 // usually a PrinterQuery. | 47 // usually a PrinterQuery. |
| 57 void Initialize(PrintJobWorkerOwner* job, PrintedPagesSource* source); | 48 void Initialize(PrintJobWorkerOwner* job, PrintedPagesSource* source); |
| 58 | 49 |
| 59 // NotificationObserver | 50 // NotificationObserver |
| 60 virtual void Observe(NotificationType type, | 51 virtual void Observe(NotificationType type, |
| 61 const NotificationSource& source, | 52 const NotificationSource& source, |
| 62 const NotificationDetails& details); | 53 const NotificationDetails& details); |
| 63 | 54 |
| 64 // PrintJobWorkerOwner | 55 // PrintJobWorkerOwner |
| 65 virtual void AddRef() { | 56 virtual void AddRef() { |
| 66 return base::RefCountedThreadSafe<PrintJob>::AddRef(); | 57 return base::RefCountedThreadSafe<PrintJob>::AddRef(); |
| 67 } | 58 } |
| 68 virtual void Release() { | 59 virtual void Release() { |
| 69 return base::RefCountedThreadSafe<PrintJob>::Release(); | 60 return base::RefCountedThreadSafe<PrintJob>::Release(); |
| 70 } | 61 } |
| 62 |
| 71 virtual void GetSettingsDone(const PrintSettings& new_settings, | 63 virtual void GetSettingsDone(const PrintSettings& new_settings, |
| 72 PrintingContext::Result result); | 64 PrintingContext::Result result); |
| 73 virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner); | 65 virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner); |
| 74 virtual MessageLoop* message_loop() { return ui_message_loop_; } | 66 virtual MessageLoop* message_loop() { return ui_message_loop_; } |
| 75 virtual const PrintSettings& settings() const { return settings_; } | 67 virtual const PrintSettings& settings() const { return settings_; } |
| 76 virtual int cookie() const; | 68 virtual int cookie() const; |
| 77 | 69 |
| 78 // DestructionObserver | 70 // DestructionObserver |
| 79 virtual void WillDestroyCurrentMessageLoop(); | 71 virtual void WillDestroyCurrentMessageLoop(); |
| 80 | 72 |
| 81 // Initializes the printing context. This can be done synchronously or not. It | |
| 82 // is fine to call this function multiple times to reinitialize the settings. | |
| 83 // |parent_window| parameter will be the owner of the print setting dialog | |
| 84 // box. It is unused when |ask_for_user_settings| is DEFAULTS. No-op if a | |
| 85 // print job is active. | |
| 86 void GetSettings(GetSettingsAskParam ask_user_for_settings, | |
| 87 gfx::NativeView parent_window); | |
| 88 | |
| 89 // Starts the actual printing. Signals the worker that it should begin to | 73 // Starts the actual printing. Signals the worker that it should begin to |
| 90 // spool as soon as data is available. | 74 // spool as soon as data is available. |
| 91 void StartPrinting(); | 75 void StartPrinting(); |
| 92 | 76 |
| 93 // Waits for the worker thread to finish its queued tasks and disconnects the | 77 // Waits for the worker thread to finish its queued tasks and disconnects the |
| 94 // delegate object. The PrintJobManager will remove it reference. This may | 78 // delegate object. The PrintJobManager will remove it reference. This may |
| 95 // have the side-effect of destroying the object if the caller doesn't have a | 79 // have the side-effect of destroying the object if the caller doesn't have a |
| 96 // handle to the object. | 80 // handle to the object. |
| 97 void Stop(); | 81 void Stop(); |
| 98 | 82 |
| 99 // Cancels printing job and stops the worker thread. Takes effect immediately. | 83 // Cancels printing job and stops the worker thread. Takes effect immediately. |
| 100 void Cancel(); | 84 void Cancel(); |
| 101 | 85 |
| 102 // Requests all the missing pages in the PrintedDocument. Returns true if at | |
| 103 // least one page has been requested. Returns false if there was not enough | |
| 104 // information to request the missing pages, i.e. | |
| 105 // document()->document_page_count() is not initialized or no page | |
| 106 // has been requested. | |
| 107 bool RequestMissingPages(); | |
| 108 | |
| 109 // Synchronously wait for the job to finish. It is mainly useful when the | 86 // Synchronously wait for the job to finish. It is mainly useful when the |
| 110 // process is about to be shut down and we're waiting for the spooler to eat | 87 // process is about to be shut down and we're waiting for the spooler to eat |
| 111 // our data. | 88 // our data. |
| 112 bool FlushJob(int timeout_ms); | 89 bool FlushJob(int timeout_ms); |
| 113 | 90 |
| 114 // Disconnects the PrintedPage source (PrintedPagesSource). It is done when | 91 // Disconnects the PrintedPage source (PrintedPagesSource). It is done when |
| 115 // the source is being destroyed. | 92 // the source is being destroyed. |
| 116 void DisconnectSource(); | 93 void DisconnectSource(); |
| 117 | 94 |
| 118 // Returns true if the print job is pending, i.e. between a StartPrinting() | 95 // Returns true if the print job is pending, i.e. between a StartPrinting() |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 scoped_refptr<PrintedPage> page_; | 203 scoped_refptr<PrintedPage> page_; |
| 227 const Type type_; | 204 const Type type_; |
| 228 | 205 |
| 229 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); | 206 DISALLOW_COPY_AND_ASSIGN(JobEventDetails); |
| 230 }; | 207 }; |
| 231 | 208 |
| 232 } // namespace printing | 209 } // namespace printing |
| 233 | 210 |
| 234 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ | 211 #endif // CHROME_BROWSER_PRINTING_PRINT_JOB_H_ |
| 235 | 212 |
| OLD | NEW |