cdm_host_files.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2016 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. #ifndef MEDIA_CDM_CDM_HOST_FILES_H_
  5. #define MEDIA_CDM_CDM_HOST_FILES_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/files/file.h"
  9. #include "base/files/file_path.h"
  10. #include "base/lazy_instance.h"
  11. #include "base/memory/ptr_util.h"
  12. #include "base/native_library.h"
  13. #include "base/path_service.h"
  14. #include "build/build_config.h"
  15. #include "media/base/media_export.h"
  16. #include "media/cdm/api/content_decryption_module_ext.h"
  17. #include "media/cdm/cdm_host_file.h"
  18. #include "media/cdm/cdm_paths.h"
  19. namespace base {
  20. class FilePath;
  21. }
  22. namespace media {
  23. // Manages all CDM host files.
  24. class MEDIA_EXPORT CdmHostFiles {
  25. public:
  26. CdmHostFiles();
  27. CdmHostFiles(const CdmHostFiles&) = delete;
  28. CdmHostFiles& operator=(const CdmHostFiles&) = delete;
  29. ~CdmHostFiles();
  30. // Opens all common files and CDM specific files for the CDM at |cdm_path|.
  31. void Initialize(const base::FilePath& cdm_path,
  32. const std::vector<CdmHostFilePath>& cdm_host_file_paths);
  33. // Status of CDM host verification.
  34. // Note: Reported to UMA. Do not change the values.
  35. enum class Status {
  36. kNotCalled = 0,
  37. kSuccess = 1,
  38. kCdmLoadFailed = 2,
  39. kGetFunctionFailed = 3,
  40. kInitVerificationFailed = 4,
  41. kStatusCount
  42. };
  43. // Initializes the verification of CDM files by calling the function exported
  44. // by the CDM. If unexpected error happens, all files will be closed.
  45. // Otherwise, the PlatformFiles are passed to the CDM which will close the
  46. // files later.
  47. // NOTE: Initialize() must be called before calling this.
  48. Status InitVerification(base::NativeLibrary cdm_library);
  49. void CloseAllFiles();
  50. private:
  51. // Opens common CDM host files shared by all CDMs.
  52. void OpenCommonFiles(const std::vector<CdmHostFilePath>& cdm_host_file_paths);
  53. // Opens the CDM file.
  54. void OpenCdmFile(const base::FilePath& cdm_path);
  55. // Fills |cdm_host_files| with common and CDM specific files. The ownership
  56. // of those files are also transferred.
  57. void TakePlatformFiles(std::vector<cdm::HostFile>* cdm_host_files);
  58. using ScopedFileVector = std::vector<std::unique_ptr<CdmHostFile>>;
  59. // Files common to all CDM types, e.g. main executable.
  60. ScopedFileVector common_files_;
  61. // Files specific to each CDM type, e.g. the CDM binary.
  62. ScopedFileVector cdm_specific_files_;
  63. };
  64. } // namespace media
  65. #endif // MEDIA_CDM_CDM_HOST_FILES_H_