OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 |
| 5 #include "components/printing/service/public/cpp/pdf_compositor_client.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "mojo/public/cpp/system/platform_handle.h" |
| 10 |
| 11 namespace printing { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Helper callback which owns an PdfCompositorPtr until invoked. This keeps the |
| 16 // PdfCompositor pipe open just long enough to dispatch a reply, at which point |
| 17 // the reply is forwarded to the wrapped |callback|. |
| 18 void OnCompositePdf( |
| 19 printing::mojom::PdfCompositorPtr compositor, |
| 20 const printing::mojom::PdfCompositor::CompositePdfCallback& callback, |
| 21 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 22 mojo::ScopedSharedBufferHandle pdf_handle) { |
| 23 task_runner->PostTask(FROM_HERE, |
| 24 base::Bind(callback, base::Passed(&pdf_handle))); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 PdfCompositorClient::PdfCompositorClient() : compositor_(nullptr) {} |
| 30 |
| 31 PdfCompositorClient::~PdfCompositorClient() {} |
| 32 |
| 33 void PdfCompositorClient::Connect(service_manager::Connector* connector) { |
| 34 DCHECK(!compositor_.is_bound()); |
| 35 connector->BindInterface(mojom::kServiceName, &compositor_); |
| 36 } |
| 37 |
| 38 void PdfCompositorClient::Composite( |
| 39 service_manager::Connector* connector, |
| 40 base::SharedMemoryHandle handle, |
| 41 uint32_t data_size, |
| 42 const mojom::PdfCompositor::CompositePdfCallback& callback, |
| 43 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { |
| 44 DCHECK(data_size); |
| 45 |
| 46 if (!compositor_.get()) |
| 47 Connect(connector); |
| 48 |
| 49 mojo::ScopedSharedBufferHandle buffer_handle = |
| 50 mojo::WrapSharedMemoryHandle(handle, data_size, true); |
| 51 |
| 52 compositor_.get()->CompositePdf( |
| 53 std::move(buffer_handle), |
| 54 base::Bind(&OnCompositePdf, base::Passed(&compositor_), callback, |
| 55 callback_task_runner)); |
| 56 } |
| 57 |
| 58 } // namespace printing |
OLD | NEW |