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::kIgnoreMissingCdmHostFile); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 // static |
| 28 std::unique_ptr<CdmHostFile> CdmHostFile::Create( |
| 29 const base::FilePath& file_path, |
| 30 const base::FilePath& sig_file_path) { |
| 31 // Open file at |file_path|. |
| 32 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 33 if (!file.IsValid()) { |
| 34 DVLOG(1) << "Failed to open file at " << file_path.MaybeAsASCII(); |
| 35 return nullptr; |
| 36 } |
| 37 |
| 38 // Also open the sig file at |sig_file_path|. |
| 39 base::File sig_file(sig_file_path, |
| 40 base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 41 if (!sig_file.IsValid()) { |
| 42 DVLOG(1) << "Failed to open sig file at " << sig_file_path.MaybeAsASCII(); |
| 43 if (!IgnoreMissingCdmHostFile()) |
| 44 return nullptr; |
| 45 |
| 46 DVLOG(1) << "Ignoring sig file failure at " << sig_file_path.MaybeAsASCII(); |
| 47 } |
| 48 |
| 49 return std::unique_ptr<CdmHostFile>( |
| 50 new CdmHostFile(file_path, std::move(file), std::move(sig_file))); |
| 51 } |
| 52 |
| 53 cdm::HostFile CdmHostFile::TakePlatformFile() { |
| 54 return cdm::HostFile(file_path_.value().c_str(), file_.TakePlatformFile(), |
| 55 sig_file_.TakePlatformFile()); |
| 56 } |
| 57 |
| 58 CdmHostFile::CdmHostFile(const base::FilePath& file_path, |
| 59 base::File file, |
| 60 base::File sig_file) |
| 61 : file_path_(file_path), |
| 62 file_(std::move(file)), |
| 63 sig_file_(std::move(sig_file)) { |
| 64 DVLOG(1) << __func__ << ": " << file_path_.value(); |
| 65 DCHECK(!file_path_.empty()) << "File path is empty."; |
| 66 DCHECK(file_.IsValid()) << "Invalid file."; |
| 67 |
| 68 if (!IgnoreMissingCdmHostFile()) |
| 69 DCHECK(sig_file_.IsValid()) << "Invalid signature file."; |
| 70 } |
| 71 |
| 72 } // namespace content |
OLD | NEW |