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/pdf_compositor_service.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/lazy_instance.h" | |
10 #include "base/memory/discardable_memory.h" | |
11 #include "base/memory/ptr_util.h" | |
12 #include "components/printing/service/pdf_compositor_impl.h" | |
13 #include "components/printing/service/public/interfaces/pdf_compositor.mojom.h" | |
14 #include "content/public/common/service_names.mojom.h" | |
15 #include "content/public/utility/utility_thread.h" | |
16 #include "mojo/public/cpp/bindings/strong_binding.h" | |
17 #include "services/service_manager/public/cpp/connector.h" | |
18 #include "services/service_manager/public/cpp/service_context.h" | |
19 | |
20 namespace { | |
21 | |
22 base::LazyInstance<std::string>::Leaky g_creator; | |
dcheng
2017/05/10 07:36:48
It feels a bit awkward to hold this as a LazyInsta
Wei Li
2017/05/11 16:53:02
I have not found a better solution. This string sh
dcheng
2017/05/12 08:14:20
How about just having a static function to configu
| |
23 | |
24 void OnPdfCompositorRequest( | |
25 service_manager::ServiceContextRefFactory* ref_factory, | |
26 const service_manager::BindSourceInfo& source_info, | |
27 printing::mojom::PdfCompositorRequest request) { | |
28 mojo::MakeStrongBinding(base::MakeUnique<printing::PdfCompositorImpl>( | |
29 g_creator.Get(), ref_factory->CreateRef()), | |
30 std::move(request)); | |
31 } | |
32 } // namespace | |
33 | |
34 namespace printing { | |
35 | |
36 PdfCompositorService::PdfCompositorService() : weak_factory_(this) {} | |
37 | |
38 PdfCompositorService::~PdfCompositorService() = default; | |
39 | |
40 // static | |
41 std::unique_ptr<service_manager::Service> PdfCompositorService::Create( | |
42 const std::string& creator) { | |
43 g_creator.Get() = creator; | |
44 return base::MakeUnique<printing::PdfCompositorService>(); | |
45 } | |
46 | |
47 void PdfCompositorService::OnStart() { | |
48 // Set up discardable memory manager. | |
49 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr; | |
50 context()->connector()->BindInterface(content::mojom::kBrowserServiceName, | |
51 &manager_ptr); | |
52 discardable_shared_memory_manager_ = base::MakeUnique< | |
53 discardable_memory::ClientDiscardableSharedMemoryManager>( | |
54 std::move(manager_ptr), content::UtilityThread::Get()->GetIOTaskRunner()); | |
55 DCHECK(discardable_shared_memory_manager_); | |
56 base::DiscardableMemoryAllocator::SetInstance( | |
57 discardable_shared_memory_manager_.get()); | |
58 | |
59 ref_factory_ = base::MakeUnique<service_manager::ServiceContextRefFactory>( | |
60 base::Bind(&service_manager::ServiceContext::RequestQuit, | |
61 base::Unretained(context()))); | |
62 registry_.AddInterface( | |
63 base::Bind(&OnPdfCompositorRequest, ref_factory_.get())); | |
64 } | |
65 | |
66 void PdfCompositorService::OnBindInterface( | |
67 const service_manager::BindSourceInfo& source_info, | |
68 const std::string& interface_name, | |
69 mojo::ScopedMessagePipeHandle interface_pipe) { | |
70 registry_.BindInterface(source_info, interface_name, | |
71 std::move(interface_pipe)); | |
72 } | |
73 | |
74 } // namespace printing | |
OLD | NEW |