Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: content/common/media/cdm_host_files.h

Issue 2582463003: media: Verify CDM Host files (Closed)
Patch Set: comments addressed Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/media/cdm_host_file.cc ('k') | content/common/media/cdm_host_files.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 the function exported
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 // Only returns false if the CDM returns false (when there's an immediate
67 // failure). Otherwise always returns true for backward compatibility, e.g.
68 // when using an old CDM which doesn't implement the verification API.
69 bool VerifyFiles(base::NativeLibrary cdm_adapter_library,
70 const base::FilePath& cdm_adapter_path);
71
72 private:
73 #if defined(POSIX_WITH_ZYGOTE)
74 // Opens all common files and CDM specific files for all registered CDMs.
75 bool OpenFilesForAllRegisteredCdms();
76 #endif
77
78 // Opens all common files and CDM specific files for the CDM adapter
79 // registered at |cdm_adapter_path|.
80 bool OpenFiles(const base::FilePath& cdm_adapter_path);
81
82 // Opens common CDM host files shared by all CDMs. Upon failure, close all
83 // files opened.
84 bool OpenCommonFiles();
85
86 // Opens CDM specific files for the CDM adapter registered at
87 // |cdm_adapter_path|. Returns whether all CDM specific files are opened.
88 // Upon failure, close all files opened.
89 bool OpenCdmFiles(const base::FilePath& cdm_adapter_path);
90
91 // Fills |cdm_host_files| with common and CDM specific files for
92 // |cdm_adapter_path|. The ownership of those files are also transferred.
93 // Returns true upon success where the remaining files will be closed.
94 // Returns false upon any failure and all files will be closed.
95 bool TakePlatformFiles(const base::FilePath& cdm_adapter_path,
96 std::vector<cdm::HostFile>* cdm_host_files);
97
98 void CloseAllFiles();
99
100 using ScopedFileVector = std::vector<std::unique_ptr<CdmHostFile>>;
101 ScopedFileVector common_files_;
102 std::map<base::FilePath, ScopedFileVector> cdm_specific_files_map_;
103 };
104
105 // Returns whether the |cdm_adapter_path| corresponds to a known CDM.
106 bool IsCdm(const base::FilePath& cdm_adapter_path);
107
108 } // namespace content
109
110 #endif // CONTENT_COMMON_MEDIA_CDM_HOST_FILES_H_
OLDNEW
« no previous file with comments | « content/common/media/cdm_host_file.cc ('k') | content/common/media/cdm_host_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698