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

Side by Side Diff: chrome/common/media/cdm_host_file_path.cc

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
OLDNEW
(Empty)
1 // Copyright 2017 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 "chrome/common/media/cdm_host_file_path.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/path_service.h"
13 #include "build/build_config.h"
14 #include "chrome/common/chrome_version.h"
15
16 #if defined(OS_MACOSX)
17 #include "base/mac/bundle_locations.h"
18 #include "chrome/common/chrome_constants.h"
19 #endif
20
21 namespace chrome {
22
23 namespace {
24
25 using content::CdmHostFilePath;
26
27 // TODO(xhwang): Move this to a common place if needed.
28 const base::FilePath::CharType kSignatureFileExtension[] =
29 FILE_PATH_LITERAL(".sig");
30
31 // Returns the signature file path given the |file_path|. This function should
32 // only be used when the signature file and the file are located in the same
33 // directory.
34 base::FilePath GetSigFilePath(const base::FilePath& file_path) {
35 return file_path.AddExtension(kSignatureFileExtension);
36 }
37
38 #if defined(OS_WIN)
39
40 void AddCdmHostFilePathsWin(std::vector<CdmHostFilePath>* cdm_host_file_paths) {
41 static const base::FilePath::CharType* const kUnversionedFiles[] = {
42 FILE_PATH_LITERAL("chrome.exe")};
43 static const base::FilePath::CharType* const kVersionedFiles[] = {
44 FILE_PATH_LITERAL("chrome.dll"), FILE_PATH_LITERAL("chrome_child.dll")};
45
46 // Find where chrome.exe is installed.
47 base::FilePath chrome_exe_dir;
48 if (!PathService::Get(base::DIR_EXE, &chrome_exe_dir))
49 NOTREACHED();
50
51 cdm_host_file_paths->reserve(arraysize(kUnversionedFiles) +
52 arraysize(kVersionedFiles));
53
54 for (size_t i = 0; i < arraysize(kUnversionedFiles); ++i) {
55 base::FilePath file_path = chrome_exe_dir.Append(kUnversionedFiles[i]);
56 DVLOG(2) << __func__ << ": unversioned file " << i << " at "
57 << file_path.value();
58 cdm_host_file_paths->push_back(
59 CdmHostFilePath(file_path, GetSigFilePath(file_path)));
60 }
61
62 base::FilePath version_dir(chrome_exe_dir.AppendASCII(CHROME_VERSION_STRING));
63 for (size_t i = 0; i < arraysize(kVersionedFiles); ++i) {
64 base::FilePath file_path = version_dir.Append(kVersionedFiles[i]);
65 DVLOG(2) << __func__ << ": versioned file " << i << " at "
66 << file_path.value();
67 cdm_host_file_paths->push_back(
68 CdmHostFilePath(file_path, GetSigFilePath(file_path)));
69 }
70 }
71
72 #elif defined(OS_MACOSX)
73
74 void AddCdmHostFilePathsMac(std::vector<CdmHostFilePath>* cdm_host_file_paths) {
75 base::FilePath chrome_framework_path =
76 base::mac::FrameworkBundlePath().Append(chrome::kFrameworkExecutableName);
77
78 DVLOG(2) << __func__
79 << ": chrome_framework_path=" << chrome_framework_path.value();
80 cdm_host_file_paths->push_back(CdmHostFilePath(
81 chrome_framework_path, GetSigFilePath(chrome_framework_path)));
82 }
83
84 #elif defined(OS_LINUX)
85
86 void AddCdmHostFilePathsLinux(
87 std::vector<CdmHostFilePath>* cdm_host_file_paths) {
88 base::FilePath chrome_exe_dir;
89 if (!PathService::Get(base::DIR_EXE, &chrome_exe_dir))
90 NOTREACHED();
91
92 base::FilePath chrome_path =
93 chrome_exe_dir.Append(FILE_PATH_LITERAL("chrome"));
94 DVLOG(2) << __func__ << ": chrome_path=" << chrome_path.value();
95 cdm_host_file_paths->push_back(
96 CdmHostFilePath(chrome_path, GetSigFilePath(chrome_path)));
97 }
98
99 #endif // defined(OS_WIN)
100
101 } // namespace
102
103 void AddCdmHostFilePaths(
104 std::vector<content::CdmHostFilePath>* cdm_host_file_paths) {
105 DVLOG(1) << __func__;
106 DCHECK(cdm_host_file_paths);
107 DCHECK(cdm_host_file_paths->empty());
108
109 #if defined(OS_WIN)
110 AddCdmHostFilePathsWin(cdm_host_file_paths);
jam 2017/01/24 00:39:24 nit: name the method the same on all platforms and
xhwang 2017/01/24 01:14:19 Done.
111 #elif defined(OS_MACOSX)
112 AddCdmHostFilePathsMac(cdm_host_file_paths);
113 #elif defined(OS_LINUX)
114 AddCdmHostFilePathsLinux(cdm_host_file_paths);
115 #endif // defined(OS_WIN)
116 }
117
118 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698