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

Side by Side 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, 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 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 "services/pdf_compositor/public/cpp/pdf_compositor_client.h"
6
7 #include <vector>
8
9 #include "content/public/common/service_manager_connection.h"
10 #include "mojo/public/cpp/system/platform_handle.h"
11 #include "services/pdf_compositor/public/interfaces/constants.mojom.h"
12
13 namespace pdf_compositor {
14
15 namespace {
16
17 // Helper callback which owns an PdfCompositorPtr until invoked. This keeps the
18 // PdfCompositor pipe open just long enough to dispatch a reply, at which point
19 // the reply is forwarded to the wrapped |callback|.
20 void OnCompositePdf(
21 mojom::PdfCompositorPtr compositor,
22 const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback,
23 scoped_refptr<base::SequencedTaskRunner> task_runner,
24 mojo::ScopedSharedBufferHandle pdf_handle) {
25 task_runner->PostTask(FROM_HERE,
26 base::Bind(callback, base::Passed(&pdf_handle)));
27 }
28
29 void OnIsReadyToComposite(
30 mojom::PdfCompositorPtr compositor,
31 const pdf_compositor::mojom::PdfCompositor::IsReadyToCompositeCallback&
32 callback,
33 scoped_refptr<base::SequencedTaskRunner> task_runner,
34 bool status) {
35 task_runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&status)));
36 }
37
38 } // namespace
39
40 void PdfCompositorClient::DisconnectFromPdfCompositor() {
41 compositor_.reset();
42 }
43
44 void PdfCompositorClient::ConnectionWithPdfCompositor() {
45 DCHECK(!compositor_.is_bound());
46 if (compositor_.is_bound())
47 return;
48
49 service_manager::mojom::ConnectorRequest connector_request;
50 std::unique_ptr<service_manager::Connector> connector =
51 service_manager::Connector::Create(&connector_request);
52 content::ServiceManagerConnection::GetForProcess()
53 ->GetConnector()
54 ->BindConnectorRequest(std::move(connector_request));
55 connector->BindInterface(mojom::kServiceName, &compositor_);
56 }
57
58 void PdfCompositorClient::Composite(
59 base::SharedMemoryHandle handle,
60 uint32_t data_size,
61 const pdf_compositor::mojom::PdfCompositor::CompositePdfCallback& callback,
62 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
63 if (!compositor_.get()) {
64 ConnectionWithPdfCompositor();
65 }
66
67 mojo::ScopedSharedBufferHandle buffer_handle =
68 mojo::WrapSharedMemoryHandle(handle, data_size, true);
69
70 compositor_.get()->CompositePdf(
71 std::move(buffer_handle),
72 base::Bind(&OnCompositePdf, base::Passed(&compositor_), callback,
73 callback_task_runner));
74 }
75
76 void PdfCompositorClient::PrepareSubframe(int id, int page_num) {
77 if (!compositor_.get()) {
78 ConnectionWithPdfCompositor();
79 }
80
81 compositor_.get()->PrepareSubframe(id, page_num);
82 }
83
84 void PdfCompositorClient::IsReadyToComposite(
85 int page_num,
86 const pdf_compositor::mojom::PdfCompositor::IsReadyToCompositeCallback&
87 callback,
88 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) {
89 if (!compositor_.get()) {
90 ConnectionWithPdfCompositor();
91 }
92
93 compositor_.get()->IsReadyToComposite(
94 page_num, base::Bind(&OnIsReadyToComposite, base::Passed(&compositor_),
95 callback, callback_task_runner));
96 }
97
98 void PdfCompositorClient::AddSubFrameContent(int id,
99 base::SharedMemoryHandle handle,
100 uint32_t data_size) {
101 if (!compositor_.get()) {
102 ConnectionWithPdfCompositor();
103 }
104
105 mojo::ScopedSharedBufferHandle buffer_handle =
106 mojo::WrapSharedMemoryHandle(handle, data_size, true);
107 compositor_.get()->AddSubFrameContent(id, std::move(buffer_handle));
108 }
109
110 } // namespace pdf_compositor
OLDNEW
« 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