[email protected] | 75b6805 | 2011-02-03 06:01:16 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | b75dca8 | 2009-10-13 18:46:21 | [diff] [blame] | 2 | // 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 Screen | 4e284e9cb | 2021-12-04 00:38:29 | [diff] [blame] | 7 | #include "base/check.h" |
8 | #include "base/synchronization/lock.h" | ||||
Alan Screen | b4a2d96 | 2021-12-04 00:31:36 | [diff] [blame] | 9 | #include "printing/mojom/print.mojom.h" |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 10 | #include "printing/printed_page_win.h" |
Alan Screen | 4e284e9cb | 2021-12-04 00:38:29 | [diff] [blame] | 11 | #include "printing/printing_context.h" |
[email protected] | b75dca8 | 2009-10-13 18:46:21 | [diff] [blame] | 12 | |
13 | namespace printing { | ||||
14 | |||||
Alan Screen | 5ff1790 | 2022-01-15 01:51:15 | [diff] [blame] | 15 | #if !defined(NDEBUG) |
16 | bool 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 Screen | b4a2d96 | 2021-12-04 00:31:36 | [diff] [blame] | 23 | mojom::ResultCode PrintedDocument::RenderPrintedPage( |
tfarina | 876d1e0 | 2016-10-11 23:12:53 | [diff] [blame] | 24 | const PrintedPage& page, |
Alan Screen | 4e284e9cb | 2021-12-04 00:38:29 | [diff] [blame] | 25 | PrintingContext* context) const { |
Alan Screen | 5ff1790 | 2022-01-15 01:51:15 | [diff] [blame] | 26 | #if !defined(NDEBUG) |
27 | DCHECK(IsPageInList(page)); | ||||
[email protected] | b75dca8 | 2009-10-13 18:46:21 | [diff] [blame] | 28 | #endif |
29 | |||||
[email protected] | 3b52c98 | 2010-09-27 20:40:36 | [diff] [blame] | 30 | DCHECK(context); |
Alan Screen | 46d031eb | 2022-01-05 23:15:29 | [diff] [blame] | 31 | 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 Screen | 13ec987ca | 2019-12-10 19:23:07 | [diff] [blame] | 42 | } |
43 | |||||
[email protected] | b75dca8 | 2009-10-13 18:46:21 | [diff] [blame] | 44 | } // namespace printing |