1 // Copyright 2015 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 #include "components/printing/browser/print_manager.h"
7 #include "components/printing/common/print_messages.h"
11 PrintManager::PrintManager(content::WebContents
* contents
)
12 : content::WebContentsObserver(contents
),
17 PrintManager::~PrintManager() {
20 bool PrintManager::OnMessageReceived(const IPC::Message
& message
) {
22 IPC_BEGIN_MESSAGE_MAP(PrintManager
, message
)
23 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount
,
24 OnDidGetPrintedPagesCount
)
25 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie
,
26 OnDidGetDocumentCookie
)
27 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed
, OnPrintingFailed
)
28 IPC_MESSAGE_UNHANDLED(handled
= false)
33 void PrintManager::OnDidGetPrintedPagesCount(int cookie
,
36 DCHECK_GT(number_pages
, 0);
37 number_pages_
= number_pages
;
40 void PrintManager::OnDidGetDocumentCookie(int cookie
) {
44 void PrintManager::OnPrintingFailed(int cookie
) {
45 if (cookie
!= cookie_
) {
49 #if defined(OS_ANDROID)
50 PdfWritingDone(false);
54 void PrintManager::RenderProcessGone(base::TerminationStatus status
) {
55 #if defined(OS_ANDROID)
56 PdfWritingDone(false);
60 #if defined(OS_ANDROID)
61 void PrintManager::PdfWritingDone(bool result
) {
62 if (!pdf_writing_done_callback_
.is_null())
63 pdf_writing_done_callback_
.Run(file_descriptor().fd
, result
);
64 // Invalidate the file descriptor so it doesn't get reused.
65 file_descriptor_
= base::FileDescriptor(-1, false);
69 } // namespace printing