Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: components/printing/service/public/cpp/pdf_compositor_client.cc

Issue 2832633002: Add PDF compositor service (Closed)
Patch Set: remove headers Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1c490807927078a6b5582a0fe582de01c9264657
--- /dev/null
+++ b/components/printing/service/public/cpp/pdf_compositor_client.cc
@@ -0,0 +1,59 @@
+// 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,
+ const mojom::PdfCompositor::CompositePdfCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
+ if (!data_size)
+ return;
Lei Zhang 2017/04/22 00:12:26 Do we need to run |callback| here?
Wei Li 2017/04/27 05:34:16 Changed.
+
+ if (!compositor_.get())
+ 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));
+}
+
+} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698