Create constants for common SODA file paths
This CL defines Speech On-Device API (SODA)-related file path constants in //components/soda that will be used by the component updater in //chrome/browser/component_updater, the SODA sandbox hook in //content/utility, and the SODA service in //chrome/services. Bug: 1039824 Change-Id: Ic96c7eb5ec6d458beb4f0bf90982bf4dccc6dc45 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015483 Reviewed-by: Scott Violet <sky@chromium.org> Commit-Queue: Evan Liu <evliu@google.com> Cr-Commit-Position: refs/heads/master@{#735085}
This commit is contained in:
chrome/browser
components/soda
content/utility/soda
@ -2108,6 +2108,7 @@ jumbo_static_library("browser") {
|
||||
"//components/signin/public/base:signin_buildflags",
|
||||
"//components/signin/public/identity_manager",
|
||||
"//components/signin/public/webdata",
|
||||
"//components/soda:constants",
|
||||
"//components/spellcheck:buildflags",
|
||||
"//components/sqlite_proto",
|
||||
"//components/ssl_errors",
|
||||
|
@ -1,5 +1,6 @@
|
||||
include_rules = [
|
||||
"+chrome/elevation_service",
|
||||
"+components/soda",
|
||||
"+media/cdm/cdm_proxy.h",
|
||||
"+media/cdm/supported_cdm_versions.h",
|
||||
"+ppapi/thunk",
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/component_updater/component_updater_service.h"
|
||||
#include "components/crx_file/id_util.h"
|
||||
#include "components/soda/constants.h"
|
||||
#include "components/update_client/update_client_errors.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "crypto/sha2.h"
|
||||
@ -28,9 +29,6 @@ const uint8_t kSODAPublicKeySHA256[32] = {
|
||||
0x8e, 0xd0, 0x0c, 0xef, 0xa5, 0xc0, 0x97, 0x00, 0x84, 0x1c, 0x21,
|
||||
0xa6, 0xae, 0xc8, 0x1b, 0x87, 0xfb, 0x12, 0x27, 0x28, 0xb1};
|
||||
|
||||
const base::FilePath::CharType kSODABinaryFileName[] =
|
||||
FILE_PATH_LITERAL("SODAFiles/libsoda.so");
|
||||
|
||||
static_assert(base::size(kSODAPublicKeySHA256) == crypto::kSHA256Length,
|
||||
"Wrong hash length");
|
||||
|
||||
@ -66,7 +64,7 @@ void SODAComponentInstallerPolicy::UpdateSODAComponentOnDemand() {
|
||||
bool SODAComponentInstallerPolicy::VerifyInstallation(
|
||||
const base::DictionaryValue& manifest,
|
||||
const base::FilePath& install_dir) const {
|
||||
return base::PathExists(install_dir.Append(kSODABinaryFileName));
|
||||
return base::PathExists(install_dir.Append(soda::kSodaBinaryRelativePath));
|
||||
}
|
||||
|
||||
bool SODAComponentInstallerPolicy::SupportsGroupPolicyEnabledComponentUpdates()
|
||||
@ -98,7 +96,7 @@ void SODAComponentInstallerPolicy::ComponentReady(
|
||||
}
|
||||
|
||||
base::FilePath SODAComponentInstallerPolicy::GetRelativeInstallDir() const {
|
||||
return base::FilePath(FILE_PATH_LITERAL("SODA"));
|
||||
return base::FilePath(soda::kSodaInstallationRelativePath);
|
||||
}
|
||||
|
||||
void SODAComponentInstallerPolicy::GetHash(std::vector<uint8_t>* hash) const {
|
||||
@ -121,7 +119,8 @@ std::vector<std::string> SODAComponentInstallerPolicy::GetMimeTypes() const {
|
||||
|
||||
void UpdateSODAInstallDirPref(PrefService* prefs,
|
||||
const base::FilePath& install_dir) {
|
||||
prefs->SetFilePath(prefs::kSODAPath, install_dir.Append(kSODABinaryFileName));
|
||||
prefs->SetFilePath(prefs::kSODAPath,
|
||||
install_dir.Append(soda::kSodaBinaryRelativePath));
|
||||
}
|
||||
|
||||
void RegisterSODAComponent(ComponentUpdateService* cus,
|
||||
|
15
components/soda/BUILD.gn
Normal file
15
components/soda/BUILD.gn
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
source_set("constants") {
|
||||
sources = [
|
||||
"constants.cc",
|
||||
"constants.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//components/component_updater",
|
||||
]
|
||||
}
|
3
components/soda/DEPS
Normal file
3
components/soda/DEPS
Normal file
@ -0,0 +1,3 @@
|
||||
include_rules = [
|
||||
"+components/component_updater/component_updater_paths.h",
|
||||
]
|
52
components/soda/constants.cc
Normal file
52
components/soda/constants.cc
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/soda/constants.h"
|
||||
|
||||
#include "base/files/file_enumerator.h"
|
||||
#include "base/path_service.h"
|
||||
#include "components/component_updater/component_updater_paths.h"
|
||||
|
||||
namespace soda {
|
||||
|
||||
constexpr base::FilePath::CharType kSodaInstallationRelativePath[] =
|
||||
FILE_PATH_LITERAL("SODA");
|
||||
|
||||
constexpr base::FilePath::CharType kSodaBinaryRelativePath[] =
|
||||
FILE_PATH_LITERAL("SODAFiles/libsoda.so");
|
||||
|
||||
constexpr base::FilePath::CharType kSodaConfigFileRelativePath[] =
|
||||
FILE_PATH_LITERAL("SODAFiles/en_us/dictation.ascii_proto");
|
||||
|
||||
const base::FilePath GetSodaDirectory() {
|
||||
base::FilePath components_dir;
|
||||
base::PathService::Get(component_updater::DIR_COMPONENT_USER,
|
||||
&components_dir);
|
||||
|
||||
base::FileEnumerator enumerator(
|
||||
components_dir.Append(kSodaInstallationRelativePath), false,
|
||||
base::FileEnumerator::DIRECTORIES);
|
||||
base::FilePath latest_version_dir;
|
||||
for (base::FilePath version_dir = enumerator.Next(); !version_dir.empty();
|
||||
version_dir = enumerator.Next()) {
|
||||
latest_version_dir =
|
||||
latest_version_dir < version_dir ? version_dir : latest_version_dir;
|
||||
}
|
||||
|
||||
return latest_version_dir;
|
||||
}
|
||||
|
||||
const base::FilePath GetSodaBinaryPath() {
|
||||
base::FilePath soda_dir = GetSodaDirectory();
|
||||
return soda_dir.empty() ? soda_dir : soda_dir.Append(kSodaBinaryRelativePath);
|
||||
}
|
||||
|
||||
const base::FilePath GetSodaConfigPath() {
|
||||
base::FilePath soda_dir = GetSodaDirectory();
|
||||
return soda_dir.empty() ? soda_dir
|
||||
: soda_dir.Append(kSodaConfigFileRelativePath);
|
||||
}
|
||||
|
||||
} // namespace soda
|
39
components/soda/constants.h
Normal file
39
components/soda/constants.h
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_SODA_CONSTANTS_H_
|
||||
#define COMPONENTS_SODA_CONSTANTS_H_
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
|
||||
namespace soda {
|
||||
|
||||
// Location of the SODA component relative to components directory.
|
||||
extern const base::FilePath::CharType kSodaInstallationRelativePath[];
|
||||
|
||||
// Location of the libsoda binary within the SODA installation directory.
|
||||
extern const base::FilePath::CharType kSodaBinaryRelativePath[];
|
||||
|
||||
// Location of the en_us SODA config file within the SODA installation
|
||||
// directory. Note: SODA is currently only available in English.
|
||||
extern const base::FilePath::CharType kSodaConfigFileRelativePath[];
|
||||
|
||||
// Get the directory containing the latest version of SODA. In most cases
|
||||
// there will only be one version of SODA, but it is possible for there to be
|
||||
// multiple versions if a newer version of SODA was recently downloaded before
|
||||
// the old version gets cleaned up. Returns an empty path if SODA is not
|
||||
// installed.
|
||||
const base::FilePath GetSodaDirectory();
|
||||
|
||||
// Get the path to the SODA binary. Returns an empty path if SODA is not
|
||||
// installed.
|
||||
const base::FilePath GetSodaBinaryPath();
|
||||
|
||||
// Get the path to the dictation.ascii_proto config file used by SODA. Returns
|
||||
// an empty path if SODA is not installed.
|
||||
const base::FilePath GetSodaConfigPath();
|
||||
|
||||
} // namespace soda
|
||||
|
||||
#endif // COMPONENTS_SODA_CONSTANTS_H_
|
@ -11,6 +11,7 @@ source_set("soda_sandbox_hook") {
|
||||
deps = [
|
||||
"//base",
|
||||
"//components/component_updater:component_updater",
|
||||
"//components/soda:constants",
|
||||
"//sandbox/linux:sandbox_services",
|
||||
]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
include_rules = [
|
||||
"+components/component_updater/component_updater_paths.h",
|
||||
"+components/soda",
|
||||
"+sandbox",
|
||||
"+services/service_manager/sandbox",
|
||||
]
|
||||
|
@ -6,10 +6,7 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "base/files/file_enumerator.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/path_service.h"
|
||||
#include "components/component_updater/component_updater_paths.h"
|
||||
#include "components/soda/constants.h"
|
||||
#include "sandbox/linux/syscall_broker/broker_command.h"
|
||||
#include "sandbox/linux/syscall_broker/broker_file_permission.h"
|
||||
|
||||
@ -20,10 +17,6 @@ namespace soda {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr base::FilePath::CharType kSodaDirName[] = FILE_PATH_LITERAL("SODA/");
|
||||
constexpr base::FilePath::CharType kSodaBinaryFileName[] =
|
||||
FILE_PATH_LITERAL("SODAFiles/libsoda.so");
|
||||
|
||||
std::vector<BrokerFilePermission> GetSodaFilePermissions(
|
||||
base::FilePath latest_version_dir) {
|
||||
std::vector<BrokerFilePermission> permissions{
|
||||
@ -37,29 +30,8 @@ std::vector<BrokerFilePermission> GetSodaFilePermissions(
|
||||
} // namespace
|
||||
|
||||
bool SodaPreSandboxHook(service_manager::SandboxLinux::Options options) {
|
||||
base::FilePath components_dir;
|
||||
base::PathService::Get(component_updater::DIR_COMPONENT_USER,
|
||||
&components_dir);
|
||||
|
||||
// Get the directory containing the latest version of SODA. In most cases
|
||||
// there will only be one version of SODA, but it is possible for there to be
|
||||
// multiple versions if a newer version of SODA was recently downloaded before
|
||||
// the old version gets cleaned up.
|
||||
base::FileEnumerator enumerator(components_dir.Append(kSodaDirName), false,
|
||||
base::FileEnumerator::DIRECTORIES);
|
||||
base::FilePath latest_version_dir;
|
||||
for (base::FilePath version_dir = enumerator.Next(); !version_dir.empty();
|
||||
version_dir = enumerator.Next()) {
|
||||
latest_version_dir =
|
||||
latest_version_dir < version_dir ? version_dir : latest_version_dir;
|
||||
}
|
||||
|
||||
void* soda_library =
|
||||
latest_version_dir.empty()
|
||||
? nullptr
|
||||
: dlopen(
|
||||
latest_version_dir.Append(kSodaBinaryFileName).value().c_str(),
|
||||
RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
|
||||
void* soda_library = dlopen(GetSodaBinaryPath().value().c_str(),
|
||||
RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
|
||||
DCHECK(soda_library);
|
||||
|
||||
auto* instance = service_manager::SandboxLinux::GetInstance();
|
||||
@ -69,7 +41,7 @@ bool SodaPreSandboxHook(service_manager::SandboxLinux::Options options) {
|
||||
sandbox::syscall_broker::COMMAND_READLINK,
|
||||
sandbox::syscall_broker::COMMAND_STAT,
|
||||
}),
|
||||
GetSodaFilePermissions(latest_version_dir),
|
||||
GetSodaFilePermissions(GetSodaDirectory()),
|
||||
service_manager::SandboxLinux::PreSandboxHook(),
|
||||
options);
|
||||
instance->EngageNamespaceSandboxIfPossible();
|
||||
|
Reference in New Issue
Block a user