OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cdm/aes_decryptor.h" | 5 #include "media/cdm/aes_decryptor.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Returns whether the list is empty | 47 // Returns whether the list is empty |
48 bool Empty() const { return key_list_.empty(); } | 48 bool Empty() const { return key_list_.empty(); } |
49 | 49 |
50 // Returns the last inserted DecryptionKey. | 50 // Returns the last inserted DecryptionKey. |
51 DecryptionKey* LatestDecryptionKey() { | 51 DecryptionKey* LatestDecryptionKey() { |
52 DCHECK(!key_list_.empty()); | 52 DCHECK(!key_list_.empty()); |
53 return key_list_.begin()->second; | 53 return key_list_.begin()->second; |
54 } | 54 } |
55 | 55 |
| 56 bool Contains(const std::string& web_session_id) { |
| 57 return Find(web_session_id) != key_list_.end(); |
| 58 } |
| 59 |
56 private: | 60 private: |
57 // Searches the list for an element with |web_session_id|. | 61 // Searches the list for an element with |web_session_id|. |
58 KeyList::iterator Find(const std::string& web_session_id); | 62 KeyList::iterator Find(const std::string& web_session_id); |
59 | 63 |
60 // Deletes the entry pointed to by |position|. | 64 // Deletes the entry pointed to by |position|. |
61 void Erase(KeyList::iterator position); | 65 void Erase(KeyList::iterator position); |
62 | 66 |
63 KeyList key_list_; | 67 KeyList key_list_; |
64 | 68 |
65 DISALLOW_COPY_AND_ASSIGN(SessionIdDecryptionKeyMap); | 69 DISALLOW_COPY_AND_ASSIGN(SessionIdDecryptionKeyMap); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (!new_audio_key_cb_.is_null()) | 312 if (!new_audio_key_cb_.is_null()) |
309 new_audio_key_cb_.Run(); | 313 new_audio_key_cb_.Run(); |
310 | 314 |
311 if (!new_video_key_cb_.is_null()) | 315 if (!new_video_key_cb_.is_null()) |
312 new_video_key_cb_.Run(); | 316 new_video_key_cb_.Run(); |
313 } | 317 } |
314 | 318 |
315 promise->resolve(); | 319 promise->resolve(); |
316 } | 320 } |
317 | 321 |
| 322 void AesDecryptor::GetUsableKeyIds(const std::string& web_session_id, |
| 323 scoped_ptr<KeyIdsPromise> promise) { |
| 324 // Since |web_session_id| is not provided by the user, this should never |
| 325 // happen. |
| 326 DCHECK(valid_sessions_.find(web_session_id) != valid_sessions_.end()); |
| 327 |
| 328 KeyIdsVector keyids; |
| 329 base::AutoLock auto_lock(key_map_lock_); |
| 330 for (KeyIdToSessionKeysMap::iterator it = key_map_.begin(); |
| 331 it != key_map_.end(); |
| 332 ++it) { |
| 333 if (it->second->Contains(web_session_id)) |
| 334 keyids.push_back(std::vector<uint8>(it->first.begin(), it->first.end())); |
| 335 } |
| 336 promise->resolve(keyids); |
| 337 } |
| 338 |
318 void AesDecryptor::ReleaseSession(const std::string& web_session_id, | 339 void AesDecryptor::ReleaseSession(const std::string& web_session_id, |
319 scoped_ptr<SimpleCdmPromise> promise) { | 340 scoped_ptr<SimpleCdmPromise> promise) { |
320 // Validate that this is a reference to an active session and then forget it. | 341 // Validate that this is a reference to an active session and then forget it. |
321 std::set<std::string>::iterator it = valid_sessions_.find(web_session_id); | 342 std::set<std::string>::iterator it = valid_sessions_.find(web_session_id); |
322 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. | 343 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. |
323 if (it == valid_sessions_.end()) { | 344 if (it == valid_sessions_.end()) { |
324 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); | 345 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); |
325 return; | 346 return; |
326 } | 347 } |
327 | 348 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 bool AesDecryptor::DecryptionKey::Init() { | 508 bool AesDecryptor::DecryptionKey::Init() { |
488 CHECK(!secret_.empty()); | 509 CHECK(!secret_.empty()); |
489 decryption_key_.reset(crypto::SymmetricKey::Import( | 510 decryption_key_.reset(crypto::SymmetricKey::Import( |
490 crypto::SymmetricKey::AES, secret_)); | 511 crypto::SymmetricKey::AES, secret_)); |
491 if (!decryption_key_) | 512 if (!decryption_key_) |
492 return false; | 513 return false; |
493 return true; | 514 return true; |
494 } | 515 } |
495 | 516 |
496 } // namespace media | 517 } // namespace media |
OLD | NEW |