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

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, 4 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 (c) 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 : weak_factory_(this) {}
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 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38
39 if (!data_size)
40 return;
41
42 // if (connector_request_.is_pending())
43 if (!connector_)
44 CreateConnectorRequest();
45 Composite(connector_.get(), handle, data_size, std::move(callback),
46 callback_task_runner);
47 }
48
49 std::unique_ptr<base::SharedMemory> PrintCompositeClient::GetShmFromMojoHandle(
50 mojo::ScopedSharedBufferHandle handle) {
51 if (!handle.is_valid()) {
52 DLOG(ERROR) << "Invalid mojo handle.";
53 return nullptr;
54 }
55
56 base::SharedMemoryHandle memory_handle;
57 size_t memory_size = 0;
58 bool read_only_flag = false;
59
60 const MojoResult result = mojo::UnwrapSharedMemoryHandle(
61 std::move(handle), &memory_handle, &memory_size, &read_only_flag);
62 DCHECK_EQ(MOJO_RESULT_OK, result);
63 DCHECK_GT(memory_size, 0u);
64
65 std::unique_ptr<base::SharedMemory> shm(
66 new base::SharedMemory(memory_handle, true /* read_only */));
67 if (!shm->Map(memory_size)) {
68 DLOG(ERROR) << "Map shared memory failed.";
69 return nullptr;
70 }
71 return shm;
72 }
73
74 scoped_refptr<base::RefCountedBytes>
75 PrintCompositeClient::GetDataFromMojoHandle(
76 mojo::ScopedSharedBufferHandle handle) {
77 std::unique_ptr<base::SharedMemory> shm =
78 GetShmFromMojoHandle(std::move(handle));
79 if (!shm)
80 return nullptr;
81
82 return scoped_refptr<base::RefCountedBytes>(new base::RefCountedBytes(
83 reinterpret_cast<const unsigned char*>(shm->memory()),
84 shm->mapped_size()));
85 }
86
87 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698