OLD | NEW |
(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 } // namespace |
| 39 |
| 40 void AddCdmHostFilePaths( |
| 41 std::vector<content::CdmHostFilePath>* cdm_host_file_paths) { |
| 42 DVLOG(1) << __func__; |
| 43 DCHECK(cdm_host_file_paths); |
| 44 DCHECK(cdm_host_file_paths->empty()); |
| 45 |
| 46 #if defined(OS_WIN) |
| 47 |
| 48 static const base::FilePath::CharType* const kUnversionedFiles[] = { |
| 49 FILE_PATH_LITERAL("chrome.exe")}; |
| 50 static const base::FilePath::CharType* const kVersionedFiles[] = { |
| 51 FILE_PATH_LITERAL("chrome.dll"), FILE_PATH_LITERAL("chrome_child.dll")}; |
| 52 |
| 53 // Find where chrome.exe is installed. |
| 54 base::FilePath chrome_exe_dir; |
| 55 if (!PathService::Get(base::DIR_EXE, &chrome_exe_dir)) |
| 56 NOTREACHED(); |
| 57 |
| 58 cdm_host_file_paths->reserve(arraysize(kUnversionedFiles) + |
| 59 arraysize(kVersionedFiles)); |
| 60 |
| 61 for (size_t i = 0; i < arraysize(kUnversionedFiles); ++i) { |
| 62 base::FilePath file_path = chrome_exe_dir.Append(kUnversionedFiles[i]); |
| 63 DVLOG(2) << __func__ << ": unversioned file " << i << " at " |
| 64 << file_path.value(); |
| 65 cdm_host_file_paths->push_back( |
| 66 CdmHostFilePath(file_path, GetSigFilePath(file_path))); |
| 67 } |
| 68 |
| 69 base::FilePath version_dir(chrome_exe_dir.AppendASCII(CHROME_VERSION_STRING)); |
| 70 for (size_t i = 0; i < arraysize(kVersionedFiles); ++i) { |
| 71 base::FilePath file_path = version_dir.Append(kVersionedFiles[i]); |
| 72 DVLOG(2) << __func__ << ": versioned file " << i << " at " |
| 73 << file_path.value(); |
| 74 cdm_host_file_paths->push_back( |
| 75 CdmHostFilePath(file_path, GetSigFilePath(file_path))); |
| 76 } |
| 77 |
| 78 #elif defined(OS_MACOSX) |
| 79 |
| 80 base::FilePath chrome_framework_path = |
| 81 base::mac::FrameworkBundlePath().Append(chrome::kFrameworkExecutableName); |
| 82 |
| 83 DVLOG(2) << __func__ |
| 84 << ": chrome_framework_path=" << chrome_framework_path.value(); |
| 85 cdm_host_file_paths->push_back(CdmHostFilePath( |
| 86 chrome_framework_path, GetSigFilePath(chrome_framework_path))); |
| 87 |
| 88 #elif defined(OS_LINUX) |
| 89 |
| 90 base::FilePath chrome_exe_dir; |
| 91 if (!PathService::Get(base::DIR_EXE, &chrome_exe_dir)) |
| 92 NOTREACHED(); |
| 93 |
| 94 base::FilePath chrome_path = |
| 95 chrome_exe_dir.Append(FILE_PATH_LITERAL("chrome")); |
| 96 DVLOG(2) << __func__ << ": chrome_path=" << chrome_path.value(); |
| 97 cdm_host_file_paths->push_back( |
| 98 CdmHostFilePath(chrome_path, GetSigFilePath(chrome_path))); |
| 99 |
| 100 #endif // defined(OS_WIN) |
| 101 } |
| 102 |
| 103 } // namespace chrome |
OLD | NEW |