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

Side by Side Diff: content/common/media/cdm_host_file.cc

Issue 2773283002: media: Simplify CdmHostFile(s) (Closed)
Patch Set: comments addressed Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/media/cdm_host_file.h" 5 #include "content/common/media/cdm_host_file.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.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" 13 #include "media/cdm/api/content_decryption_module_ext.h"
15 14
16 namespace content { 15 namespace content {
17 16
18 namespace {
19
20 bool IgnoreMissingCdmHostFile() {
21 return base::CommandLine::ForCurrentProcess()->HasSwitch(
22 switches::kIgnoreMissingCdmHostFile);
23 }
24
25 } // namespace
26
27 // static 17 // static
28 std::unique_ptr<CdmHostFile> CdmHostFile::Create( 18 std::unique_ptr<CdmHostFile> CdmHostFile::Create(
29 const base::FilePath& file_path, 19 const base::FilePath& file_path,
30 const base::FilePath& sig_file_path) { 20 const base::FilePath& sig_file_path) {
21 DVLOG(1) << __func__;
22
31 // Open file at |file_path|. 23 // Open file at |file_path|.
32 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 24 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
33 if (!file.IsValid()) { 25 DVLOG(1) << " " << file.IsValid() << ": " << file_path.MaybeAsASCII();
34 DVLOG(1) << "Failed to open file at " << file_path.MaybeAsASCII();
35 return nullptr;
36 }
37 26
38 // Also open the sig file at |sig_file_path|. 27 // Also open the sig file at |sig_file_path|.
39 base::File sig_file(sig_file_path, 28 base::File sig_file(sig_file_path,
40 base::File::FLAG_OPEN | base::File::FLAG_READ); 29 base::File::FLAG_OPEN | base::File::FLAG_READ);
41 if (!sig_file.IsValid()) { 30 DVLOG(1) << " " << sig_file.IsValid() << ": "
42 DVLOG(1) << "Failed to open sig file at " << sig_file_path.MaybeAsASCII(); 31 << 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 32
49 return std::unique_ptr<CdmHostFile>( 33 return std::unique_ptr<CdmHostFile>(
50 new CdmHostFile(file_path, std::move(file), std::move(sig_file))); 34 new CdmHostFile(file_path, std::move(file), std::move(sig_file)));
51 } 35 }
52 36
53 cdm::HostFile CdmHostFile::TakePlatformFile() { 37 cdm::HostFile CdmHostFile::TakePlatformFile() {
54 return cdm::HostFile(file_path_.value().c_str(), file_.TakePlatformFile(), 38 return cdm::HostFile(file_path_.value().c_str(), file_.TakePlatformFile(),
55 sig_file_.TakePlatformFile()); 39 sig_file_.TakePlatformFile());
56 } 40 }
57 41
58 CdmHostFile::CdmHostFile(const base::FilePath& file_path, 42 CdmHostFile::CdmHostFile(const base::FilePath& file_path,
59 base::File file, 43 base::File file,
60 base::File sig_file) 44 base::File sig_file)
61 : file_path_(file_path), 45 : file_path_(file_path),
62 file_(std::move(file)), 46 file_(std::move(file)),
63 sig_file_(std::move(sig_file)) { 47 sig_file_(std::move(sig_file)) {
64 DVLOG(1) << __func__ << ": " << file_path_.value(); 48 DCHECK(!file_path_.empty());
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 } 49 }
71 50
72 } // namespace content 51 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/zygote_host/zygote_communication_linux.cc ('k') | content/common/media/cdm_host_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698