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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
11 #include "media/mojo/services/interface_factory_impl.h" | 11 #include "media/mojo/services/interface_factory_impl.h" |
12 #include "media/mojo/services/mojo_media_client.h" | 12 #include "media/mojo/services/mojo_media_client.h" |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 #include "services/service_manager/public/cpp/connection.h" | 14 #include "services/service_manager/public/cpp/connection.h" |
15 #include "services/service_manager/public/cpp/connector.h" | 15 #include "services/service_manager/public/cpp/connector.h" |
16 #include "services/service_manager/public/cpp/interface_registry.h" | |
17 | 16 |
18 namespace media { | 17 namespace media { |
19 | 18 |
20 // TODO(xhwang): Hook up MediaLog when possible. | 19 // TODO(xhwang): Hook up MediaLog when possible. |
21 MediaService::MediaService(std::unique_ptr<MojoMediaClient> mojo_media_client) | 20 MediaService::MediaService(std::unique_ptr<MojoMediaClient> mojo_media_client) |
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 DCHECK(mojo_media_client_); | 23 DCHECK(mojo_media_client_); |
| 24 registry_.AddInterface<mojom::MediaService>(this); |
25 } | 25 } |
26 | 26 |
27 MediaService::~MediaService() {} | 27 MediaService::~MediaService() {} |
28 | 28 |
29 void MediaService::OnStart() { | 29 void MediaService::OnStart() { |
30 ref_factory_.reset(new service_manager::ServiceContextRefFactory( | 30 ref_factory_.reset(new service_manager::ServiceContextRefFactory( |
31 base::Bind(&service_manager::ServiceContext::RequestQuit, | 31 base::Bind(&service_manager::ServiceContext::RequestQuit, |
32 base::Unretained(context())))); | 32 base::Unretained(context())))); |
33 mojo_media_client_->Initialize(context()->connector()); | 33 mojo_media_client_->Initialize(context()->connector()); |
34 } | 34 } |
35 | 35 |
36 bool MediaService::OnConnect(const service_manager::ServiceInfo& remote_info, | 36 void MediaService::OnBindInterface( |
37 service_manager::InterfaceRegistry* registry) { | 37 const service_manager::ServiceInfo& source_info, |
38 registry->AddInterface<mojom::MediaService>(this); | 38 const std::string& interface_name, |
39 return true; | 39 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 40 registry_.BindInterface(source_info.identity, interface_name, |
| 41 std::move(interface_pipe)); |
40 } | 42 } |
41 | 43 |
42 bool MediaService::OnServiceManagerConnectionLost() { | 44 bool MediaService::OnServiceManagerConnectionLost() { |
43 mojo_media_client_.reset(); | 45 mojo_media_client_.reset(); |
44 return true; | 46 return true; |
45 } | 47 } |
46 | 48 |
47 void MediaService::Create(const service_manager::Identity& remote_identity, | 49 void MediaService::Create(const service_manager::Identity& remote_identity, |
48 mojom::MediaServiceRequest request) { | 50 mojom::MediaServiceRequest request) { |
49 bindings_.AddBinding(this, std::move(request)); | 51 bindings_.AddBinding(this, std::move(request)); |
50 } | 52 } |
51 | 53 |
52 void MediaService::CreateInterfaceFactory( | 54 void MediaService::CreateInterfaceFactory( |
53 mojom::InterfaceFactoryRequest request, | 55 mojom::InterfaceFactoryRequest request, |
54 service_manager::mojom::InterfaceProviderPtr host_interfaces) { | 56 service_manager::mojom::InterfaceProviderPtr host_interfaces) { |
55 // Ignore request if service has already stopped. | 57 // Ignore request if service has already stopped. |
56 if (!mojo_media_client_) | 58 if (!mojo_media_client_) |
57 return; | 59 return; |
58 | 60 |
59 mojo::MakeStrongBinding( | 61 mojo::MakeStrongBinding( |
60 base::MakeUnique<InterfaceFactoryImpl>( | 62 base::MakeUnique<InterfaceFactoryImpl>( |
61 std::move(host_interfaces), media_log_, ref_factory_->CreateRef(), | 63 std::move(host_interfaces), media_log_, ref_factory_->CreateRef(), |
62 mojo_media_client_.get()), | 64 mojo_media_client_.get()), |
63 std::move(request)); | 65 std::move(request)); |
64 } | 66 } |
65 | 67 |
66 } // namespace media | 68 } // namespace media |
OLD | NEW |