| 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 "chromecast/browser/media/cast_mojo_media_application.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "chromecast/browser/media/cast_mojo_media_client.h" | |
| 10 #include "media/base/media_log.h" | |
| 11 #include "media/mojo/services/service_factory_impl.h" | |
| 12 #include "services/shell/public/cpp/connection.h" | |
| 13 | |
| 14 namespace { | |
| 15 void CreateServiceFactory( | |
| 16 mojo::InterfaceRequest<media::interfaces::ServiceFactory> request, | |
| 17 shell::mojom::InterfaceProvider* interfaces, | |
| 18 scoped_refptr<media::MediaLog> media_log, | |
| 19 std::unique_ptr<shell::ShellConnectionRef> connection_ref, | |
| 20 media::MojoMediaClient* mojo_media_client) { | |
| 21 new ::media::ServiceFactoryImpl(std::move(request), interfaces, | |
| 22 std::move(media_log), | |
| 23 std::move(connection_ref), mojo_media_client); | |
| 24 } | |
| 25 } // namespace | |
| 26 | |
| 27 namespace chromecast { | |
| 28 namespace media { | |
| 29 | |
| 30 CastMojoMediaApplication::CastMojoMediaApplication( | |
| 31 std::unique_ptr<CastMojoMediaClient> mojo_media_client, | |
| 32 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | |
| 33 const base::Closure& quit_closure) | |
| 34 : mojo_media_client_(std::move(mojo_media_client)), | |
| 35 media_task_runner_(media_task_runner), | |
| 36 media_log_(new ::media::MediaLog()), | |
| 37 ref_factory_(quit_closure) { | |
| 38 DCHECK(mojo_media_client_); | |
| 39 DCHECK(media_task_runner_); | |
| 40 } | |
| 41 | |
| 42 CastMojoMediaApplication::~CastMojoMediaApplication() {} | |
| 43 | |
| 44 void CastMojoMediaApplication::Initialize(::shell::Connector* connector, | |
| 45 const ::shell::Identity& identity, | |
| 46 uint32_t /* id */) {} | |
| 47 | |
| 48 bool CastMojoMediaApplication::AcceptConnection( | |
| 49 ::shell::Connection* connection) { | |
| 50 connection->AddInterface<::media::interfaces::ServiceFactory>(this); | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 void CastMojoMediaApplication::Create( | |
| 55 ::shell::Connection* connection, | |
| 56 mojo::InterfaceRequest<::media::interfaces::ServiceFactory> request) { | |
| 57 // Create a connection ref here to keep the app alive until the ServiceFactory | |
| 58 // is done with it. | |
| 59 std::unique_ptr<shell::ShellConnectionRef> connection_ref = | |
| 60 ref_factory_.CreateRef(); | |
| 61 media_task_runner_->PostTask( | |
| 62 FROM_HERE, | |
| 63 base::Bind(&CreateServiceFactory, base::Passed(&request), | |
| 64 connection->GetRemoteInterfaces(), media_log_, | |
| 65 base::Passed(&connection_ref), mojo_media_client_.get())); | |
| 66 } | |
| 67 | |
| 68 } // namespace media | |
| 69 } // namespace chromecast | |
| OLD | NEW |