forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This CL splits the SODA component into a single SODA binary component and multiple language pack components. Todo: Update the settings UI reflect the download progress of the SODA binary and the language pack(s). Todo: Verify that the SODA binary component and the language pack component is installed before launching the Live caption feature. Change-Id: Ia82ac3b46da2d37ce1e0fae9d6cd7fb541d67d60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340873 Reviewed-by: Joshua Pawlicki <waffles@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org> Commit-Queue: Evan Liu <evliu@google.com> Cr-Commit-Position: refs/heads/master@{#800723}
- Loading branch information
1 parent
87071b6
commit 5826f33
Showing
23 changed files
with
739 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include_rules = [ | ||
"+components/soda", | ||
"+services/image_annotation", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
chrome/browser/component_updater/soda_en_us_component_installer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// 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 "chrome/browser/component_updater/soda_en_us_component_installer.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/files/file_util.h" | ||
#include "build/build_config.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "chrome/services/speech/buildflags.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 "content/public/browser/browser_thread.h" | ||
#include "crypto/sha2.h" | ||
|
||
using content::BrowserThread; | ||
|
||
namespace component_updater { | ||
|
||
namespace { | ||
|
||
// The SHA256 of the SubjectPublicKeyInfo used to sign the component. | ||
// The component id is: oegebmmcimckjhkhbggblnkjloogjdfg | ||
const uint8_t kSodaEnUsPublicKeySHA256[32] = { | ||
0xe4, 0x64, 0x1c, 0xc2, 0x8c, 0x2a, 0x97, 0xa7, 0x16, 0x61, 0xbd, | ||
0xa9, 0xbe, 0xe6, 0x93, 0x56, 0xf5, 0x05, 0x33, 0x9b, 0x8b, 0x0b, | ||
0x02, 0xe2, 0x6b, 0x7e, 0x6c, 0x40, 0xa1, 0xd2, 0x7e, 0x18}; | ||
|
||
static_assert(base::size(kSodaEnUsPublicKeySHA256) == crypto::kSHA256Length, | ||
"Wrong hash length"); | ||
|
||
const char kSodaEnUsManifestName[] = "SODA en-US Models"; | ||
|
||
constexpr base::FilePath::CharType kSodaEnUsConfigFileRelativePath[] = | ||
FILE_PATH_LITERAL("SODAModels/dictation.ascii_proto"); | ||
|
||
} // namespace | ||
|
||
SodaEnUsComponentInstallerPolicy::SodaEnUsComponentInstallerPolicy( | ||
OnSodaEnUsComponentReadyCallback callback) | ||
: on_component_ready_callback_(callback) {} | ||
|
||
SodaEnUsComponentInstallerPolicy::~SodaEnUsComponentInstallerPolicy() = default; | ||
|
||
const std::string SodaEnUsComponentInstallerPolicy::GetExtensionId() { | ||
return crx_file::id_util::GenerateIdFromHash( | ||
kSodaEnUsPublicKeySHA256, sizeof(kSodaEnUsPublicKeySHA256)); | ||
} | ||
|
||
void SodaEnUsComponentInstallerPolicy::UpdateSodaEnUsComponentOnDemand() { | ||
const std::string crx_id = | ||
component_updater::SodaEnUsComponentInstallerPolicy::GetExtensionId(); | ||
g_browser_process->component_updater()->GetOnDemandUpdater().OnDemandUpdate( | ||
crx_id, component_updater::OnDemandUpdater::Priority::FOREGROUND, | ||
base::BindOnce([](update_client::Error error) { | ||
if (error != update_client::Error::NONE && | ||
error != update_client::Error::UPDATE_IN_PROGRESS) | ||
LOG(ERROR) << "On demand update of the SODA en-US component failed " | ||
"with error: " | ||
<< static_cast<int>(error); | ||
})); | ||
} | ||
|
||
bool SodaEnUsComponentInstallerPolicy::VerifyInstallation( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) const { | ||
return base::PathExists(install_dir.Append(kSodaEnUsConfigFileRelativePath)); | ||
} | ||
|
||
bool SodaEnUsComponentInstallerPolicy:: | ||
SupportsGroupPolicyEnabledComponentUpdates() const { | ||
return true; | ||
} | ||
|
||
bool SodaEnUsComponentInstallerPolicy::RequiresNetworkEncryption() const { | ||
return true; | ||
} | ||
|
||
update_client::CrxInstaller::Result | ||
SodaEnUsComponentInstallerPolicy::OnCustomInstall( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) { | ||
return update_client::CrxInstaller::Result(0); // Nothing custom here. | ||
} | ||
|
||
void SodaEnUsComponentInstallerPolicy::OnCustomUninstall() {} | ||
|
||
void SodaEnUsComponentInstallerPolicy::ComponentReady( | ||
const base::Version& version, | ||
const base::FilePath& install_dir, | ||
std::unique_ptr<base::DictionaryValue> manifest) { | ||
VLOG(1) << "Component ready, version " << version.GetString() << " in " | ||
<< install_dir.value(); | ||
|
||
on_component_ready_callback_.Run(install_dir); | ||
} | ||
|
||
base::FilePath SodaEnUsComponentInstallerPolicy::GetRelativeInstallDir() const { | ||
return base::FilePath(speech::kSodaEnUsInstallationRelativePath); | ||
} | ||
|
||
void SodaEnUsComponentInstallerPolicy::GetHash( | ||
std::vector<uint8_t>* hash) const { | ||
hash->assign(kSodaEnUsPublicKeySHA256, | ||
kSodaEnUsPublicKeySHA256 + base::size(kSodaEnUsPublicKeySHA256)); | ||
} | ||
|
||
std::string SodaEnUsComponentInstallerPolicy::GetName() const { | ||
return kSodaEnUsManifestName; | ||
} | ||
|
||
update_client::InstallerAttributes | ||
SodaEnUsComponentInstallerPolicy::GetInstallerAttributes() const { | ||
return update_client::InstallerAttributes(); | ||
} | ||
|
||
std::vector<std::string> SodaEnUsComponentInstallerPolicy::GetMimeTypes() | ||
const { | ||
return std::vector<std::string>(); | ||
} | ||
|
||
void UpdateSodaEnUsInstallDirPref(PrefService* prefs, | ||
const base::FilePath& install_dir) { | ||
#if !defined(OS_ANDROID) | ||
prefs->SetFilePath(prefs::kSodaEnUsConfigPath, | ||
install_dir.Append(kSodaEnUsConfigFileRelativePath)); | ||
#endif | ||
} | ||
|
||
void RegisterSodaEnUsComponent(ComponentUpdateService* cus, | ||
PrefService* prefs, | ||
base::OnceClosure callback) { | ||
DCHECK_CURRENTLY_ON(BrowserThread::UI); | ||
#if BUILDFLAG(ENABLE_SODA) | ||
if (!prefs->GetBoolean(prefs::kLiveCaptionEnabled)) | ||
return; | ||
|
||
auto installer = base::MakeRefCounted<ComponentInstaller>( | ||
std::make_unique<SodaEnUsComponentInstallerPolicy>(base::BindRepeating( | ||
[](ComponentUpdateService* cus, PrefService* prefs, | ||
const base::FilePath& install_dir) { | ||
if (prefs->GetBoolean(prefs::kLiveCaptionEnabled)) { | ||
content::GetUIThreadTaskRunner({base::TaskPriority::BEST_EFFORT}) | ||
->PostTask(FROM_HERE, | ||
base::BindOnce(&UpdateSodaEnUsInstallDirPref, | ||
prefs, install_dir)); | ||
} | ||
}, | ||
cus, prefs))); | ||
|
||
installer->Register(cus, std::move(callback)); | ||
#endif | ||
} | ||
|
||
bool UninstallSodaEnUsComponent(ComponentUpdateService* cus, | ||
PrefService* prefs) { | ||
return cus->UnregisterComponent( | ||
SodaEnUsComponentInstallerPolicy::GetExtensionId()); | ||
} | ||
} // namespace component_updater |
Oops, something went wrong.