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.
5 #ifndef CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
6 #define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/printing/print_job_worker_owner.h"
12 #include "printing/print_job_constants.h"
15 class DictionaryValue
;
20 class PrintDestinationInterface
;
23 // Query the printer for settings.
24 class PrinterQuery
: public PrintJobWorkerOwner
{
26 // GetSettings() UI parameter.
27 enum GetSettingsAskParam
{
32 PrinterQuery(int render_process_id
, int render_view_id
);
34 // PrintJobWorkerOwner implementation.
35 virtual void GetSettingsDone(const PrintSettings
& new_settings
,
36 PrintingContext::Result result
) OVERRIDE
;
37 virtual PrintJobWorker
* DetachWorker(PrintJobWorkerOwner
* new_owner
) OVERRIDE
;
38 virtual const PrintSettings
& settings() const OVERRIDE
;
39 virtual int cookie() const OVERRIDE
;
41 // Initializes the printing context. It is fine to call this function multiple
42 // times to reinitialize the settings. |web_contents_observer| can be queried
43 // to find the owner of the print setting dialog box. It is unused when
44 // |ask_for_user_settings| is DEFAULTS.
46 GetSettingsAskParam ask_user_for_settings
,
47 int expected_page_count
,
49 MarginType margin_type
,
50 const base::Closure
& callback
);
52 // Updates the current settings with |new_settings| dictionary values.
53 void SetSettings(scoped_ptr
<base::DictionaryValue
> new_settings
,
54 const base::Closure
& callback
);
56 // Stops the worker thread since the client is done with this object.
59 // Returns true if a GetSettings() call is pending completion.
60 bool is_callback_pending() const;
62 PrintingContext::Result
last_status() const { return last_status_
; }
64 // Returns if a worker thread is still associated to this instance.
65 bool is_valid() const;
68 virtual ~PrinterQuery();
70 // Lazy create the worker thread. There is one worker thread per print job.
71 void StartWorker(const base::Closure
& callback
);
73 // All the UI is done in a worker thread because many Win32 print functions
74 // are blocking and enters a message loop without your consent. There is one
75 // worker thread per print job.
76 scoped_ptr
<PrintJobWorker
> worker_
;
78 // Cache of the print context settings for access in the UI thread.
79 PrintSettings settings_
;
81 // Is the Print... dialog box currently shown.
82 bool is_print_dialog_box_shown_
;
84 // Cookie that make this instance unique.
87 // Results from the last GetSettingsDone() callback.
88 PrintingContext::Result last_status_
;
90 // Callback waiting to be run.
91 base::Closure callback_
;
93 DISALLOW_COPY_AND_ASSIGN(PrinterQuery
);
96 } // namespace printing
98 #endif // CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_