Avoid double-InitCache() in SimpleDoomBetween test, leak
[chromium-blink-merge.git] / printing / printing_context.h
blob60ea0bec78362af97a222a989a7d044dc20f625f
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.
5 #ifndef PRINTING_PRINTING_CONTEXT_H_
6 #define PRINTING_PRINTING_CONTEXT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/string16.h"
13 #include "printing/print_settings.h"
14 #include "ui/gfx/native_widget_types.h"
16 namespace base {
17 class DictionaryValue;
20 namespace printing {
22 // An abstraction of a printer context, implemented by objects that describe the
23 // user selected printing context. This includes the OS-dependent UI to ask the
24 // user about the print settings. Concrete implementations directly talk to the
25 // printer and manage the document and page breaks.
26 class PRINTING_EXPORT PrintingContext {
27 public:
28 // Tri-state result for user behavior-dependent functions.
29 enum Result {
30 OK,
31 CANCEL,
32 FAILED,
35 virtual ~PrintingContext();
37 // Callback of AskUserForSettings, used to notify the PrintJobWorker when
38 // print settings are available.
39 typedef base::Callback<void(Result)> PrintSettingsCallback;
41 // Asks the user what printer and format should be used to print. Updates the
42 // context with the select device settings. The result of the call is returned
43 // in the callback. This is necessary for Linux, which only has an
44 // asynchronous printing API.
45 virtual void AskUserForSettings(gfx::NativeView parent_view,
46 int max_pages,
47 bool has_selection,
48 const PrintSettingsCallback& callback) = 0;
50 // Selects the user's default printer and format. Updates the context with the
51 // default device settings.
52 virtual Result UseDefaultSettings() = 0;
54 // Updates printer related settings. |job_settings| contains all print job
55 // settings information. |ranges| has the new page range settings.
56 virtual Result UpdatePrinterSettings(
57 const base::DictionaryValue& job_settings,
58 const PageRanges& ranges) = 0;
60 // Updates Print Settings. |job_settings| contains all print job
61 // settings information. |ranges| has the new page range settings.
62 Result UpdatePrintSettings(const base::DictionaryValue& job_settings,
63 const PageRanges& ranges);
65 // Initializes with predefined settings.
66 virtual Result InitWithSettings(const PrintSettings& settings) = 0;
68 // Does platform specific setup of the printer before the printing. Signal the
69 // printer that a document is about to be spooled.
70 // Warning: This function enters a message loop. That may cause side effects
71 // like IPC message processing! Some printers have side-effects on this call
72 // like virtual printers that ask the user for the path of the saved document;
73 // for example a PDF printer.
74 virtual Result NewDocument(const string16& document_name) = 0;
76 // Starts a new page.
77 virtual Result NewPage() = 0;
79 // Closes the printed page.
80 virtual Result PageDone() = 0;
82 // Closes the printing job. After this call the object is ready to start a new
83 // document.
84 virtual Result DocumentDone() = 0;
86 // Cancels printing. Can be used in a multi-threaded context. Takes effect
87 // immediately.
88 virtual void Cancel() = 0;
90 // Releases the native printing context.
91 virtual void ReleaseContext() = 0;
93 // Returns the native context used to print.
94 virtual gfx::NativeDrawingContext context() const = 0;
96 // Creates an instance of this object. Implementers of this interface should
97 // implement this method to create an object of their implementation. The
98 // caller owns the returned object.
99 static PrintingContext* Create(const std::string& app_locale);
101 void set_margin_type(MarginType type);
103 const PrintSettings& settings() const {
104 return settings_;
107 protected:
108 explicit PrintingContext(const std::string& app_locale);
110 // Reinitializes the settings for object reuse.
111 void ResetSettings();
113 // Does bookkeeping when an error occurs.
114 PrintingContext::Result OnError();
116 // Complete print context settings.
117 PrintSettings settings_;
119 // The dialog box has been dismissed.
120 volatile bool dialog_box_dismissed_;
122 // Is a print job being done.
123 volatile bool in_print_job_;
125 // Did the user cancel the print job.
126 volatile bool abort_printing_;
128 // The application locale.
129 std::string app_locale_;
131 DISALLOW_COPY_AND_ASSIGN(PrintingContext);
134 } // namespace printing
136 #endif // PRINTING_PRINTING_CONTEXT_H_