blob: 6652e04180b5a720eb3716a40b7890a09b122456 [file] [log] [blame]
[email protected]75b68052011-02-03 06:01:161// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]b75dca82009-10-13 18:46:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "printing/printed_document.h"
6
Alan Screen4e284e9cb2021-12-04 00:38:297#include "base/check.h"
8#include "base/synchronization/lock.h"
Alan Screenb4a2d962021-12-04 00:31:369#include "printing/mojom/print.mojom.h"
rbpotter80cbe042017-12-08 07:00:5210#include "printing/printed_page_win.h"
Alan Screen4e284e9cb2021-12-04 00:38:2911#include "printing/printing_context.h"
[email protected]b75dca82009-10-13 18:46:2112
13namespace printing {
14
Alan Screen5ff17902022-01-15 01:51:1515#if !defined(NDEBUG)
16bool PrintedDocument::IsPageInList(const PrintedPage& page) const {
17 // Make sure the page is from our list.
18 base::AutoLock lock(lock_);
19 return &page == mutable_.pages_.find(page.page_number() - 1)->second.get();
20}
21#endif
22
Alan Screenb4a2d962021-12-04 00:31:3623mojom::ResultCode PrintedDocument::RenderPrintedPage(
tfarina876d1e02016-10-11 23:12:5324 const PrintedPage& page,
Alan Screen4e284e9cb2021-12-04 00:38:2925 PrintingContext* context) const {
Alan Screen5ff17902022-01-15 01:51:1526#if !defined(NDEBUG)
27 DCHECK(IsPageInList(page));
[email protected]b75dca82009-10-13 18:46:2128#endif
29
[email protected]3b52c982010-09-27 20:40:3630 DCHECK(context);
Alan Screen46d031eb2022-01-05 23:15:2931 mojom::ResultCode result = context->RenderPage(
32 page, immutable_.settings_->page_setup_device_units());
33 if (result != mojom::ResultCode::kSuccess)
34 return result;
35
36 // Beware of any asynchronous aborts of the print job that happened during
37 // printing.
38 if (context->PrintingAborted())
39 return mojom::ResultCode::kCanceled;
40
41 return mojom::ResultCode::kSuccess;
Alan Screen13ec987ca2019-12-10 19:23:0742}
43
[email protected]b75dca82009-10-13 18:46:2144} // namespace printing