Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / media / android / media_drm_credential_manager.cc
blob0fb86184fbb3131020f2ae98d8c85320e894e41a
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
3 // found in the LICENSE file.
5 #include "content/browser/media/android/media_drm_credential_manager.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_ref.h"
9 #include "base/bind.h"
10 #include "base/callback_helpers.h"
11 #include "base/location.h"
12 #include "base/message_loop/message_loop_proxy.h"
13 #include "jni/MediaDrmCredentialManager_jni.h"
14 #include "media/base/android/media_drm_bridge.h"
15 #include "url/gurl.h"
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
19 using base::android::ScopedJavaGlobalRef;
21 namespace {
23 void MediaDrmCredentialManagerCallback(
24 const ScopedJavaGlobalRef<jobject>& j_media_drm_credential_manager_callback,
25 bool succeeded) {
26 JNIEnv* env = base::android::AttachCurrentThread();
27 content::Java_MediaDrmCredentialManagerCallback_onCredentialResetFinished(
28 env, j_media_drm_credential_manager_callback.obj(), succeeded);
31 } // namespace
33 namespace content {
35 MediaDrmCredentialManager::MediaDrmCredentialManager() {};
37 MediaDrmCredentialManager::~MediaDrmCredentialManager() {};
39 // static
40 MediaDrmCredentialManager* MediaDrmCredentialManager::GetInstance() {
41 return Singleton<MediaDrmCredentialManager>::get();
44 void MediaDrmCredentialManager::ResetCredentials(
45 const ResetCredentialsCB& reset_credentials_cb) {
46 // Ignore reset request if one is already in progress.
47 if (!reset_credentials_cb_.is_null())
48 return;
50 reset_credentials_cb_ = reset_credentials_cb;
52 // First reset the L3 credential.
53 if (!ResetCredentialsInternal(media::MediaDrmBridge::SECURITY_LEVEL_3)) {
54 // TODO(qinmin): We should post a task instead.
55 base::ResetAndReturn(&reset_credentials_cb_).Run(false);
59 // static
60 void ResetCredentials(
61 JNIEnv* env,
62 jclass clazz,
63 jobject j_media_drm_credential_manager_callback) {
64 MediaDrmCredentialManager* media_drm_credential_manager =
65 MediaDrmCredentialManager::GetInstance();
67 ScopedJavaGlobalRef<jobject> j_scoped_media_drm_credential_manager_callback;
68 j_scoped_media_drm_credential_manager_callback.Reset(
69 env, j_media_drm_credential_manager_callback);
71 MediaDrmCredentialManager::ResetCredentialsCB callback_runner =
72 base::Bind(&MediaDrmCredentialManagerCallback,
73 j_scoped_media_drm_credential_manager_callback);
75 media_drm_credential_manager->ResetCredentials(callback_runner);
78 void MediaDrmCredentialManager::OnResetCredentialsCompleted(
79 SecurityLevel security_level, bool success) {
80 if (security_level == media::MediaDrmBridge::SECURITY_LEVEL_3 && success) {
81 if (ResetCredentialsInternal(media::MediaDrmBridge::SECURITY_LEVEL_1))
82 return;
83 success = false;
86 base::ResetAndReturn(&reset_credentials_cb_).Run(success);
87 media_drm_bridge_.reset();
90 bool MediaDrmCredentialManager::ResetCredentialsInternal(
91 SecurityLevel security_level) {
92 media_drm_bridge_ =
93 media::MediaDrmBridge::Create(0, kWidevineKeySystem, GURL(), NULL);
94 if (!media_drm_bridge_)
95 return false;
97 ResetCredentialsCB reset_credentials_cb =
98 base::Bind(&MediaDrmCredentialManager::OnResetCredentialsCompleted,
99 base::Unretained(this), security_level);
101 if (!media_drm_bridge_->SetSecurityLevel(security_level)) {
102 // No need to reset credentials for unsupported |security_level|.
103 base::MessageLoopProxy::current()->PostTask(
104 FROM_HERE, base::Bind(reset_credentials_cb, true));
105 return true;
108 media_drm_bridge_->ResetDeviceCredentials(reset_credentials_cb);
109 return true;
112 // static
113 bool MediaDrmCredentialManager::RegisterMediaDrmCredentialManager(JNIEnv* env) {
114 return RegisterNativesImpl(env);
117 } // namespace content