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

Side by Side Diff: media/mojo/services/mojo_cdm_service.cc

Issue 2568463003: media: Rename MediaKeys to ContentDecryptionModule (Closed)
Patch Set: comments addressed Created 4 years 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
« no previous file with comments | « media/mojo/services/mojo_cdm_service.h ('k') | media/mojo/services/mojo_cdm_service_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/mojo/services/mojo_cdm_service.h" 5 #include "media/mojo/services/mojo_cdm_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 namespace { 27 namespace {
28 28
29 // Manages all CDMs created by MojoCdmService. Can only have one instance per 29 // Manages all CDMs created by MojoCdmService. Can only have one instance per
30 // process so use a LazyInstance to ensure this. 30 // process so use a LazyInstance to ensure this.
31 class CdmManager { 31 class CdmManager {
32 public: 32 public:
33 CdmManager() {} 33 CdmManager() {}
34 ~CdmManager() {} 34 ~CdmManager() {}
35 35
36 // Returns the CDM associated with |cdm_id|. Can be called on any thread. 36 // Returns the CDM associated with |cdm_id|. Can be called on any thread.
37 scoped_refptr<MediaKeys> GetCdm(int cdm_id) { 37 scoped_refptr<ContentDecryptionModule> GetCdm(int cdm_id) {
38 base::AutoLock lock(lock_); 38 base::AutoLock lock(lock_);
39 auto iter = cdm_map_.find(cdm_id); 39 auto iter = cdm_map_.find(cdm_id);
40 return iter == cdm_map_.end() ? nullptr : iter->second; 40 return iter == cdm_map_.end() ? nullptr : iter->second;
41 } 41 }
42 42
43 // Registers the |cdm| for |cdm_id|. 43 // Registers the |cdm| for |cdm_id|.
44 void RegisterCdm(int cdm_id, const scoped_refptr<MediaKeys>& cdm) { 44 void RegisterCdm(int cdm_id,
45 const scoped_refptr<ContentDecryptionModule>& cdm) {
45 base::AutoLock lock(lock_); 46 base::AutoLock lock(lock_);
46 DCHECK(!cdm_map_.count(cdm_id)); 47 DCHECK(!cdm_map_.count(cdm_id));
47 cdm_map_[cdm_id] = cdm; 48 cdm_map_[cdm_id] = cdm;
48 } 49 }
49 50
50 // Unregisters the CDM associated with |cdm_id|. 51 // Unregisters the CDM associated with |cdm_id|.
51 void UnregisterCdm(int cdm_id) { 52 void UnregisterCdm(int cdm_id) {
52 base::AutoLock lock(lock_); 53 base::AutoLock lock(lock_);
53 DCHECK(cdm_map_.count(cdm_id)); 54 DCHECK(cdm_map_.count(cdm_id));
54 cdm_map_.erase(cdm_id); 55 cdm_map_.erase(cdm_id);
55 } 56 }
56 57
57 private: 58 private:
58 // Lock to protect |cdm_map_|. 59 // Lock to protect |cdm_map_|.
59 base::Lock lock_; 60 base::Lock lock_;
60 std::map<int, scoped_refptr<MediaKeys>> cdm_map_; 61 std::map<int, scoped_refptr<ContentDecryptionModule>> cdm_map_;
61 62
62 DISALLOW_COPY_AND_ASSIGN(CdmManager); 63 DISALLOW_COPY_AND_ASSIGN(CdmManager);
63 }; 64 };
64 65
65 base::LazyInstance<CdmManager>::Leaky g_cdm_manager = LAZY_INSTANCE_INITIALIZER; 66 base::LazyInstance<CdmManager>::Leaky g_cdm_manager = LAZY_INSTANCE_INITIALIZER;
66 67
67 } // namespace 68 } // namespace
68 69
69 using SimpleMojoCdmPromise = MojoCdmPromise<>; 70 using SimpleMojoCdmPromise = MojoCdmPromise<>;
70 using NewSessionMojoCdmPromise = MojoCdmPromise<std::string>; 71 using NewSessionMojoCdmPromise = MojoCdmPromise<std::string>;
71 72
72 int MojoCdmService::next_cdm_id_ = CdmContext::kInvalidCdmId + 1; 73 int MojoCdmService::next_cdm_id_ = CdmContext::kInvalidCdmId + 1;
73 74
74 // static 75 // static
75 scoped_refptr<MediaKeys> MojoCdmService::LegacyGetCdm(int cdm_id) { 76 scoped_refptr<ContentDecryptionModule> MojoCdmService::LegacyGetCdm(
77 int cdm_id) {
76 DVLOG(1) << __func__ << ": " << cdm_id; 78 DVLOG(1) << __func__ << ": " << cdm_id;
77 return g_cdm_manager.Get().GetCdm(cdm_id); 79 return g_cdm_manager.Get().GetCdm(cdm_id);
78 } 80 }
79 81
80 MojoCdmService::MojoCdmService(base::WeakPtr<MojoCdmServiceContext> context, 82 MojoCdmService::MojoCdmService(base::WeakPtr<MojoCdmServiceContext> context,
81 CdmFactory* cdm_factory) 83 CdmFactory* cdm_factory)
82 : context_(context), 84 : context_(context),
83 cdm_factory_(cdm_factory), 85 cdm_factory_(cdm_factory),
84 cdm_id_(CdmContext::kInvalidCdmId), 86 cdm_id_(CdmContext::kInvalidCdmId),
85 weak_factory_(this) { 87 weak_factory_(this) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 base::MakeUnique<SimpleMojoCdmPromise>(callback)); 163 base::MakeUnique<SimpleMojoCdmPromise>(callback));
162 } 164 }
163 165
164 void MojoCdmService::RemoveSession(const std::string& session_id, 166 void MojoCdmService::RemoveSession(const std::string& session_id,
165 const RemoveSessionCallback& callback) { 167 const RemoveSessionCallback& callback) {
166 DVLOG(2) << __func__; 168 DVLOG(2) << __func__;
167 cdm_->RemoveSession(session_id, 169 cdm_->RemoveSession(session_id,
168 base::MakeUnique<SimpleMojoCdmPromise>(callback)); 170 base::MakeUnique<SimpleMojoCdmPromise>(callback));
169 } 171 }
170 172
171 scoped_refptr<MediaKeys> MojoCdmService::GetCdm() { 173 scoped_refptr<ContentDecryptionModule> MojoCdmService::GetCdm() {
172 return cdm_; 174 return cdm_;
173 } 175 }
174 176
175 void MojoCdmService::OnCdmCreated(const InitializeCallback& callback, 177 void MojoCdmService::OnCdmCreated(
176 const scoped_refptr<MediaKeys>& cdm, 178 const InitializeCallback& callback,
177 const std::string& error_message) { 179 const scoped_refptr<::media::ContentDecryptionModule>& cdm,
180 const std::string& error_message) {
178 mojom::CdmPromiseResultPtr cdm_promise_result(mojom::CdmPromiseResult::New()); 181 mojom::CdmPromiseResultPtr cdm_promise_result(mojom::CdmPromiseResult::New());
179 182
180 // TODO(xhwang): This should not happen when KeySystemInfo is properly 183 // TODO(xhwang): This should not happen when KeySystemInfo is properly
181 // populated. See http://crbug.com/469366 184 // populated. See http://crbug.com/469366
182 if (!cdm || !context_) { 185 if (!cdm || !context_) {
183 cdm_promise_result->success = false; 186 cdm_promise_result->success = false;
184 cdm_promise_result->exception = CdmPromise::Exception::NOT_SUPPORTED_ERROR; 187 cdm_promise_result->exception = CdmPromise::Exception::NOT_SUPPORTED_ERROR;
185 cdm_promise_result->system_code = 0; 188 cdm_promise_result->system_code = 0;
186 cdm_promise_result->error_message = error_message; 189 cdm_promise_result->error_message = error_message;
187 callback.Run(std::move(cdm_promise_result), 0, nullptr); 190 callback.Run(std::move(cdm_promise_result), 0, nullptr);
(...skipping 17 matching lines...) Expand all
205 cdm_, GetProxy(&decryptor_service), 208 cdm_, GetProxy(&decryptor_service),
206 base::Bind(&MojoCdmService::OnDecryptorConnectionError, weak_this_))); 209 base::Bind(&MojoCdmService::OnDecryptorConnectionError, weak_this_)));
207 } 210 }
208 211
209 DVLOG(1) << __func__ << ": CDM successfully created with ID " << cdm_id_; 212 DVLOG(1) << __func__ << ": CDM successfully created with ID " << cdm_id_;
210 cdm_promise_result->success = true; 213 cdm_promise_result->success = true;
211 callback.Run(std::move(cdm_promise_result), cdm_id_, 214 callback.Run(std::move(cdm_promise_result), cdm_id_,
212 std::move(decryptor_service)); 215 std::move(decryptor_service));
213 } 216 }
214 217
215 void MojoCdmService::OnSessionMessage(const std::string& session_id, 218 void MojoCdmService::OnSessionMessage(
216 MediaKeys::MessageType message_type, 219 const std::string& session_id,
217 const std::vector<uint8_t>& message) { 220 ::media::ContentDecryptionModule::MessageType message_type,
221 const std::vector<uint8_t>& message) {
218 DVLOG(2) << __func__ << "(" << message_type << ")"; 222 DVLOG(2) << __func__ << "(" << message_type << ")";
219 client_->OnSessionMessage(session_id, message_type, message); 223 client_->OnSessionMessage(session_id, message_type, message);
220 } 224 }
221 225
222 void MojoCdmService::OnSessionKeysChange(const std::string& session_id, 226 void MojoCdmService::OnSessionKeysChange(const std::string& session_id,
223 bool has_additional_usable_key, 227 bool has_additional_usable_key,
224 CdmKeysInfo keys_info) { 228 CdmKeysInfo keys_info) {
225 DVLOG(2) << __func__ 229 DVLOG(2) << __func__
226 << " has_additional_usable_key=" << has_additional_usable_key; 230 << " has_additional_usable_key=" << has_additional_usable_key;
227 231
(...skipping 18 matching lines...) Expand all
246 250
247 void MojoCdmService::OnDecryptorConnectionError() { 251 void MojoCdmService::OnDecryptorConnectionError() {
248 DVLOG(2) << __func__; 252 DVLOG(2) << __func__;
249 253
250 // MojoDecryptorService has lost connectivity to it's client, so it can be 254 // MojoDecryptorService has lost connectivity to it's client, so it can be
251 // freed. 255 // freed.
252 decryptor_.reset(); 256 decryptor_.reset();
253 } 257 }
254 258
255 } // namespace media 259 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_cdm_service.h ('k') | media/mojo/services/mojo_cdm_service_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698