| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/mojo/services/media_service.h" | 5 #include "media/mojo/services/media_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "media/base/media_log.h" | 9 #include "media/base/media_log.h" |
| 10 #include "media/mojo/services/interface_factory_impl.h" | 10 #include "media/mojo/services/interface_factory_impl.h" |
| 11 #include "media/mojo/services/mojo_media_client.h" | 11 #include "media/mojo/services/mojo_media_client.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 #include "services/service_manager/public/cpp/connection.h" | 13 #include "services/service_manager/public/cpp/connection.h" |
| 14 #include "services/service_manager/public/cpp/connector.h" | 14 #include "services/service_manager/public/cpp/connector.h" |
| 15 #include "services/service_manager/public/cpp/interface_registry.h" | 15 #include "services/service_manager/public/cpp/interface_registry.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // TODO(xhwang): Hook up MediaLog when possible. | 19 // TODO(xhwang): Hook up MediaLog when possible. |
| 20 MediaService::MediaService(std::unique_ptr<MojoMediaClient> mojo_media_client, | 20 MediaService::MediaService(std::unique_ptr<MojoMediaClient> mojo_media_client) |
| 21 const base::Closure& quit_closure) | |
| 22 : mojo_media_client_(std::move(mojo_media_client)), | 21 : mojo_media_client_(std::move(mojo_media_client)), |
| 23 media_log_(new MediaLog()), | 22 media_log_(new MediaLog()) { |
| 24 ref_factory_(quit_closure) { | |
| 25 DCHECK(mojo_media_client_); | 23 DCHECK(mojo_media_client_); |
| 26 } | 24 } |
| 27 | 25 |
| 28 MediaService::~MediaService() {} | 26 MediaService::~MediaService() {} |
| 29 | 27 |
| 30 void MediaService::OnStart(service_manager::ServiceContext* context) { | 28 void MediaService::OnStart(service_manager::ServiceContext* context) { |
| 29 ref_factory_.reset(new service_manager::ServiceContextRefFactory( |
| 30 base::Bind(&service_manager::ServiceContext::RequestQuit, |
| 31 base::Unretained(context)))); |
| 31 mojo_media_client_->Initialize(); | 32 mojo_media_client_->Initialize(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 bool MediaService::OnConnect(const service_manager::ServiceInfo& remote_info, | 35 bool MediaService::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 35 service_manager::InterfaceRegistry* registry) { | 36 service_manager::InterfaceRegistry* registry) { |
| 36 registry->AddInterface<mojom::MediaService>(this); | 37 registry->AddInterface<mojom::MediaService>(this); |
| 37 return true; | 38 return true; |
| 38 } | 39 } |
| 39 | 40 |
| 40 bool MediaService::OnStop() { | 41 bool MediaService::OnStop() { |
| 41 mojo_media_client_.reset(); | 42 mojo_media_client_.reset(); |
| 42 return true; | 43 return true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 void MediaService::Create(const service_manager::Identity& remote_identity, | 46 void MediaService::Create(const service_manager::Identity& remote_identity, |
| 46 mojom::MediaServiceRequest request) { | 47 mojom::MediaServiceRequest request) { |
| 47 bindings_.AddBinding(this, std::move(request)); | 48 bindings_.AddBinding(this, std::move(request)); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void MediaService::CreateInterfaceFactory( | 51 void MediaService::CreateInterfaceFactory( |
| 51 mojom::InterfaceFactoryRequest request, | 52 mojom::InterfaceFactoryRequest request, |
| 52 service_manager::mojom::InterfaceProviderPtr remote_interfaces) { | 53 service_manager::mojom::InterfaceProviderPtr remote_interfaces) { |
| 53 // Ignore request if service has already stopped. | 54 // Ignore request if service has already stopped. |
| 54 if (!mojo_media_client_) | 55 if (!mojo_media_client_) |
| 55 return; | 56 return; |
| 56 | 57 |
| 57 mojo::MakeStrongBinding( | 58 mojo::MakeStrongBinding( |
| 58 base::MakeUnique<InterfaceFactoryImpl>( | 59 base::MakeUnique<InterfaceFactoryImpl>( |
| 59 std::move(remote_interfaces), media_log_, ref_factory_.CreateRef(), | 60 std::move(remote_interfaces), media_log_, ref_factory_->CreateRef(), |
| 60 mojo_media_client_.get()), | 61 mojo_media_client_.get()), |
| 61 std::move(request)); | 62 std::move(request)); |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace media | 65 } // namespace media |
| OLD | NEW |