| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ |
| 6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> |
| 10 | 11 |
| 11 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "media/base/android/android_util.h" |
| 17 #include "media/base/android/media_drm_storage.h" |
| 18 #include "url/origin.h" |
| 14 | 19 |
| 15 namespace base { | 20 namespace base { |
| 16 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
| 17 } // namespace base | 22 } // namespace base |
| 18 | 23 |
| 19 namespace media { | 24 namespace media { |
| 20 | 25 |
| 21 // This class is the native version of MediaDrmStorageBridge in Java. It's used | 26 // This class is the native version of MediaDrmStorageBridge in Java. It's used |
| 22 // to talk to the concrete implementation for persistent data management. | 27 // to talk to the concrete implementation for persistent data management. |
| 23 class MediaDrmStorageBridge { | 28 class MediaDrmStorageBridge { |
| 24 public: | 29 public: |
| 25 static bool RegisterMediaDrmStorageBridge(JNIEnv* env); | 30 static bool RegisterMediaDrmStorageBridge(JNIEnv* env); |
| 26 | 31 |
| 27 MediaDrmStorageBridge(); | 32 MediaDrmStorageBridge(const url::Origin& origin, |
| 33 const CreateStorageCB& create_storage_cb); |
| 28 ~MediaDrmStorageBridge(); | 34 ~MediaDrmStorageBridge(); |
| 29 | 35 |
| 30 // The following OnXXX functions are called by Java. The functions will post | 36 // The following OnXXX functions are called by Java. The functions will post |
| 31 // task on message loop immediately to avoid reentrancy issues. | 37 // task on message loop immediately to avoid reentrancy issues. |
| 32 | 38 |
| 33 // Called by the java object when device provision is finished. Implementation | 39 // Called by the java object when device provision is finished. Implementation |
| 34 // will record the time as provisioning time. | 40 // will record the time as provisioning time. |
| 35 void OnProvisioned(JNIEnv* env, | 41 void OnProvisioned(JNIEnv* env, |
| 36 const base::android::JavaParamRef<jobject>& j_storage, | 42 const base::android::JavaParamRef<jobject>& j_storage, |
| 37 // Callback<Boolean> | 43 // Callback<Boolean> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 54 const base::android::JavaParamRef<jobject>& j_callback); | 60 const base::android::JavaParamRef<jobject>& j_callback); |
| 55 | 61 |
| 56 // Called by the java object to remove persistent session data. | 62 // Called by the java object to remove persistent session data. |
| 57 void OnClearInfo(JNIEnv* env, | 63 void OnClearInfo(JNIEnv* env, |
| 58 const base::android::JavaParamRef<jobject>& j_storage, | 64 const base::android::JavaParamRef<jobject>& j_storage, |
| 59 const base::android::JavaParamRef<jbyteArray>& j_session_id, | 65 const base::android::JavaParamRef<jbyteArray>& j_session_id, |
| 60 // Callback<Boolean> | 66 // Callback<Boolean> |
| 61 const base::android::JavaParamRef<jobject>& j_callback); | 67 const base::android::JavaParamRef<jobject>& j_callback); |
| 62 | 68 |
| 63 private: | 69 private: |
| 70 void RunAndroidBoolCallback(JavaObjectPtr j_callback, bool success); |
| 71 void OnSessionDataLoaded( |
| 72 JavaObjectPtr j_callback, |
| 73 const std::string& session_id, |
| 74 std::unique_ptr<MediaDrmStorage::SessionData> session_data); |
| 75 |
| 76 MediaDrmStorage* GetStorageImpl(); |
| 77 |
| 78 CreateStorageCB create_storage_cb_; |
| 79 std::unique_ptr<MediaDrmStorage> impl_; |
| 80 |
| 81 const url::Origin origin_; |
| 82 |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 65 | 84 |
| 66 // NOTE: Weak pointers must be invalidated before all other member variables. | |
| 67 base::WeakPtrFactory<MediaDrmStorageBridge> weak_factory_; | 85 base::WeakPtrFactory<MediaDrmStorageBridge> weak_factory_; |
| 68 | 86 |
| 69 DISALLOW_COPY_AND_ASSIGN(MediaDrmStorageBridge); | 87 DISALLOW_COPY_AND_ASSIGN(MediaDrmStorageBridge); |
| 70 }; | 88 }; |
| 71 | 89 |
| 72 } // namespace media | 90 } // namespace media |
| 73 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ | 91 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_STORAGE_BRIDGE_H_ |
| OLD | NEW |