Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: content/common/media/content_decryption_module_service.cc

Issue 1637083002: Add CdmService to keep track of CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ContentDecryptionModule Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "content/public/common/content_decryption_module_service.h"
6
7 #include "content/public/common/content_client.h"
8
9 namespace content {
10
11 static base::LazyInstance<ContentDecryptionModuleService>::Leaky g_cdm_service =
12 LAZY_INSTANCE_INITIALIZER;
13
14 // static
15 ContentDecryptionModuleService* ContentDecryptionModuleService::GetInstance() {
16 return g_cdm_service.Pointer();
17 }
18
19 ContentDecryptionModuleService::ContentDecryptionModuleService() {
20 GetContentClient()->AddContentDecryptionModules(&registered_modules_);
21 }
22
23 ContentDecryptionModuleService::~ContentDecryptionModuleService() {}
24
25 void ContentDecryptionModuleService::Register(
26 const std::string& key_system,
27 const std::string& version,
28 const base::FilePath& module_library_path,
29 const std::vector<base::string16>& supported_codecs,
30 const std::vector<base::string16>& supported_init_data_types) {
31 DCHECK(!key_system.empty());
32 DCHECK(!version.empty());
33 for (size_t i = 0; i < registered_modules_.size(); i++) {
34 if (registered_modules_[i].key_system == key_system &&
35 registered_modules_[i].version == version) {
36 registered_modules_[i].module_library_path = module_library_path;
37 registered_modules_[i].supported_codecs = supported_codecs;
38 registered_modules_[i].supported_init_data_types =
39 supported_init_data_types;
40 return;
41 }
42 }
43
44 registered_modules_.insert(registered_modules_.begin(),
45 ContentDecryptionModuleRegistration(
46 key_system, version, module_library_path,
47 supported_codecs, supported_init_data_types));
48 }
49
50 bool ContentDecryptionModuleService::GetCdmLibraryPath(
51 const std::string& key_system,
52 const std::string& version,
53 base::FilePath* module_library_path) {
54 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
55 if (registered_modules_[i].key_system == key_system) {
56 if (version.empty() || registered_modules_[i].version == version) {
57 *module_library_path = registered_modules_[i].module_library_path;
58 return true;
59 }
60 }
61 }
62
63 // |key_system| not (yet) registered.
64 return false;
65 }
66
67 bool ContentDecryptionModuleService::GetSupportedCodecs(
68 const std::string& key_system,
69 const std::string& version,
70 std::vector<base::string16>* supported_codecs) {
71 for (size_t i = 0; i < registered_modules_.size(); i++) {
72 if (registered_modules_[i].key_system == key_system) {
73 if (version.empty() || registered_modules_[i].version == version) {
74 *supported_codecs = registered_modules_[i].supported_codecs;
75 return true;
76 }
77 }
78 }
79
80 // |key_system| not (yet) registered.
81 return false;
82 }
83
84 bool ContentDecryptionModuleService::GetSupportedInitDataTypes(
85 const std::string& key_system,
86 const std::string& version,
87 std::vector<base::string16>* supported_init_data_types) {
88 ContentDecryptionModuleRegistration* entry = FindEntry(key_system, version);
89 if (!entry)
90 return false;
91
92 *supported_init_data_types = entry->supported_init_data_types;
93 return true;
94 }
95
96 void ContentDecryptionModuleService::GetAllRegisteredModules(
97 std::vector<std::pair<std::string, base::FilePath>>* key_systems) {
98 DCHECK(key_systems->empty());
99
100 for (size_t i = 0; i < registered_modules_.size(); i++) {
101 key_systems->push_back(
102 std::make_pair(registered_modules_[i].key_system,
103 registered_modules_[i].module_library_path));
104 }
105 }
106
107 ContentDecryptionModuleRegistration* ContentDecryptionModuleService::FindEntry(
108 const std::string& key_system,
109 const std::string& version) {
110 for (size_t i = 0; i < registered_modules_.size(); i++) {
111 if (registered_modules_[i].key_system == key_system) {
112 // Found an entry that matches |key_system|, now match version if
113 // specified.
114 if (version.empty() || registered_modules_[i].version == version)
115 return &registered_modules_[i];
116 }
117 }
118
119 // |key_system| not (yet) registered.
120 return nullptr;
121 }
122
123 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698