Chromium Code Reviews| Index: components/printing/service/public/cpp/pdf_compositor_client.cc |
| diff --git a/components/printing/service/public/cpp/pdf_compositor_client.cc b/components/printing/service/public/cpp/pdf_compositor_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e288cea90a263ebe71a4b8e5de6ff118f1a38849 |
| --- /dev/null |
| +++ b/components/printing/service/public/cpp/pdf_compositor_client.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/printing/service/public/cpp/pdf_compositor_client.h" |
| + |
| +#include <utility> |
| + |
| +#include "mojo/public/cpp/system/platform_handle.h" |
| + |
| +namespace printing { |
| + |
| +namespace { |
| + |
| +// Helper callback which owns an PdfCompositorPtr until invoked. This keeps the |
| +// PdfCompositor pipe open just long enough to dispatch a reply, at which point |
| +// the reply is forwarded to the wrapped |callback|. |
| +void OnCompositePdf( |
| + printing::mojom::PdfCompositorPtr compositor, |
| + const printing::mojom::PdfCompositor::CompositePdfCallback& callback, |
| + scoped_refptr<base::SequencedTaskRunner> task_runner, |
| + mojo::ScopedSharedBufferHandle pdf_handle) { |
| + task_runner->PostTask(FROM_HERE, |
| + base::Bind(callback, base::Passed(&pdf_handle))); |
| +} |
| + |
| +} // namespace |
| + |
| +PdfCompositorClient::PdfCompositorClient() : compositor_(nullptr) {} |
| + |
| +PdfCompositorClient::~PdfCompositorClient() {} |
| + |
| +void PdfCompositorClient::Connect(service_manager::Connector* connector) { |
| + DCHECK(!compositor_.is_bound()); |
| + connector->BindInterface(mojom::kServiceName, &compositor_); |
| +} |
| + |
| +void PdfCompositorClient::Composite( |
| + service_manager::Connector* connector, |
| + base::SharedMemoryHandle handle, |
| + uint32_t data_size, |
|
dcheng
2017/05/10 07:36:48
Any particular reason for uint32_t instead of size
Wei Li
2017/05/11 16:53:02
Done.
|
| + const mojom::PdfCompositor::CompositePdfCallback& callback, |
| + scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { |
| + DCHECK(data_size); |
| + |
| + if (!compositor_.get()) |
|
dcheng
2017/05/10 07:36:48
Nit: no .get()
Wei Li
2017/05/11 16:53:02
Done.
|
| + Connect(connector); |
| + |
| + mojo::ScopedSharedBufferHandle buffer_handle = |
| + mojo::WrapSharedMemoryHandle(handle, data_size, true); |
| + |
| + compositor_.get()->CompositePdf( |
| + std::move(buffer_handle), |
| + base::Bind(&OnCompositePdf, base::Passed(&compositor_), callback, |
| + callback_task_runner)); |
|
dcheng
2017/05/10 07:36:48
Optional: perhaps use base::Passed() with callback
Wei Li
2017/05/11 16:53:02
Done.
|
| +} |
| + |
| +} // namespace printing |