Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / printing / browser / print_manager.cc
blob7e80befe31026685d6ebc04c778553ce68c1e33d
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"
9 namespace printing {
11 PrintManager::PrintManager(content::WebContents* contents)
12 : content::WebContentsObserver(contents),
13 number_pages_(0),
14 cookie_(0) {
17 PrintManager::~PrintManager() {
20 bool PrintManager::OnMessageReceived(const IPC::Message& message) {
21 bool handled = true;
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)
29 IPC_END_MESSAGE_MAP()
30 return handled;
33 void PrintManager::OnDidGetPrintedPagesCount(int cookie,
34 int number_pages) {
35 DCHECK_GT(cookie, 0);
36 DCHECK_GT(number_pages, 0);
37 number_pages_ = number_pages;
40 void PrintManager::OnDidGetDocumentCookie(int cookie) {
41 cookie_ = cookie;
44 void PrintManager::OnPrintingFailed(int cookie) {
45 if (cookie != cookie_) {
46 NOTREACHED();
47 return;
49 #if defined(OS_ANDROID)
50 PdfWritingDone(false);
51 #endif
54 void PrintManager::RenderProcessGone(base::TerminationStatus status) {
55 #if defined(OS_ANDROID)
56 PdfWritingDone(false);
57 #endif
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);
67 #endif
69 } // namespace printing