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

Side by Side Diff: media/base/android/media_drm_bridge.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Created 3 years, 10 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/base/android/media_drm_bridge.h" 5 #include "media/base/android/media_drm_bridge.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/android/build_info.h" 11 #include "base/android/build_info.h"
12 #include "base/android/jni_array.h" 12 #include "base/android/jni_array.h"
13 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback_helpers.h" 15 #include "base/callback_helpers.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/lazy_instance.h"
18 #include "base/location.h" 17 #include "base/location.h"
19 #include "base/logging.h" 18 #include "base/logging.h"
20 #include "base/macros.h" 19 #include "base/macros.h"
21 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
24 #include "base/sys_byteorder.h" 23 #include "base/sys_byteorder.h"
25 #include "base/sys_info.h" 24 #include "base/sys_info.h"
26 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
27 #include "jni/MediaDrmBridge_jni.h" 26 #include "jni/MediaDrmBridge_jni.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 std::vector<std::string> key_systems; 158 std::vector<std::string> key_systems;
160 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin(); 159 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin();
161 it != key_system_uuid_map_.end(); ++it) { 160 it != key_system_uuid_map_.end(); ++it) {
162 // Rule out the key system handled by Chrome explicitly. 161 // Rule out the key system handled by Chrome explicitly.
163 if (it->first != kWidevineKeySystem) 162 if (it->first != kWidevineKeySystem)
164 key_systems.push_back(it->first); 163 key_systems.push_back(it->first);
165 } 164 }
166 return key_systems; 165 return key_systems;
167 } 166 }
168 167
169 base::LazyInstance<KeySystemManager>::Leaky g_key_system_manager = 168 KeySystemManager* GetKeySystemManager() {
170 LAZY_INSTANCE_INITIALIZER; 169 static KeySystemManager* ksm = new KeySystemManager();
170 return ksm;
171 }
171 172
172 // Checks whether |key_system| is supported with |container_mime_type|. Only 173 // Checks whether |key_system| is supported with |container_mime_type|. Only
173 // checks |key_system| support if |container_mime_type| is empty. 174 // checks |key_system| support if |container_mime_type| is empty.
174 // TODO(xhwang): The |container_mime_type| is not the same as contentType in 175 // TODO(xhwang): The |container_mime_type| is not the same as contentType in
175 // the EME spec. Revisit this once the spec issue with initData type is 176 // the EME spec. Revisit this once the spec issue with initData type is
176 // resolved. 177 // resolved.
177 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system, 178 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system,
178 const std::string& container_mime_type) { 179 const std::string& container_mime_type) {
179 DCHECK(MediaDrmBridge::IsAvailable()); 180 DCHECK(MediaDrmBridge::IsAvailable());
180 181
181 if (key_system.empty()) { 182 if (key_system.empty()) {
182 NOTREACHED(); 183 NOTREACHED();
183 return false; 184 return false;
184 } 185 }
185 186
186 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); 187 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system);
187 if (scheme_uuid.empty()) 188 if (scheme_uuid.empty())
188 return false; 189 return false;
189 190
190 JNIEnv* env = AttachCurrentThread(); 191 JNIEnv* env = AttachCurrentThread();
191 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = 192 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid =
192 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); 193 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size());
193 ScopedJavaLocalRef<jstring> j_container_mime_type = 194 ScopedJavaLocalRef<jstring> j_container_mime_type =
194 ConvertUTF8ToJavaString(env, container_mime_type); 195 ConvertUTF8ToJavaString(env, container_mime_type);
195 return Java_MediaDrmBridge_isCryptoSchemeSupported(env, j_scheme_uuid, 196 return Java_MediaDrmBridge_isCryptoSchemeSupported(env, j_scheme_uuid,
196 j_container_mime_type); 197 j_container_mime_type);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return false; 269 return false;
269 270
270 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); 271 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type);
271 } 272 }
272 273
273 // static 274 // static
274 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { 275 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() {
275 if (!MediaDrmBridge::IsAvailable()) 276 if (!MediaDrmBridge::IsAvailable())
276 return std::vector<std::string>(); 277 return std::vector<std::string>();
277 278
278 return g_key_system_manager.Get().GetPlatformKeySystemNames(); 279 return GetKeySystemManager()->GetPlatformKeySystemNames();
279 } 280 }
280 281
281 // static 282 // static
282 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( 283 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal(
283 const std::string& key_system, 284 const std::string& key_system,
284 SecurityLevel security_level, 285 SecurityLevel security_level,
285 const CreateFetcherCB& create_fetcher_cb, 286 const CreateFetcherCB& create_fetcher_cb,
286 const SessionMessageCB& session_message_cb, 287 const SessionMessageCB& session_message_cb,
287 const SessionClosedCB& session_closed_cb, 288 const SessionClosedCB& session_closed_cb,
288 const SessionKeysChangeCB& session_keys_change_cb, 289 const SessionKeysChangeCB& session_keys_change_cb,
289 const SessionExpirationUpdateCB& session_expiration_update_cb) { 290 const SessionExpirationUpdateCB& session_expiration_update_cb) {
290 // All paths requires the MediaDrmApis. 291 // All paths requires the MediaDrmApis.
291 DCHECK(AreMediaDrmApisAvailable()); 292 DCHECK(AreMediaDrmApisAvailable());
292 293
293 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); 294 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system);
294 if (scheme_uuid.empty()) 295 if (scheme_uuid.empty())
295 return nullptr; 296 return nullptr;
296 297
297 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( 298 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge(
298 scheme_uuid, security_level, create_fetcher_cb, session_message_cb, 299 scheme_uuid, security_level, create_fetcher_cb, session_message_cb,
299 session_closed_cb, session_keys_change_cb, session_expiration_update_cb)); 300 session_closed_cb, session_keys_change_cb, session_expiration_update_cb));
300 301
301 if (media_drm_bridge->j_media_drm_.is_null()) 302 if (media_drm_bridge->j_media_drm_.is_null())
302 media_drm_bridge = nullptr; 303 media_drm_bridge = nullptr;
303 304
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } 872 }
872 873
873 void MediaDrmBridge::OnHasAdditionalUsableKey() { 874 void MediaDrmBridge::OnHasAdditionalUsableKey() {
874 DCHECK(task_runner_->BelongsToCurrentThread()); 875 DCHECK(task_runner_->BelongsToCurrentThread());
875 DVLOG(1) << __func__; 876 DVLOG(1) << __func__;
876 877
877 player_tracker_.NotifyNewKey(); 878 player_tracker_.NotifyNewKey();
878 } 879 }
879 880
880 } // namespace media 881 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698