cdm_host_file.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_FILE_H_
  5. #define MEDIA_CDM_CDM_HOST_FILE_H_
  6. #include <memory>
  7. #include "base/files/file.h"
  8. #include "base/files/file_path.h"
  9. #include "media/base/media_export.h"
  10. namespace cdm {
  11. struct HostFile;
  12. }
  13. namespace media {
  14. struct MEDIA_EXPORT CdmHostFilePath {
  15. CdmHostFilePath(const base::FilePath& file_path,
  16. const base::FilePath& sig_file_path);
  17. ~CdmHostFilePath();
  18. // Path to a file that takes part in hosting the CDM.
  19. base::FilePath file_path;
  20. // Path to a signature file of the file at |file_path|.
  21. base::FilePath sig_file_path;
  22. };
  23. // Represents a file that participated in hosting the CDM.
  24. class MEDIA_EXPORT CdmHostFile {
  25. public:
  26. // Opens the file at |file_path| and the corresponding signature file at
  27. // |sig_file_path|. Upon success, constructs and returns a CdmHostFile object.
  28. // Otherwise returns nullptr. The opened files are closed when |this| is
  29. // destructed unless TakePlatformFile() was called, in which case the caller
  30. // must make sure the files are closed properly.
  31. static std::unique_ptr<CdmHostFile> Create(
  32. const base::FilePath& file_path,
  33. const base::FilePath& sig_file_path);
  34. CdmHostFile(const CdmHostFile&) = delete;
  35. CdmHostFile& operator=(const CdmHostFile&) = delete;
  36. // Takes the PlatformFile of the |file_| and |sig_file_| and put them in the
  37. // returned cdm::HostFile. The caller must make sure the PlatformFiles are
  38. // properly closed after use.
  39. cdm::HostFile TakePlatformFile();
  40. private:
  41. CdmHostFile(const base::FilePath& file_path,
  42. base::File file,
  43. base::File sig_file);
  44. base::FilePath file_path_;
  45. base::File file_;
  46. // The signature file associated with |file_|.
  47. base::File sig_file_;
  48. };
  49. } // namespace media
  50. #endif // MEDIA_CDM_CDM_HOST_FILE_H_