Chromium Code Reviews| Index: components/printing/service/pdf_compositor_service.cc |
| diff --git a/components/printing/service/pdf_compositor_service.cc b/components/printing/service/pdf_compositor_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..117074f524c5bcfb7b5a708ccd1c178684d67a1a |
| --- /dev/null |
| +++ b/components/printing/service/pdf_compositor_service.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/printing/service/pdf_compositor_service.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/discardable_memory.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "components/printing/service/pdf_compositor_impl.h" |
| +#include "components/printing/service/public/interfaces/pdf_compositor.mojom.h" |
| +#include "content/public/common/service_names.mojom.h" |
| +#include "content/public/utility/utility_thread.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| +#include "services/service_manager/public/cpp/service_context.h" |
| + |
| +namespace { |
| + |
| +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
|
| + |
| +void OnPdfCompositorRequest( |
| + service_manager::ServiceContextRefFactory* ref_factory, |
| + const service_manager::BindSourceInfo& source_info, |
| + printing::mojom::PdfCompositorRequest request) { |
| + mojo::MakeStrongBinding(base::MakeUnique<printing::PdfCompositorImpl>( |
| + g_creator.Get(), ref_factory->CreateRef()), |
| + std::move(request)); |
| +} |
| +} // namespace |
| + |
| +namespace printing { |
| + |
| +PdfCompositorService::PdfCompositorService() : weak_factory_(this) {} |
| + |
| +PdfCompositorService::~PdfCompositorService() = default; |
| + |
| +// static |
| +std::unique_ptr<service_manager::Service> PdfCompositorService::Create( |
| + const std::string& creator) { |
| + g_creator.Get() = creator; |
| + return base::MakeUnique<printing::PdfCompositorService>(); |
| +} |
| + |
| +void PdfCompositorService::OnStart() { |
| + // Set up discardable memory manager. |
| + discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager_ptr; |
| + context()->connector()->BindInterface(content::mojom::kBrowserServiceName, |
| + &manager_ptr); |
| + discardable_shared_memory_manager_ = base::MakeUnique< |
| + discardable_memory::ClientDiscardableSharedMemoryManager>( |
| + std::move(manager_ptr), content::UtilityThread::Get()->GetIOTaskRunner()); |
| + DCHECK(discardable_shared_memory_manager_); |
| + base::DiscardableMemoryAllocator::SetInstance( |
| + discardable_shared_memory_manager_.get()); |
| + |
| + ref_factory_ = base::MakeUnique<service_manager::ServiceContextRefFactory>( |
| + base::Bind(&service_manager::ServiceContext::RequestQuit, |
| + base::Unretained(context()))); |
| + registry_.AddInterface( |
| + base::Bind(&OnPdfCompositorRequest, ref_factory_.get())); |
| +} |
| + |
| +void PdfCompositorService::OnBindInterface( |
| + const service_manager::BindSourceInfo& source_info, |
| + const std::string& interface_name, |
| + mojo::ScopedMessagePipeHandle interface_pipe) { |
| + registry_.BindInterface(source_info, interface_name, |
| + std::move(interface_pipe)); |
| +} |
| + |
| +} // namespace printing |