Chromium Code Reviews| Index: media/remoting/remoting_cdm_factory.cc |
| diff --git a/media/remoting/remoting_cdm_factory.cc b/media/remoting/remoting_cdm_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..796634dc2a263a0a053d2f0f45fd5a3fc30f4eda |
| --- /dev/null |
| +++ b/media/remoting/remoting_cdm_factory.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/remoting/remoting_cdm_factory.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "media/base/cdm_config.h" |
| +#include "media/remoting/remoting_cdm.h" |
| + |
| +namespace media { |
| + |
| +RemotingCdmFactory::RemotingCdmFactory( |
| + std::unique_ptr<CdmFactory> default_cdm_factory, |
| + mojom::RemoterFactory* remoter_factory, |
| + RemotingSinkObserver* sink_observer) |
| + : default_cdm_factory_(std::move(default_cdm_factory)), |
| + remoter_factory_(remoter_factory), |
| + sink_observer_(sink_observer), |
| + weak_factory_(this) { |
| + DCHECK(default_cdm_factory_); |
| + DCHECK(remoter_factory_); |
| + DCHECK(sink_observer_); |
| +} |
| + |
| +RemotingCdmFactory::~RemotingCdmFactory() {} |
| + |
| +std::unique_ptr<RemotingCdmController> |
| +RemotingCdmFactory::CreateRemotingCdmController() { |
| + mojom::RemotingSourcePtr remoting_source; |
| + mojom::RemotingSourceRequest remoting_source_request = |
| + mojo::GetProxy(&remoting_source); |
| + mojom::RemoterPtr remoter; |
| + remoter_factory_->Create(std::move(remoting_source), |
| + mojo::GetProxy(&remoter)); |
| + scoped_refptr<RemotingSourceImpl> remoting_source_impl = |
| + new RemotingSourceImpl(std::move(remoting_source_request), |
| + std::move(remoter)); |
| + // Initialize the sink availability according to |sink_observer_|. |
|
miu
2016/11/05 04:05:15
Please add to this comment: Explain that we are pu
xjz
2016/11/07 19:03:55
Done.
|
| + if (sink_observer_->is_sink_available()) |
| + remoting_source_impl->OnSinkAvailable(); |
| + return base::MakeUnique<RemotingCdmController>(remoting_source_impl); |
| +} |
| + |
| +// TODO(xjz): Replace the callbacks with an interface. http://crbug.com/657940. |
| +void RemotingCdmFactory::Create( |
| + const std::string& key_system, |
| + const GURL& security_origin, |
| + const CdmConfig& cdm_config, |
| + const SessionMessageCB& session_message_cb, |
| + const SessionClosedCB& session_closed_cb, |
| + const SessionKeysChangeCB& session_keys_change_cb, |
| + const SessionExpirationUpdateCB& session_expiration_update_cb, |
| + const CdmCreatedCB& cdm_created_cb) { |
| + std::unique_ptr<RemotingCdmController> remoting_cdm_controller = |
| + CreateRemotingCdmController(); |
| + // Get the raw pointer of |remoting_cdm_controller| as it will be invalidated |
| + // before calling |ShouldCreateRemotingCdm()| by base::Passed(). |
| + RemotingCdmController* remoting_cdm_controller_ptr = |
| + remoting_cdm_controller.get(); |
| + remoting_cdm_controller_ptr->ShouldCreateRemotingCdm(base::Bind( |
|
xhwang
2016/11/05 02:39:58
Can we check sink_observer_->is_sink_available() h
miu
2016/11/05 04:05:15
+1
xjz
2016/11/07 19:03:55
Done.
xjz
2016/11/07 19:03:55
Done.
|
| + &RemotingCdmFactory::CreateCdm, weak_factory_.GetWeakPtr(), key_system, |
| + security_origin, cdm_config, session_message_cb, session_closed_cb, |
| + session_keys_change_cb, session_expiration_update_cb, cdm_created_cb, |
| + base::Passed(&remoting_cdm_controller))); |
| +} |
| + |
| +void RemotingCdmFactory::CreateCdm( |
| + const std::string& key_system, |
| + const GURL& security_origin, |
| + const CdmConfig& cdm_config, |
| + const SessionMessageCB& session_message_cb, |
| + const SessionClosedCB& session_closed_cb, |
| + const SessionKeysChangeCB& session_keys_change_cb, |
| + const SessionExpirationUpdateCB& session_expiration_update_cb, |
| + const CdmCreatedCB& cdm_created_cb, |
| + std::unique_ptr<RemotingCdmController> remoting_cdm_controller, |
| + bool is_remoting) { |
| + if (is_remoting) { |
| + VLOG(1) << "Create remoting CDM."; |
| + // TODO(xjz): Merge this with erickung's implementation to create remoting |
| + // CDM. |
| + NOTIMPLEMENTED(); |
| + } else { |
| + VLOG(1) << "Create default CDM."; |
| + default_cdm_factory_->Create(key_system, security_origin, cdm_config, |
| + session_message_cb, session_closed_cb, |
| + session_keys_change_cb, |
| + session_expiration_update_cb, cdm_created_cb); |
| + } |
| +} |
| + |
| +} // namespace media |