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 #include "content/common/media/cdm_host_file.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/feature_list.h" | |
11 #include "base/logging.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "media/base/media_switches.h" | |
14 #include "media/cdm/api/content_decryption_module_ext.h" | |
15 | |
16 namespace content { | |
17 | |
18 namespace { | |
19 | |
20 bool IgnoreMissingCdmHostFile() { | |
21 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
22 switches::kIgnoreMissingCdmHostFileForTesting); | |
23 } | |
24 | |
25 } // namespace | |
26 | |
27 std::unique_ptr<CdmHostFile> CdmHostFile::Create( | |
alexmos
2017/01/24 00:40:14
nit: // static
xhwang
2017/01/24 01:14:19
Done.
| |
28 const base::FilePath& file_path, | |
29 const base::FilePath& sig_file_path) { | |
30 // Open file at |file_path|. | |
31 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
32 if (!file.IsValid()) { | |
33 DVLOG(1) << "Failed to open file at " << file_path.MaybeAsASCII(); | |
34 return nullptr; | |
35 } | |
36 | |
37 // Also open the sig file at |sig_file_path|. | |
38 base::File sig_file(sig_file_path, | |
39 base::File::FLAG_OPEN | base::File::FLAG_READ); | |
40 if (!sig_file.IsValid()) { | |
41 DVLOG(1) << "Failed to open sig file at " << sig_file_path.MaybeAsASCII(); | |
42 if (!IgnoreMissingCdmHostFile()) | |
43 return nullptr; | |
44 | |
45 DVLOG(1) << "Ignoring sig file failure at " << sig_file_path.MaybeAsASCII(); | |
46 } | |
47 | |
48 return std::unique_ptr<CdmHostFile>( | |
49 new CdmHostFile(file_path, std::move(file), std::move(sig_file))); | |
50 } | |
51 | |
52 cdm::HostFile CdmHostFile::TakePlatformFile() { | |
53 return cdm::HostFile(file_path_.value().c_str(), file_.TakePlatformFile(), | |
54 sig_file_.TakePlatformFile()); | |
55 } | |
56 | |
57 CdmHostFile::CdmHostFile(const base::FilePath& file_path, | |
58 base::File file, | |
59 base::File sig_file) | |
60 : file_path_(file_path), | |
61 file_(std::move(file)), | |
62 sig_file_(std::move(sig_file)) { | |
63 DVLOG(1) << __func__ << ": " << file_path_.value(); | |
64 DCHECK(!file_path_.empty()) << "File path is empty."; | |
65 DCHECK(file_.IsValid()) << "Invalid file."; | |
66 | |
67 if (!IgnoreMissingCdmHostFile()) | |
68 DCHECK(sig_file_.IsValid()) << "Invalid signature file."; | |
69 } | |
70 | |
71 } // namespace content | |
OLD | NEW |