OLD | NEW |
---|---|
(Empty) | |
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 | |
5 #ifndef CONTENT_COMMON_MEDIA_CDM_HOST_FILES_H_ | |
6 #define CONTENT_COMMON_MEDIA_CDM_HOST_FILES_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <vector> | |
11 | |
12 #include "base/files/file.h" | |
13 #include "base/files/file_path.h" | |
14 #include "base/lazy_instance.h" | |
15 #include "base/logging.h" | |
16 #include "base/memory/ptr_util.h" | |
17 #include "base/native_library.h" | |
18 #include "base/path_service.h" | |
19 #include "build/build_config.h" | |
20 #include "content/common/media/cdm_host_file.h" | |
21 #include "content/common/pepper_plugin_list.h" | |
22 #include "content/public/common/pepper_plugin_info.h" | |
23 #include "media/cdm/api/content_decryption_module_ext.h" | |
24 #include "media/cdm/cdm_paths.h" | |
25 | |
26 // On systems that use the zygote process to spawn child processes, we must | |
27 // open files in the zygote process. | |
28 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MACOSX) && \ | |
29 !defined(OS_ANDROID) | |
30 #define POSIX_WITH_ZYGOTE 1 | |
31 #endif | |
32 | |
33 namespace base { | |
34 class FilePath; | |
35 } | |
36 | |
37 namespace content { | |
38 | |
39 // Manages all CDM host files. | |
40 class CdmHostFiles { | |
41 public: | |
42 CdmHostFiles(); | |
43 ~CdmHostFiles(); | |
44 | |
45 #if defined(POSIX_WITH_ZYGOTE) | |
46 // Opens CDM host files for all registered CDMs and set the global | |
47 // CdmHostFiles instance. On any failure, the global instance will not be | |
48 // set and no file will be left open. | |
49 static void CreateGlobalInstance(); | |
50 | |
51 // Takes and returns the global CdmHostFiles instance. The return value could | |
52 // be nullptr if CreateGlobalInstance() failed. | |
53 static std::unique_ptr<CdmHostFiles> TakeGlobalInstance(); | |
54 #endif | |
55 | |
56 // Opens CDM host files for the CDM adapter at |cdm_adapter_path| and returns | |
57 // the created CdmHostFiles instance. Returns nullptr if any of the files | |
58 // cannot be opened, in which case no file will be left open. | |
59 static std::unique_ptr<CdmHostFiles> Create( | |
60 const base::FilePath& cdm_adapter_path); | |
61 | |
62 // Verifies |cdm_adapter_path| CDM files by calling VerifyHostFiles() exported | |
tinskip1
2017/01/19 03:42:47
Again, perhaps VerifyHost?
xhwang
2017/01/19 08:30:51
ditto
| |
63 // by the CDM. If unexpected error happens, all files will be closed. | |
64 // Otherwise, the PlatformFiles are passed to the CDM which will close the | |
65 // files later. | |
66 void VerifyFiles(base::NativeLibrary cdm_adapter_library, | |
67 const base::FilePath& cdm_adapter_path); | |
68 | |
69 private: | |
70 #if defined(POSIX_WITH_ZYGOTE) | |
71 // Opens all common files and CDM specific files for all registered CDMs. | |
72 bool OpenFilesForAllRegisteredCdms(); | |
73 #endif | |
74 | |
75 // Opens all common files and CDM specific files for the CDM adapter | |
76 // registered at |cdm_adapter_path|. | |
77 bool OpenFiles(const base::FilePath& cdm_adapter_path); | |
78 | |
79 // Opens common CDM host files shared by all CDMs. Upon failure, close all | |
80 // files opened. | |
81 bool OpenCommonFiles(); | |
82 | |
83 // Opens CDM specific files for the CDM adapter registered at | |
84 // |cdm_adapter_path|. Returns whether all CDM specific files are opened. | |
85 // Upon failure, close all files opened. | |
86 bool OpenCdmFiles(const base::FilePath& cdm_adapter_path); | |
87 | |
88 // Fills |cdm_host_files| with common and CDM specific files for | |
89 // |cdm_adapter_path|. The ownership of those files are also transferred. | |
90 // Returns true upon success where the remaining files will be closed. | |
91 // Returns false upon any failure and all files will be closed. | |
92 bool TakePlatformFiles(const base::FilePath& cdm_adapter_path, | |
93 std::vector<cdm::HostFile>* cdm_host_files); | |
94 | |
95 void CloseAllFiles(); | |
96 | |
97 using ScopedFileVector = std::vector<std::unique_ptr<CdmHostFile>>; | |
98 ScopedFileVector common_files_; | |
99 std::map<base::FilePath, ScopedFileVector> cdm_specific_files_map_; | |
100 }; | |
101 | |
102 // Returns whether the |cdm_adapter_path| corresponds to a known CDM. | |
103 bool IsCdm(const base::FilePath& cdm_adapter_path); | |
104 | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_COMMON_MEDIA_CDM_HOST_FILES_H_ | |
OLD | NEW |