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

Side by Side Diff: media/cdm/json_web_key.cc

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
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/json_web_key.h" 5 #include "media/cdm/json_web_key.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 jwk->SetString(kKeyIdTag, key_id_string); 66 jwk->SetString(kKeyIdTag, key_id_string);
67 return jwk; 67 return jwk;
68 } 68 }
69 69
70 std::string GenerateJWKSet(const uint8_t* key, 70 std::string GenerateJWKSet(const uint8_t* key,
71 int key_length, 71 int key_length,
72 const uint8_t* key_id, 72 const uint8_t* key_id,
73 int key_id_length) { 73 int key_id_length) {
74 // Create the JWK, and wrap it into a JWK Set. 74 // Create the JWK, and wrap it into a JWK Set.
75 std::unique_ptr<base::ListValue> list(new base::ListValue()); 75 std::unique_ptr<base::ListValue> list(new base::ListValue());
76 list->Append( 76 list->Append(CreateJSONDictionary(key, key_length, key_id, key_id_length));
77 CreateJSONDictionary(key, key_length, key_id, key_id_length).release());
78 base::DictionaryValue jwk_set; 77 base::DictionaryValue jwk_set;
79 jwk_set.Set(kKeysTag, list.release()); 78 jwk_set.Set(kKeysTag, list.release());
80 79
81 // Finally serialize |jwk_set| into a string and return it. 80 // Finally serialize |jwk_set| into a string and return it.
82 std::string serialized_jwk; 81 std::string serialized_jwk;
83 JSONStringValueSerializer serializer(&serialized_jwk); 82 JSONStringValueSerializer serializer(&serialized_jwk);
84 serializer.Serialize(jwk_set); 83 serializer.Serialize(jwk_set);
85 return serialized_jwk; 84 return serialized_jwk;
86 } 85 }
87 86
88 std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys, 87 std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys,
89 MediaKeys::SessionType session_type) { 88 MediaKeys::SessionType session_type) {
90 std::unique_ptr<base::ListValue> list(new base::ListValue()); 89 std::unique_ptr<base::ListValue> list(new base::ListValue());
91 for (const auto& key_pair : keys) { 90 for (const auto& key_pair : keys) {
92 list->Append(CreateJSONDictionary( 91 list->Append(CreateJSONDictionary(
93 reinterpret_cast<const uint8_t*>(key_pair.second.data()), 92 reinterpret_cast<const uint8_t*>(key_pair.second.data()),
94 key_pair.second.length(), 93 key_pair.second.length(),
95 reinterpret_cast<const uint8_t*>(key_pair.first.data()), 94 reinterpret_cast<const uint8_t*>(key_pair.first.data()),
96 key_pair.first.length()) 95 key_pair.first.length()));
97 .release());
98 } 96 }
99 97
100 base::DictionaryValue jwk_set; 98 base::DictionaryValue jwk_set;
101 jwk_set.Set(kKeysTag, list.release()); 99 jwk_set.Set(kKeysTag, list.release());
102 switch (session_type) { 100 switch (session_type) {
103 case MediaKeys::TEMPORARY_SESSION: 101 case MediaKeys::TEMPORARY_SESSION:
104 jwk_set.SetString(kTypeTag, kTemporarySession); 102 jwk_set.SetString(kTypeTag, kTemporarySession);
105 break; 103 break;
106 case MediaKeys::PERSISTENT_LICENSE_SESSION: 104 case MediaKeys::PERSISTENT_LICENSE_SESSION:
107 jwk_set.SetString(kTypeTag, kPersistentLicenseSession); 105 jwk_set.SetString(kTypeTag, kPersistentLicenseSession);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 DVLOG(1) << "Invalid '" << kKeyIdsTag << "' value: " << encoded_key; 409 DVLOG(1) << "Invalid '" << kKeyIdsTag << "' value: " << encoded_key;
412 return false; 410 return false;
413 } 411 }
414 412
415 std::vector<uint8_t> result(decoded_string.begin(), decoded_string.end()); 413 std::vector<uint8_t> result(decoded_string.begin(), decoded_string.end());
416 first_key->swap(result); 414 first_key->swap(result);
417 return true; 415 return true;
418 } 416 }
419 417
420 } // namespace media 418 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698