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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(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/browser/print_composite_client.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/threading/thread_task_runner_handle.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/service_manager_connection.h"
13 #include "mojo/public/cpp/system/platform_handle.h"
14 #include "services/service_manager/public/cpp/connector.h"
15
16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintCompositeClient);
17
18 namespace printing {
19
20 PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents) {
21 }
22
23 PrintCompositeClient::~PrintCompositeClient() {}
24
25 void PrintCompositeClient::CreateConnectorRequest() {
26 connector_ = service_manager::Connector::Create(&connector_request_);
27 content::ServiceManagerConnection::GetForProcess()
28 ->GetConnector()
29 ->BindConnectorRequest(std::move(connector_request_));
30 }
31
32 void PrintCompositeClient::DoComposite(
33 base::SharedMemoryHandle handle,
34 uint32_t data_size,
35 mojom::PdfCompositor::CompositePdfCallback callback) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37 DCHECK(data_size);
38
39 if (!connector_)
40 CreateConnectorRequest();
41 Composite(connector_.get(), handle, data_size, std::move(callback),
42 base::ThreadTaskRunnerHandle::Get());
43 }
44
45 std::unique_ptr<base::SharedMemory> PrintCompositeClient::GetShmFromMojoHandle(
46 mojo::ScopedSharedBufferHandle handle) {
47 if (!handle.is_valid()) {
48 DLOG(ERROR) << "Invalid mojo handle.";
49 return nullptr;
50 }
51
52 base::SharedMemoryHandle memory_handle;
53 size_t memory_size = 0;
54 bool read_only_flag = false;
55
56 const MojoResult result = mojo::UnwrapSharedMemoryHandle(
57 std::move(handle), &memory_handle, &memory_size, &read_only_flag);
58 DCHECK_EQ(MOJO_RESULT_OK, result);
59 DCHECK_GT(memory_size, 0u);
60
61 std::unique_ptr<base::SharedMemory> shm =
62 base::MakeUnique<base::SharedMemory>(memory_handle, true /* read_only */);
63 if (!shm->Map(memory_size)) {
64 DLOG(ERROR) << "Map shared memory failed.";
65 return nullptr;
66 }
67 return shm;
68 }
69
70 scoped_refptr<base::RefCountedBytes>
71 PrintCompositeClient::GetDataFromMojoHandle(
72 mojo::ScopedSharedBufferHandle handle) {
73 std::unique_ptr<base::SharedMemory> shm =
74 GetShmFromMojoHandle(std::move(handle));
75 if (!shm)
76 return nullptr;
77
78 return base::MakeRefCounted<base::RefCountedBytes>(
79 reinterpret_cast<const unsigned char*>(shm->memory()),
80 shm->mapped_size());
81 }
82
83 } // namespace printing
OLDNEW
« 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