Chromium Code Reviews| 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 "content/browser/media/android/media_drm_credential_manager.h" | 5 #include "content/browser/media/android/media_drm_credential_manager.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/scoped_java_ref.h" | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/memory/singleton.h" | |
|
qinmin
2013/09/24 02:35:48
nit: this is already included in the header
Kibeom Kim (inactive)
2013/09/24 02:52:48
Done.
| |
| 12 #include "jni/MediaDrmCredentialManager_jni.h" | |
| 9 #include "media/base/android/media_drm_bridge.h" | 13 #include "media/base/android/media_drm_bridge.h" |
| 10 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 11 | 15 |
| 16 using base::android::ScopedJavaGlobalRef; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void MediaDrmCredentialManagerCallback( | |
| 21 const ScopedJavaGlobalRef<jobject>& j_media_drm_credential_manager_callback, | |
| 22 bool succeeded) { | |
| 23 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 24 content::Java_MediaDrmCredentialManagerCallback_onCredentialResetFinished( | |
| 25 env, j_media_drm_credential_manager_callback.obj(), succeeded); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 12 namespace content { | 30 namespace content { |
| 13 | 31 |
| 14 // TODO(qinmin): Move the UUID definition to some common places. | 32 // TODO(qinmin): Move the UUID definition to some common places. |
| 15 static const uint8 kWidevineUuid[16] = { | 33 static const uint8 kWidevineUuid[16] = { |
| 16 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 34 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
| 17 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 35 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
| 18 | 36 |
| 19 MediaDrmCredentialManager::MediaDrmCredentialManager() {} | 37 // static |
| 20 | 38 MediaDrmCredentialManager* MediaDrmCredentialManager::GetInstance() { |
| 21 MediaDrmCredentialManager::~MediaDrmCredentialManager() {} | 39 return Singleton<MediaDrmCredentialManager>::get(); |
| 40 } | |
| 22 | 41 |
| 23 void MediaDrmCredentialManager::ResetCredentials( | 42 void MediaDrmCredentialManager::ResetCredentials( |
| 24 const ResetCredentialsCB& callback) { | 43 const ResetCredentialsCB& callback) { |
| 25 // Ignore reset request if one is already in progress. | 44 // Ignore reset request if one is already in progress. |
| 26 if (!reset_credentials_cb_.is_null()) | 45 if (!reset_credentials_cb_.is_null()) |
| 27 return; | 46 return; |
| 28 | 47 |
| 29 reset_credentials_cb_ = callback; | 48 reset_credentials_cb_ = callback; |
| 30 | 49 |
| 31 // First reset the L3 credential. | 50 // First reset the L3 credential. |
| 32 if (!ResetCredentialsInternal("L3")) { | 51 if (!ResetCredentialsInternal("L3")) { |
| 33 // TODO(qinmin): We should post a task instead. | 52 // TODO(qinmin): We should post a task instead. |
| 34 base::ResetAndReturn(&reset_credentials_cb_).Run(false); | 53 base::ResetAndReturn(&reset_credentials_cb_).Run(false); |
| 35 } | 54 } |
| 36 } | 55 } |
| 37 | 56 |
| 57 // static | |
| 58 void ResetCredentials( | |
| 59 JNIEnv* env, | |
| 60 jclass clazz, | |
| 61 jobject j_media_drm_credential_manager_callback) { | |
| 62 MediaDrmCredentialManager* media_drm_credential_manager = | |
| 63 MediaDrmCredentialManager::GetInstance(); | |
| 64 | |
| 65 ScopedJavaGlobalRef<jobject> j_scoped_media_drm_credential_manager_callback; | |
| 66 j_scoped_media_drm_credential_manager_callback.Reset( | |
| 67 env, j_media_drm_credential_manager_callback); | |
| 68 | |
| 69 MediaDrmCredentialManager::ResetCredentialsCB callback_runner = | |
| 70 base::Bind(&MediaDrmCredentialManagerCallback, | |
| 71 j_scoped_media_drm_credential_manager_callback); | |
| 72 | |
| 73 media_drm_credential_manager->ResetCredentials(callback_runner); | |
| 74 } | |
| 75 | |
| 38 void MediaDrmCredentialManager::OnResetCredentialsCompleted( | 76 void MediaDrmCredentialManager::OnResetCredentialsCompleted( |
| 39 const std::string& security_level, bool success) { | 77 const std::string& security_level, bool success) { |
| 40 if (security_level == "L3" && success) { | 78 if (security_level == "L3" && success) { |
| 41 if (ResetCredentialsInternal("L1")) | 79 if (ResetCredentialsInternal("L1")) |
| 42 return; | 80 return; |
| 43 success = false; | 81 success = false; |
| 44 } | 82 } |
| 45 | 83 |
| 46 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 84 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 47 media_drm_bridge_.reset(); | 85 media_drm_bridge_.reset(); |
| 48 } | 86 } |
| 49 | 87 |
| 50 bool MediaDrmCredentialManager::ResetCredentialsInternal( | 88 bool MediaDrmCredentialManager::ResetCredentialsInternal( |
| 51 const std::string& security_level) { | 89 const std::string& security_level) { |
| 52 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); | 90 std::vector<uint8> uuid(kWidevineUuid, kWidevineUuid + 16); |
| 53 media_drm_bridge_ = media::MediaDrmBridge::Create( | 91 media_drm_bridge_ = media::MediaDrmBridge::Create( |
| 54 0, uuid, GURL(), security_level, NULL); | 92 0, uuid, GURL(), security_level, NULL); |
| 55 if (!media_drm_bridge_) | 93 if (!media_drm_bridge_) |
| 56 return false; | 94 return false; |
| 57 media_drm_bridge_->ResetDeviceCredentials( | 95 media_drm_bridge_->ResetDeviceCredentials( |
| 58 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, | 96 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted, |
| 59 base::Unretained(this), security_level)); | 97 base::Unretained(this), security_level)); |
| 60 return true; | 98 return true; |
| 61 } | 99 } |
| 62 | 100 |
| 101 // static | |
| 102 bool MediaDrmCredentialManager::RegisterMediaDrmCredentialManager(JNIEnv* env) { | |
| 103 return RegisterNativesImpl(env); | |
| 104 } | |
| 105 | |
| 63 } // namespace content | 106 } // namespace content |
| OLD | NEW |