OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/image_decoder/image_decoder_service.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 9 #include "services/image_decoder/image_decoder_impl.h" |
| 10 #include "services/image_decoder/public/interfaces/image_decoder.mojom.h" |
| 11 #include "services/service_manager/public/cpp/interface_registry.h" |
| 12 #include "services/service_manager/public/cpp/service_context.h" |
| 13 |
| 14 namespace image_decoder { |
| 15 |
| 16 namespace { |
| 17 |
| 18 void OnConnectionLost(std::unique_ptr<service_manager::ServiceContextRef> ref) { |
| 19 // No-op. This merely takes ownership of |ref| so it can be destroyed when |
| 20 // this function is invoked. |
| 21 } |
| 22 |
| 23 void OnImageDecoderRequest( |
| 24 service_manager::ServiceContextRefFactory* ref_factory, |
| 25 mojom::ImageDecoderRequest request) { |
| 26 mojo::MakeStrongBinding( |
| 27 base::MakeUnique<ImageDecoderImpl>(ref_factory->CreateRef()), |
| 28 std::move(request)); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 ImageDecoderService::ImageDecoderService() = default; |
| 34 |
| 35 ImageDecoderService::~ImageDecoderService() = default; |
| 36 |
| 37 // static |
| 38 std::unique_ptr<service_manager::Service> ImageDecoderService::Create() { |
| 39 return base::MakeUnique<ImageDecoderService>(); |
| 40 } |
| 41 |
| 42 void ImageDecoderService::OnStart(service_manager::ServiceContext* context) { |
| 43 ref_factory_.reset(new service_manager::ServiceContextRefFactory( |
| 44 base::Bind(&service_manager::ServiceContext::RequestQuit, |
| 45 base::Unretained(context)))); |
| 46 } |
| 47 |
| 48 bool ImageDecoderService::OnConnect( |
| 49 const service_manager::ServiceInfo& remote_info, |
| 50 service_manager::InterfaceRegistry* registry) { |
| 51 // Add a reference to the service and tie it to the lifetime of the |
| 52 // InterfaceRegistry's connection. |
| 53 std::unique_ptr<service_manager::ServiceContextRef> connection_ref = |
| 54 ref_factory_->CreateRef(); |
| 55 registry->AddConnectionLostClosure( |
| 56 base::Bind(&OnConnectionLost, base::Passed(&connection_ref))); |
| 57 registry->AddInterface( |
| 58 base::Bind(&OnImageDecoderRequest, ref_factory_.get())); |
| 59 return true; |
| 60 } |
| 61 |
| 62 bool ImageDecoderService::OnStop() { |
| 63 return true; |
| 64 } |
| 65 |
| 66 } // namespace image_decoder |
OLD | NEW |