printed_document_win.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2011 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.
  4. #include "printing/printed_document.h"
  5. #include "base/check.h"
  6. #include "base/synchronization/lock.h"
  7. #include "printing/mojom/print.mojom.h"
  8. #include "printing/printed_page_win.h"
  9. #include "printing/printing_context.h"
  10. namespace printing {
  11. #if !defined(NDEBUG)
  12. bool PrintedDocument::IsPageInList(const PrintedPage& page) const {
  13. // Make sure the page is from our list.
  14. base::AutoLock lock(lock_);
  15. return &page == mutable_.pages_.find(page.page_number() - 1)->second.get();
  16. }
  17. #endif
  18. mojom::ResultCode PrintedDocument::RenderPrintedPage(
  19. const PrintedPage& page,
  20. PrintingContext* context) const {
  21. #if !defined(NDEBUG)
  22. DCHECK(IsPageInList(page));
  23. #endif
  24. DCHECK(context);
  25. mojom::ResultCode result = context->RenderPage(
  26. page, immutable_.settings_->page_setup_device_units());
  27. if (result != mojom::ResultCode::kSuccess)
  28. return result;
  29. // Beware of any asynchronous aborts of the print job that happened during
  30. // printing.
  31. if (context->PrintingAborted())
  32. return mojom::ResultCode::kCanceled;
  33. return mojom::ResultCode::kSuccess;
  34. }
  35. } // namespace printing