Chromium Code Reviews| Index: content/common/media/content_decryption_module_service.cc |
| diff --git a/content/common/media/content_decryption_module_service.cc b/content/common/media/content_decryption_module_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae1d6a3bd44352442b9232a52fb47c1ffe541d39 |
| --- /dev/null |
| +++ b/content/common/media/content_decryption_module_service.cc |
| @@ -0,0 +1,123 @@ |
| +// 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 "content/public/common/content_decryption_module_service.h" |
| + |
| +#include "content/public/common/content_client.h" |
| + |
| +namespace content { |
| + |
| +static base::LazyInstance<ContentDecryptionModuleService>::Leaky g_cdm_service = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +// static |
| +ContentDecryptionModuleService* ContentDecryptionModuleService::GetInstance() { |
| + return g_cdm_service.Pointer(); |
| +} |
| + |
| +ContentDecryptionModuleService::ContentDecryptionModuleService() { |
| + GetContentClient()->AddContentDecryptionModules(®istered_modules_); |
| +} |
| + |
| +ContentDecryptionModuleService::~ContentDecryptionModuleService() {} |
| + |
| +void ContentDecryptionModuleService::Register( |
| + const std::string& key_system, |
| + const std::string& version, |
| + const base::FilePath& module_library_path, |
| + const std::vector<base::string16>& supported_codecs, |
| + const std::vector<base::string16>& supported_init_data_types) { |
| + DCHECK(!key_system.empty()); |
| + DCHECK(!version.empty()); |
| + for (size_t i = 0; i < registered_modules_.size(); i++) { |
| + if (registered_modules_[i].key_system == key_system && |
| + registered_modules_[i].version == version) { |
| + registered_modules_[i].module_library_path = module_library_path; |
| + registered_modules_[i].supported_codecs = supported_codecs; |
| + registered_modules_[i].supported_init_data_types = |
| + supported_init_data_types; |
| + return; |
| + } |
| + } |
| + |
| + registered_modules_.insert(registered_modules_.begin(), |
| + ContentDecryptionModuleRegistration( |
| + key_system, version, module_library_path, |
| + supported_codecs, supported_init_data_types)); |
| +} |
| + |
| +bool ContentDecryptionModuleService::GetCdmLibraryPath( |
| + const std::string& key_system, |
| + const std::string& version, |
| + base::FilePath* module_library_path) { |
| + for (size_t i = 0; i < registered_modules_.size(); i++) { |
|
jrummell
2016/03/04 01:19:41
I added FindEntry() to avoid duplicating code and
|
| + if (registered_modules_[i].key_system == key_system) { |
| + if (version.empty() || registered_modules_[i].version == version) { |
| + *module_library_path = registered_modules_[i].module_library_path; |
| + return true; |
| + } |
| + } |
| + } |
| + |
| + // |key_system| not (yet) registered. |
| + return false; |
| +} |
| + |
| +bool ContentDecryptionModuleService::GetSupportedCodecs( |
| + const std::string& key_system, |
| + const std::string& version, |
| + std::vector<base::string16>* supported_codecs) { |
| + for (size_t i = 0; i < registered_modules_.size(); i++) { |
| + if (registered_modules_[i].key_system == key_system) { |
| + if (version.empty() || registered_modules_[i].version == version) { |
| + *supported_codecs = registered_modules_[i].supported_codecs; |
| + return true; |
| + } |
| + } |
| + } |
| + |
| + // |key_system| not (yet) registered. |
| + return false; |
| +} |
| + |
| +bool ContentDecryptionModuleService::GetSupportedInitDataTypes( |
| + const std::string& key_system, |
| + const std::string& version, |
| + std::vector<base::string16>* supported_init_data_types) { |
| + ContentDecryptionModuleRegistration* entry = FindEntry(key_system, version); |
| + if (!entry) |
| + return false; |
| + |
| + *supported_init_data_types = entry->supported_init_data_types; |
| + return true; |
| +} |
| + |
| +void ContentDecryptionModuleService::GetAllRegisteredModules( |
| + std::vector<std::pair<std::string, base::FilePath>>* key_systems) { |
| + DCHECK(key_systems->empty()); |
| + |
| + for (size_t i = 0; i < registered_modules_.size(); i++) { |
| + key_systems->push_back( |
| + std::make_pair(registered_modules_[i].key_system, |
| + registered_modules_[i].module_library_path)); |
| + } |
| +} |
| + |
| +ContentDecryptionModuleRegistration* ContentDecryptionModuleService::FindEntry( |
| + const std::string& key_system, |
| + const std::string& version) { |
| + for (size_t i = 0; i < registered_modules_.size(); i++) { |
| + if (registered_modules_[i].key_system == key_system) { |
| + // Found an entry that matches |key_system|, now match version if |
| + // specified. |
| + if (version.empty() || registered_modules_[i].version == version) |
| + return ®istered_modules_[i]; |
| + } |
| + } |
| + |
| + // |key_system| not (yet) registered. |
| + return nullptr; |
| +} |
| + |
| +} // namespace media |