Fix race condition in gyp/ninja builds.
[chromium-blink-merge.git] / android_webview / browser / renderer_host / print_manager.h
blob7cee58778a5d2c0de7ace2b3aea8f97418170f76
1 // Copyright 2013 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 ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "content/public/browser/web_contents_observer.h"
12 class GURL;
14 namespace base {
15 struct FileDescriptor;
18 namespace printing {
19 class PrintSettings;
22 namespace android_webview {
24 class PrintManagerDelegate {
25 public:
26 virtual ~PrintManagerDelegate() { }
27 virtual void DidExportPdf(bool success) = 0;
28 virtual bool IsCancelled() = 0;
30 private:
31 // DISALLOW_COPY_AND_ASSIGN(PrintManagerDelegate);
34 // Provides RenderViewHost wrapper functionality for sending WebView-specific
35 // IPC messages to the renderer and from there to WebKit.
37 // Note for android_webview:
38 // This class manages the print (an export to PDF file essentially) task for
39 // a webview. There can be at most one active print task per webview.
40 class PrintManager : public content::WebContentsObserver,
41 public base::NonThreadSafe {
42 public:
43 // To send receive messages to a RenderView we take the WebContents instance,
44 // as it internally handles RenderViewHost instances changing underneath us.
45 PrintManager(content::WebContents* contents,
46 printing::PrintSettings* settings,
47 int fd,
48 PrintManagerDelegate* delegate);
49 virtual ~PrintManager();
51 // Prints the current document immediately. Since the rendering is
52 // asynchronous, the actual printing will not be completed on the return of
53 // this function. Returns false if printing is impossible at the moment.
55 // Note for webview: Returns false immediately if this print manager is
56 // already busy printing.
57 bool PrintNow();
59 private:
60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
61 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
62 void OnDidGetDocumentCookie(int cookie);
63 void OnPrintingFailed(int cookie);
64 void OnGetDefaultPrintSettingsReply(IPC::Message* reply_msg);
65 void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
66 void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
67 int* sequence_number);
68 void OnTempFileForPrintingWritten(int sequence_number);
70 // Print Settings.
71 printing::PrintSettings* settings_;
73 // File descriptor to export to.
74 int fd_;
75 // Print manager delegate
76 PrintManagerDelegate* delegate_;
77 // Number of pages to print in the print job.
78 int number_pages_;
79 // The document cookie of the current PrinterQuery.
80 int cookie_;
81 // Whether a print task is pending.
82 int printing_;
84 DISALLOW_COPY_AND_ASSIGN(PrintManager);
87 } // namespace android_webview
89 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_PRINT_MANAGER_H_