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

Unified Diff: services/pdf_compositor/public/cpp/pdf_compositor_client.cc

Issue 2653963002: [Experimental] Supporting OOPIF printing
Patch Set: Rename service, fix for webview, and connect to DiscardableMemoryManager Created 3 years, 9 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: services/pdf_compositor/public/cpp/pdf_compositor_client.cc
diff --git a/services/pdf_compositor/public/cpp/pdf_compositor_client.cc b/services/pdf_compositor/public/cpp/pdf_compositor_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b2e5610609148395085e406428e9b35d05994d26
--- /dev/null
+++ b/services/pdf_compositor/public/cpp/pdf_compositor_client.cc
@@ -0,0 +1,110 @@
+// 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 "services/pdf_compositor/public/cpp/pdf_compositor_client.h"
+
+#include <vector>
+
+#include "content/public/common/service_manager_connection.h"
+#include "mojo/public/cpp/system/platform_handle.h"
+#include "services/pdf_compositor/public/interfaces/constants.mojom.h"
+
+namespace pdf_compositor {
+
+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(
+ mojom::PdfCompositorPtr compositor,
+ const pdf_compositor::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)));
+}
+
+void OnIsReadyToComposite(
+ mojom::PdfCompositorPtr compositor,
+ const pdf_compositor::mojom::PdfCompositor::IsReadyToCompositeCallback&
+ callback,
+ scoped_refptr<base::SequencedTaskRunner> task_runner,
+ bool status) {
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&status)));
+}
+
+} // namespace
+
+void PdfCompositorClient::DisconnectFromPdfCompositor() {
+ compositor_.reset();
+}
+
+void PdfCompositorClient::ConnectionWithPdfCompositor() {
+ DCHECK(!compositor_.is_bound());
+ if (compositor_.is_bound())
+ return;
+
+ service_manager::mojom::ConnectorRequest connector_request;
+ std::unique_ptr<service_manager::Connector> connector =
+ service_manager::Connector::Create(&connector_request);
+ content::ServiceManagerConnection::GetForProcess()
+ ->GetConnector()
+ ->BindConnectorRequest(std::move(connector_request));
+ connector->BindInterface(mojom::kServiceName, &compositor_);
+}
+
+void PdfCompositorClient::Composite(
+ base::SharedMemoryHandle handle,
+ uint32_t data_size,
+ const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback,
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
+ if (!compositor_.get()) {
+ ConnectionWithPdfCompositor();
+ }
+
+ 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));
+}
+
+void PdfCompositorClient::PrepareSubframe(int id, int page_num) {
+ if (!compositor_.get()) {
+ ConnectionWithPdfCompositor();
+ }
+
+ compositor_.get()->PrepareSubframe(id, page_num);
+}
+
+void PdfCompositorClient::IsReadyToComposite(
+ int page_num,
+ const pdf_compositor::mojom::PdfCompositor::IsReadyToCompositeCallback&
+ callback,
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
+ if (!compositor_.get()) {
+ ConnectionWithPdfCompositor();
+ }
+
+ compositor_.get()->IsReadyToComposite(
+ page_num, base::Bind(&OnIsReadyToComposite, base::Passed(&compositor_),
+ callback, callback_task_runner));
+}
+
+void PdfCompositorClient::AddSubFrameContent(int id,
+ base::SharedMemoryHandle handle,
+ uint32_t data_size) {
+ if (!compositor_.get()) {
+ ConnectionWithPdfCompositor();
+ }
+
+ mojo::ScopedSharedBufferHandle buffer_handle =
+ mojo::WrapSharedMemoryHandle(handle, data_size, true);
+ compositor_.get()->AddSubFrameContent(id, std::move(buffer_handle));
+}
+
+} // namespace pdf_compositor
« no previous file with comments | « services/pdf_compositor/public/cpp/pdf_compositor_client.h ('k') | services/pdf_compositor/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698