Home | History | Annotate | Download | only in android
      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.
      4 
      5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_DRM_CREDENTIAL_MANAGER_H_
      6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_DRM_CREDENTIAL_MANAGER_H_
      7 
      8 #include <jni.h>
      9 #include <string>
     10 
     11 #include "base/callback.h"
     12 #include "base/memory/singleton.h"
     13 #include "media/base/android/media_drm_bridge.h"
     14 
     15 namespace content {
     16 
     17 // This class manages the media DRM credentials on Android.
     18 class MediaDrmCredentialManager {
     19  public:
     20   static MediaDrmCredentialManager* GetInstance();
     21 
     22   typedef base::Callback<void(bool)> ResetCredentialsCB;
     23 
     24   // Called to reset the DRM credentials. (for Java)
     25   static void ResetCredentials(JNIEnv* env, jclass clazz, jobject callback);
     26 
     27   // Called to reset the DRM credentials. The result is returned in the
     28   // |reset_credentials_cb|.
     29   void ResetCredentials(const ResetCredentialsCB& reset_credentials_cb);
     30 
     31   static bool RegisterMediaDrmCredentialManager(JNIEnv* env);
     32 
     33  private:
     34   friend struct DefaultSingletonTraits<MediaDrmCredentialManager>;
     35   friend class Singleton<MediaDrmCredentialManager>;
     36   typedef media::MediaDrmBridge::SecurityLevel SecurityLevel;
     37 
     38   MediaDrmCredentialManager();
     39   ~MediaDrmCredentialManager();
     40 
     41   // Callback function passed to MediaDrmBridge. It is called when credentials
     42   // reset is completed.
     43   void OnResetCredentialsCompleted(SecurityLevel security_level, bool success);
     44 
     45   // Resets DRM credentials for a particular |security_level|. Returns false if
     46   // we fail to create the MediaDrmBridge at all, in which case we cannot reset
     47   // the credentials. Otherwise, the result is returned asynchronously in
     48   // OnResetCredentialsCompleted() function.
     49   bool ResetCredentialsInternal(SecurityLevel security_level);
     50 
     51   // The MediaDrmBridge object used to perform the credential reset.
     52   scoped_ptr<media::MediaDrmBridge> media_drm_bridge_;
     53 
     54   // The callback provided by the caller.
     55   ResetCredentialsCB reset_credentials_cb_;
     56 
     57   DISALLOW_COPY_AND_ASSIGN(MediaDrmCredentialManager);
     58 };
     59 
     60 }  // namespace content
     61 
     62 #endif  // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_DRM_CREDENTIAL_MANAGER_H_
     63