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

Unified Diff: components/printing/browser/print_composite_client.cc

Issue 2920013002: Use pdf compositor service for printing when OOPIF is enabled
Patch Set: rebase Created 3 years, 3 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/browser/print_composite_client.cc
diff --git a/components/printing/browser/print_composite_client.cc b/components/printing/browser/print_composite_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5516ccc35d479784ab06a4680a82b7322642026f
--- /dev/null
+++ b/components/printing/browser/print_composite_client.cc
@@ -0,0 +1,83 @@
+// 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/browser/print_composite_client.h"
+
+#include <memory>
+#include <utility>
+
+#include "base/threading/thread_task_runner_handle.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/service_manager_connection.h"
+#include "mojo/public/cpp/system/platform_handle.h"
+#include "services/service_manager/public/cpp/connector.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintCompositeClient);
+
+namespace printing {
+
+PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents) {
+}
+
+PrintCompositeClient::~PrintCompositeClient() {}
+
+void PrintCompositeClient::CreateConnectorRequest() {
+ connector_ = service_manager::Connector::Create(&connector_request_);
+ content::ServiceManagerConnection::GetForProcess()
+ ->GetConnector()
+ ->BindConnectorRequest(std::move(connector_request_));
+}
+
+void PrintCompositeClient::DoComposite(
+ base::SharedMemoryHandle handle,
+ uint32_t data_size,
+ mojom::PdfCompositor::CompositePdfCallback callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK(data_size);
+
+ if (!connector_)
+ CreateConnectorRequest();
+ Composite(connector_.get(), handle, data_size, std::move(callback),
+ base::ThreadTaskRunnerHandle::Get());
+}
+
+std::unique_ptr<base::SharedMemory> PrintCompositeClient::GetShmFromMojoHandle(
+ mojo::ScopedSharedBufferHandle handle) {
+ if (!handle.is_valid()) {
+ DLOG(ERROR) << "Invalid mojo handle.";
+ return nullptr;
+ }
+
+ base::SharedMemoryHandle memory_handle;
+ size_t memory_size = 0;
+ bool read_only_flag = false;
+
+ const MojoResult result = mojo::UnwrapSharedMemoryHandle(
+ std::move(handle), &memory_handle, &memory_size, &read_only_flag);
+ DCHECK_EQ(MOJO_RESULT_OK, result);
+ DCHECK_GT(memory_size, 0u);
+
+ std::unique_ptr<base::SharedMemory> shm =
+ base::MakeUnique<base::SharedMemory>(memory_handle, true /* read_only */);
+ if (!shm->Map(memory_size)) {
+ DLOG(ERROR) << "Map shared memory failed.";
+ return nullptr;
+ }
+ return shm;
+}
+
+scoped_refptr<base::RefCountedBytes>
+PrintCompositeClient::GetDataFromMojoHandle(
+ mojo::ScopedSharedBufferHandle handle) {
+ std::unique_ptr<base::SharedMemory> shm =
+ GetShmFromMojoHandle(std::move(handle));
+ if (!shm)
+ return nullptr;
+
+ return base::MakeRefCounted<base::RefCountedBytes>(
+ reinterpret_cast<const unsigned char*>(shm->memory()),
+ shm->mapped_size());
+}
+
+} // namespace printing
« no previous file with comments | « components/printing/browser/print_composite_client.h ('k') | components/printing/browser/print_manager_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698