OLD | NEW |
---|---|
(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/service/public/cpp/pdf_compositor_client.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "mojo/public/cpp/system/platform_handle.h" | |
10 | |
11 namespace printing { | |
12 | |
13 namespace { | |
14 | |
15 // Helper callback which owns an PdfCompositorPtr until invoked. This keeps the | |
16 // PdfCompositor pipe open just long enough to dispatch a reply, at which point | |
17 // the reply is forwarded to the wrapped |callback|. | |
18 void OnCompositePdf( | |
19 printing::mojom::PdfCompositorPtr compositor, | |
20 const printing::mojom::PdfCompositor::CompositePdfCallback& callback, | |
21 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
22 mojo::ScopedSharedBufferHandle pdf_handle) { | |
23 task_runner->PostTask(FROM_HERE, | |
24 base::Bind(callback, base::Passed(&pdf_handle))); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 PdfCompositorClient::PdfCompositorClient() : compositor_(nullptr) {} | |
30 | |
31 PdfCompositorClient::~PdfCompositorClient() {} | |
32 | |
33 void PdfCompositorClient::Connect(service_manager::Connector* connector) { | |
34 DCHECK(!compositor_.is_bound()); | |
35 connector->BindInterface(mojom::kServiceName, &compositor_); | |
36 } | |
37 | |
38 void PdfCompositorClient::Composite( | |
39 service_manager::Connector* connector, | |
40 base::SharedMemoryHandle handle, | |
41 uint32_t data_size, | |
dcheng
2017/05/10 07:36:48
Any particular reason for uint32_t instead of size
Wei Li
2017/05/11 16:53:02
Done.
| |
42 const mojom::PdfCompositor::CompositePdfCallback& callback, | |
43 scoped_refptr<base::SequencedTaskRunner> callback_task_runner) { | |
44 DCHECK(data_size); | |
45 | |
46 if (!compositor_.get()) | |
dcheng
2017/05/10 07:36:48
Nit: no .get()
Wei Li
2017/05/11 16:53:02
Done.
| |
47 Connect(connector); | |
48 | |
49 mojo::ScopedSharedBufferHandle buffer_handle = | |
50 mojo::WrapSharedMemoryHandle(handle, data_size, true); | |
51 | |
52 compositor_.get()->CompositePdf( | |
53 std::move(buffer_handle), | |
54 base::Bind(&OnCompositePdf, base::Passed(&compositor_), callback, | |
55 callback_task_runner)); | |
dcheng
2017/05/10 07:36:48
Optional: perhaps use base::Passed() with callback
Wei Li
2017/05/11 16:53:02
Done.
| |
56 } | |
57 | |
58 } // namespace printing | |
OLD | NEW |