| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/media/media_interface_provider.h" | 5 #include "content/renderer/media/media_interface_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "media/mojo/interfaces/content_decryption_module.mojom.h" | 10 #include "media/mojo/interfaces/content_decryption_module.mojom.h" |
| 11 #include "media/mojo/interfaces/renderer.mojom.h" | 11 #include "media/mojo/interfaces/renderer.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 #include "services/service_manager/public/cpp/interface_provider.h" | 13 #include "services/service_manager/public/cpp/interface_provider.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 MediaInterfaceProvider::MediaInterfaceProvider( | 17 MediaInterfaceProvider::MediaInterfaceProvider( |
| 18 service_manager::InterfaceProvider* remote_interfaces) | 18 service_manager::InterfaceProvider* remote_interfaces) |
| 19 : remote_interfaces_(remote_interfaces) {} | 19 : remote_interfaces_(remote_interfaces), weak_factory_(this) { |
| 20 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 21 weak_this_ = weak_factory_.GetWeakPtr(); |
| 22 } |
| 20 | 23 |
| 21 MediaInterfaceProvider::~MediaInterfaceProvider() { | 24 MediaInterfaceProvider::~MediaInterfaceProvider() { |
| 22 DCHECK(thread_checker_.CalledOnValidThread()); | 25 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 23 } | 26 } |
| 24 | 27 |
| 25 void MediaInterfaceProvider::GetInterface(const std::string& interface_name, | 28 void MediaInterfaceProvider::GetInterface(const std::string& interface_name, |
| 26 mojo::ScopedMessagePipeHandle pipe) { | 29 mojo::ScopedMessagePipeHandle pipe) { |
| 27 DVLOG(1) << __func__; | 30 DVLOG(1) << __func__; |
| 28 DCHECK(thread_checker_.CalledOnValidThread()); | 31 if (!task_runner_->BelongsToCurrentThread()) { |
| 32 task_runner_->PostTask( |
| 33 FROM_HERE, base::Bind(&MediaInterfaceProvider::GetInterface, weak_this_, |
| 34 interface_name, base::Passed(&pipe))); |
| 35 return; |
| 36 } |
| 37 |
| 38 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 29 | 39 |
| 30 if (interface_name == media::mojom::ContentDecryptionModule::Name_) { | 40 if (interface_name == media::mojom::ContentDecryptionModule::Name_) { |
| 31 GetMediaInterfaceFactory()->CreateCdm( | 41 GetMediaInterfaceFactory()->CreateCdm( |
| 32 mojo::MakeRequest<media::mojom::ContentDecryptionModule>( | 42 mojo::MakeRequest<media::mojom::ContentDecryptionModule>( |
| 33 std::move(pipe))); | 43 std::move(pipe))); |
| 34 } else if (interface_name == media::mojom::Renderer::Name_) { | 44 } else if (interface_name == media::mojom::Renderer::Name_) { |
| 35 GetMediaInterfaceFactory()->CreateRenderer( | 45 GetMediaInterfaceFactory()->CreateRenderer( |
| 36 std::string(), | 46 std::string(), |
| 37 mojo::MakeRequest<media::mojom::Renderer>(std::move(pipe))); | 47 mojo::MakeRequest<media::mojom::Renderer>(std::move(pipe))); |
| 38 } else if (interface_name == media::mojom::AudioDecoder::Name_) { | 48 } else if (interface_name == media::mojom::AudioDecoder::Name_) { |
| 39 GetMediaInterfaceFactory()->CreateAudioDecoder( | 49 GetMediaInterfaceFactory()->CreateAudioDecoder( |
| 40 mojo::MakeRequest<media::mojom::AudioDecoder>(std::move(pipe))); | 50 mojo::MakeRequest<media::mojom::AudioDecoder>(std::move(pipe))); |
| 41 } else if (interface_name == media::mojom::VideoDecoder::Name_) { | 51 } else if (interface_name == media::mojom::VideoDecoder::Name_) { |
| 42 GetMediaInterfaceFactory()->CreateVideoDecoder( | 52 GetMediaInterfaceFactory()->CreateVideoDecoder( |
| 43 mojo::MakeRequest<media::mojom::VideoDecoder>(std::move(pipe))); | 53 mojo::MakeRequest<media::mojom::VideoDecoder>(std::move(pipe))); |
| 44 } else { | 54 } else { |
| 45 NOTREACHED(); | 55 NOTREACHED(); |
| 46 } | 56 } |
| 47 } | 57 } |
| 48 | 58 |
| 49 media::mojom::InterfaceFactory* | 59 media::mojom::InterfaceFactory* |
| 50 MediaInterfaceProvider::GetMediaInterfaceFactory() { | 60 MediaInterfaceProvider::GetMediaInterfaceFactory() { |
| 51 DVLOG(1) << __func__; | 61 DVLOG(1) << __func__; |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 53 | 63 |
| 54 if (!media_interface_factory_) { | 64 if (!media_interface_factory_) { |
| 55 remote_interfaces_->GetInterface(&media_interface_factory_); | 65 remote_interfaces_->GetInterface(&media_interface_factory_); |
| 56 media_interface_factory_.set_connection_error_handler(base::Bind( | 66 media_interface_factory_.set_connection_error_handler(base::Bind( |
| 57 &MediaInterfaceProvider::OnConnectionError, base::Unretained(this))); | 67 &MediaInterfaceProvider::OnConnectionError, base::Unretained(this))); |
| 58 } | 68 } |
| 59 | 69 |
| 60 return media_interface_factory_.get(); | 70 return media_interface_factory_.get(); |
| 61 } | 71 } |
| 62 | 72 |
| 63 void MediaInterfaceProvider::OnConnectionError() { | 73 void MediaInterfaceProvider::OnConnectionError() { |
| 64 DVLOG(1) << __func__; | 74 DVLOG(1) << __func__; |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 66 | 76 |
| 67 media_interface_factory_.reset(); | 77 media_interface_factory_.reset(); |
| 68 } | 78 } |
| 69 | 79 |
| 70 } // namespace content | 80 } // namespace content |
| OLD | NEW |