Make RuleBasedHostResolverProc methods to add/remove rules threadsafe.
[chromium-blink-merge.git] / printing / printing_context.h
blob3d260efe4b08b967cc7d94ab15f4a961c6c72be8
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/strings/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 // Printing context delegate.
29 class Delegate {
30 public:
31 Delegate() {};
32 virtual ~Delegate() {};
34 // Returns parent view to use for modal dialogs.
35 virtual gfx::NativeView GetParentView() = 0;
37 // Returns application locale.
38 virtual std::string GetAppLocale() = 0;
41 // Tri-state result for user behavior-dependent functions.
42 enum Result {
43 OK,
44 CANCEL,
45 FAILED,
48 virtual ~PrintingContext();
50 // Callback of AskUserForSettings, used to notify the PrintJobWorker when
51 // print settings are available.
52 typedef base::Callback<void(Result)> PrintSettingsCallback;
54 // Asks the user what printer and format should be used to print. Updates the
55 // context with the select device settings. The result of the call is returned
56 // in the callback. This is necessary for Linux, which only has an
57 // asynchronous printing API.
58 // On Android, when |is_scripted| is true, calling it initiates a full
59 // printing flow from the framework's PrintManager.
60 // (see https://codereview.chromium.org/740983002/)
61 virtual void AskUserForSettings(int max_pages,
62 bool has_selection,
63 bool is_scripted,
64 const PrintSettingsCallback& callback) = 0;
66 // Selects the user's default printer and format. Updates the context with the
67 // default device settings.
68 virtual Result UseDefaultSettings() = 0;
70 // Updates the context with PDF printer settings.
71 Result UsePdfSettings();
73 // Returns paper size to be used for PDF or Cloud Print in device units.
74 virtual gfx::Size GetPdfPaperSizeDeviceUnits() = 0;
76 // Updates printer settings.
77 // |external_preview| is true if pdf is going to be opened in external
78 // preview. Used by MacOS only now to open Preview.app.
79 virtual Result UpdatePrinterSettings(bool external_preview,
80 bool show_system_dialog,
81 int page_count) = 0;
83 // Updates Print Settings. |job_settings| contains all print job
84 // settings information. |ranges| has the new page range settings.
85 Result UpdatePrintSettings(const base::DictionaryValue& job_settings);
87 // Initializes with predefined settings.
88 virtual Result InitWithSettings(const PrintSettings& settings) = 0;
90 // Does platform specific setup of the printer before the printing. Signal the
91 // printer that a document is about to be spooled.
92 // Warning: This function enters a message loop. That may cause side effects
93 // like IPC message processing! Some printers have side-effects on this call
94 // like virtual printers that ask the user for the path of the saved document;
95 // for example a PDF printer.
96 virtual Result NewDocument(const base::string16& document_name) = 0;
98 // Starts a new page.
99 virtual Result NewPage() = 0;
101 // Closes the printed page.
102 virtual Result PageDone() = 0;
104 // Closes the printing job. After this call the object is ready to start a new
105 // document.
106 virtual Result DocumentDone() = 0;
108 // Cancels printing. Can be used in a multi-threaded context. Takes effect
109 // immediately.
110 virtual void Cancel() = 0;
112 // Releases the native printing context.
113 virtual void ReleaseContext() = 0;
115 // Returns the native context used to print.
116 virtual gfx::NativeDrawingContext context() const = 0;
118 // Creates an instance of this object. Implementers of this interface should
119 // implement this method to create an object of their implementation.
120 static scoped_ptr<PrintingContext> Create(Delegate* delegate);
122 void set_margin_type(MarginType type);
124 const PrintSettings& settings() const {
125 return settings_;
128 protected:
129 explicit PrintingContext(Delegate* delegate);
131 // Reinitializes the settings for object reuse.
132 void ResetSettings();
134 // Does bookkeeping when an error occurs.
135 PrintingContext::Result OnError();
137 // Complete print context settings.
138 PrintSettings settings_;
140 // Printing context delegate.
141 Delegate* delegate_;
143 // Is a print job being done.
144 volatile bool in_print_job_;
146 // Did the user cancel the print job.
147 volatile bool abort_printing_;
149 private:
150 DISALLOW_COPY_AND_ASSIGN(PrintingContext);
153 } // namespace printing
155 #endif // PRINTING_PRINTING_CONTEXT_H_