1 // Copyright 2014 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 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/base/media_keys.h"
13 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
14 #include "mojo/public/cpp/bindings/interface_impl.h"
18 // A mojo::ContentDecryptionModule implementation backed by a media::MediaKeys.
20 : public mojo::InterfaceImpl
<mojo::ContentDecryptionModule
> {
22 MojoCdmService(const mojo::String
& key_system
);
23 ~MojoCdmService() final
;
25 // mojo::ContentDecryptionModule implementation.
26 void SetServerCertificate(
27 mojo::Array
<uint8_t> certificate_data
,
28 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
)>& callback
) final
;
29 void CreateSessionAndGenerateRequest(
30 mojo::ContentDecryptionModule::SessionType session_type
,
31 const mojo::String
& init_data_type
,
32 mojo::Array
<uint8_t> init_data
,
33 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
, mojo::String
)>&
35 void LoadSession(mojo::ContentDecryptionModule::SessionType session_type
,
36 const mojo::String
& session_id
,
37 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
,
38 mojo::String
)>& callback
) final
;
40 const mojo::String
& session_id
,
41 mojo::Array
<uint8_t> response
,
42 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
)>& callback
) final
;
44 const mojo::String
& session_id
,
45 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
)>& callback
) final
;
47 const mojo::String
& session_id
,
48 const mojo::Callback
<void(mojo::CdmPromiseResultPtr
)>& callback
) final
;
49 void GetCdmContext(int32_t cdm_id
,
50 mojo::InterfaceRequest
<mojo::Decryptor
> decryptor
) final
;
53 // Callbacks for firing session events.
54 void OnSessionMessage(const std::string
& session_id
,
55 MediaKeys::MessageType message_type
,
56 const std::vector
<uint8_t>& message
,
57 const GURL
& legacy_destination_url
);
58 void OnSessionKeysChange(const std::string
& session_id
,
59 bool has_additional_usable_key
,
60 CdmKeysInfo keys_info
);
61 void OnSessionExpirationUpdate(const std::string
& session_id
,
62 const base::Time
& new_expiry_time
);
63 void OnSessionClosed(const std::string
& session_id
);
64 void OnSessionError(const std::string
& session_id
,
65 MediaKeys::Exception exception
,
67 const std::string
& error_message
);
69 scoped_ptr
<MediaKeys
> cdm_
;
71 base::WeakPtrFactory
<MojoCdmService
> weak_factory_
;
72 base::WeakPtr
<MojoCdmService
> weak_this_
;
74 DISALLOW_COPY_AND_ASSIGN(MojoCdmService
);
79 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_H_